lua-users home
lua-l archive

Re: [ANN] lua-pb Lua Protocol Buffers

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Friday 24, Matthew Wild wrote:
> On 23 June 2011 13:44, Robert G. Jakabosky <bobby@sharedrealm.com> wrote:
> > Announcing lua-pb [1] a Lua implementation of Google's Protocol Buffers
> > [2].
> 
> Woohoo, many thanks! I think this is something I shall be using sooner
> rather than later. Every so often a time comes where I wish for (and
> wished I had time to develop) a project like this. I'm sure I'll be
> pestering you about stuff when that time comes next :)
I am really interested in feedback on the API.
I just added a feature where you can 'require' .proto file just like Lua 
modules.
-- person.proto:
message Person {
 required string name = 1;
 required int32 id = 2;
 required string email = 3;
}
-- example_person.lua:
require"pb" -- first load lua-pb
require"person" -- load the above .proto file
msg = person.Person() -- create a Person message
msg.name = "John Doe"
msg.id = 1234
msg.email = "jdoe@example.com"
I am planning on adding these methods to the message interface:
msg:MergeFrom(msg1)
msg:CopyFrom(msg1)
msg:Clear()
msg:IsInitialized()
msg:MergeFromString(str)
msg:ParseFromString(str)
msg:SerializeToString()
msg:SerializePartialToString()
msg:ByteSize()
Basically an interface similar to the Python protobuf interface [1].
The current lua-pb message interface avoids using any methods that could 
conflict with field names. There are some hidden methods 
".encode",".decode",".dump" which are used by 
pb.encode()/pb.decode()/pb.dump(). But now I think this needlessly 
complicates the interface.
Also the style guide for Protocol Buffers recommends using 
lowercase_underscore_separated_names for field names. So people following 
that guide will not have any problems with method & field name collision.
1. 
http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf.message.Message-
class.html
2. http://code.google.com/apis/protocolbuffers/docs/style.html
-- 
Robert G. Jakabosky

AltStyle によって変換されたページ (->オリジナル) /