- : Jeffrey Rosenwald (JeffRose@acm.org)
- See also
- : SWI-Prolog
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data -- think XML, but smaller, faster, and simpler. You define how you want your data to be structured once. This takes the form of a template that describes the data structure. You use this template to encode and decode your data structure into wire-streams that may be sent-to or read-from your peers. The underlying wire stream is platform independent, lossless, and may be used to interwork with a variety of languages and systems regardless of word size or endianness. Techniques exist to safely extend your data structure without breaking deployed programs that are compiled against the "old" format.
The idea behind Google's Protocol Buffers is that you define your
structured messages using a domain-specific language and tool set. In
SWI-Prolog, you define your message template as a list of predefined
Prolog terms that correspond to production rules in the Definite Clause
Grammar (DCG) that realizes the interpreter. Each production rule has an
equivalent rule in the protobuf grammar. The process is not unlike
specifiying the format of a regular expression. To encode a template to
a wire-stream, you pass a grounded template,
decode a wire-stream,
Y, you pass an ungrounded template,
along with a grounded wire-stream,
interpreter will unify the unbound variables in the template with values
decoded from the wire-stream.
For an overview and tutorial with examples, see
Examples of usage may also be found by inspecting
- [semidet]protobuf_message(?Template, ?Wire_stream)
- [nondet]protobuf_message(?Template, ?Wire_stream, ?Rest)
- Marshalls and unmarshalls byte streams encoded using Google's Protobuf
provides a bi-directional parser that marshalls a Prolog structure to Wire_stream,
according to rules specified by Template. It can also
unmarshall Wire_stream into a Prolog structure according to
the same grammar.
provides a difference list version.
Template is a protobuf grammar specification. On decode, unbound variables in the Template are unified with their respective values in the Wire_stream. On encode, Template must be ground. Wire_stream is a code list that was generated by a protobuf encoder using an equivalent template.