Title: Theory / Unimportant / CS / Descriptive / Protobuf
Tags: seen_description type comment declaration syntactical_sugar todo_declaration
On every note of this deck, unless a note says otherwise:
Page: https://developers.google.com/protocol-buffers/docs/proto3

Question: Advantage of protobuf over xml
Answer: Simpler
Page: https://developers.google.com/protocol-buffers/docs/overview
Answer2: 3-10 time smaller
Answer3: 20-100 time faster
Answer4: Less ambiguous
Answer5: generate data access classes that are easier to use programmatically

Question: Advantage of xml over protobuf
Answer: The xml file can be directly edited by a text editor
Page: https://developers.google.com/protocol-buffers/docs/overview
Answer2: xml is self explenatory, even without the protocol
Answer3: a good way to model a text-based document with markup (e.g. HTML), since you cannot easily interleave structure with text

Question: Why was protobuf introduced ?
Answer: New fields could be easily introduced, and intermediate servers that didn't need to inspect the data could simply parse it and pass through the data without needing to know about all the fields.
Page: https://developers.google.com/protocol-buffers/docs/overview
Answer2: Formats were more self-describing, and could be dealt with from a variety of languages (C++, Java, etc.)
Answer3: Automatically-generated serialization and deserialization code avoided the need for hand parsing.
Answer4: In addition to being used for short-lived RPC (Remote Procedure Call) requests, people started to use protocol buffers as a handy self-describing format for storing data persistently (for example, in Bigtable).
Answer5: Server RPC interfaces started to be declared as part of protocol files, with the protocol compiler generating stub classes that users could override with actual implementations of the server's interface.

Instruction: syntax = "proto3";
Page: https://developers.google.com/protocol-buffers/docs/overview
Effect: state that the file is a proto3 file
Language: proto
Where to use it: First non empty line

Instruction: t v = i;
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: State that the current message has a field, number i, of type t, with name var
Language: proto
Context: proto3
Variables: t a type
var a variable name
i an integer
Where to use it: Message format
Assuming: \(1\le i\le2^{29}-1\setminus[19000,19999]\)

Extension: .proto
Description: protobuf file
Other fields (not shown on cards):
Page: https://developers.google.com/protocol-buffers/docs/proto3

Instruction: singular
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicates the current field can occur at most once by message
Language: proto
Context: Protobuf

Question: How much space take index
Answer: 1 byte for indices 1 to 15
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf
Answer2: 2 bytes for numbers in \([16,2047]\)
Answer3: ? bytes otherwise

Question: what is generated in C++ from a proto file
Answer: a .h and .cc file from each .proto, with a class for each message type described in your file.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Instruction: repeated
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicates the current field can occur any number of time
Language: proto
Context: Protobuf

Language: proto
Abbreviation: // foo
Instruction: /* foo;*/
Other fields (not shown on cards):
Page: https://developers.google.com/protocol-buffers/docs/proto3

Instruction: reserved i ;
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicates that the index i is reserved (i.e. were used in previous version of the message and sohuld not be used again)
Language: proto

Instruction: reserved "var" ;
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicates that the variable name var is reserved (i.e. were used in previous version of the message and sohuld not be used again)
Language: proto
Variables: var variable name

Instruction: reserved i to j;
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicates that the indices between i and j are reserved.
Language: proto
Variables: var_i variable name

Instruction: reserved x_1; ...; reserved x_n;
Page: https://developers.google.com/protocol-buffers/docs/proto3
Language: proto
Abbreviation: reserved x_1, ..., x_n;

Question: what is generated in Java from a proto file
Answer: a .java file with a class for each message type, as well as a special Builder classes for creating message class instances.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in python from a proto file
Answer: a module with a static descriptor of each message type in your .proto, which is then used with a metaclass to create the necessary Python data access class at runtime.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in Go from a proto file
Answer: a .pb.go file with a type for each message type in your file.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in Ruby from a proto file
Answer: a .rb file with a Ruby module containing your message types
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in Objective-C from a proto file
Answer: a pbobjc.h and pbobjc.m file from each .proto, with a class for each message type described in your file
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in C# from a proto file
Answer: a .cs file from each .proto, with a class for each message type described in your file.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is generated in Dart from a proto file
Answer: a .pb.dart file with a class for each message type in your file.
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Question: what is the default value of an enum
Answer: The first defined enum value, which must be 0
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Typ: int32/64
Meaning: Uses variable-length encoding.
Language: proto
Intuition: Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead

Typ: bool
Meaning: either true or false
Language: proto
Initialization: false

Typ: string
Meaning: utf-8 or 7-bit ascii text, length at most 2^32
Language: proto
Initialization: Empty string

Typ: bytes
Meaning: An arbitarry sequence of bytes no longer than 2^32
Language: proto
Initialization: Empty sequence

Question: what is the default value of a numeric type
Answer: 0
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Instruction: enum Foo {
  val_0 = n_0;
  ...
  val_i_-1 = n_i-1;
}
Page: https://developers.google.com/protocol-buffers/docs/proto3
Meaning: Declare a type foo with i elements val_i.
Language: Proto
Assuming: either val_i appear in no other enumeration, or allow_alias is true
n_0 = 0
each n_i distinct

Instruction: import "foo"
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Import the content of the file foo ; it can be used only in this file and is not imported in files importing current file
Language: proto
Context: protoBuf

Instruction: import public "foo"
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Import the content of the file foo as if it were in this file
Language: proto

Instruction: foo.bar
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Access to the definition bar in the definition foo
Language: proto

Question: What to do when you want to remove a field from a message typea
Answer: Either rename to OBSOLETE_
Page: https://developers.google.com/protocol-buffers/docs/proto3-
Context: protobuf
Answer2: or mark the field number as reserved

Question: What to do when you want to add a field from a message type
Answer: Ensure it does not use field number and name used in older version
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Name: An unknown field
Definition: well-formed protocol buffer serialized data representing fields that the parser does not recognize
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Instruction: oneof foo {
  def_1
  ...
  def_n
}
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: State that the currently defined value has at most one of the type defined in def_1. Named foo
Language: proto

Question: What occurs if you set a field of a oneof ?
Answer: Other field are unset
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Name: A wire
Definition: An encoding of a protobuf type
Page: https://developers.google.com/protocol-buffers/docs/proto3
Context: protobuf

Typ: map<foo, bar>
Meaning: Type of map from foo to bar
Language: proto
Context: protobuf
Extra: Elements in map are not ordered
Assuming: foo is either string or integral

Instruction: package foo
Page: https://developers.google.com/protocol-buffers/docs/proto3
Effect: Indicate that all elements of this file belong to a package called foo, so element elt should be called with foo.bar. Generated code will be in the same package
Language: proto

Instruction: .foo
Language: proto
Returns: Value of foo, as a fully qualified name

Instruction: message foo {
   bar
}
Effect: Define a new type of message,, named foo with definition of fields and other types as in bar
Language: proto