Reputation:
I am looking to encode a record data structure in erlang using protobuff for erlang. I haven't found a function to do so.
rd(person, {name = "", phone = [], address}).
A = #person{phone=[0,8,2,3,4,3,1,2], name="Robert"}.
protobuffs:encode(1, A, bytes).
** exception error: bad argument
in function protobuffs:encode_internal/3
called as protobuffs:encode_internal(1,
#person{
name = "Robert",
phone = [0,8,2,3,4,3,1,2],
address = undefined},
bytes)
How can I encode a record using protobuff?
This is the module, I am using to encode, https://github.com/basho/erlang_protobuffs
Thank you
Upvotes: 0
Views: 88
Reputation: 170815
You can't encode arbitrary records you just defined, that's simply not how Protocol Buffers work in any language.
You need to:
Define your message types in a .proto
file (read Protocol Buffers documentation for the syntax, supported types, etc.).
Generate code for the desired language(s) from it. In this case, using protobuffs_compile:scan_file(<path-to-your-proto-file>).
as shown in the README.
Use the generated code. It will include the person
record and encode_person
function.
Upvotes: 2