The Prolog term corresponding to a protobuf message
is a
dict, with the keys
corresponding to the field names in the message
(the dict
tag is treated as a comment). Repeated fields are represented as lists;
enums are looked up and converted to atoms; bools are represented by
false
and true
; strings are represented by
Prolog strings or atoms; bytes are represented by lists of codes.
TODO
: Add an option to omit default values (this is the proto3
behavior).
When serializing, the dict tag is treated as a comment and is ignored. So, you can use any dict tags when creating data for output. For example, both of these will generate the same output:
protobuf_serialize_to_codes(_{people:[_{id:1234,name:"John Doe"}]}, 'tutorial.AddressBook', WireCodes). protobuf_serialize_to_codes('tutorial.AddressBook'{people:['tutorial.Person'{name:"John Doe",id:1234}]}, 'tutorial.AddressBook', WireCodes).
NOTE: if the wire codes can't be parsed, protobuf_parse_from_codes/3 fails. One common cause is if you give an incorrect field name. Typically, this shows up in a call to protobufs:field_segment/3, when protobufs:proto_meta_field_name/4 fails.