-
Notifications
You must be signed in to change notification settings - Fork 807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work In Progress: Separate binary with default code generation behaviour for normal proto files. #39
Comments
(FYI @andrei-alpha) |
Upstreaming yeah :) I really like the idea of overriding the DefaultParams for gogoproto extensions, but I do not think sizeMethodName fits into this model though. When you talk about a mutator API you are talking about setters that return a pointer to the struct they just changed, right? |
if we can remove io/ and the Sizer interface from proto/encode_gogo.go (looks like neither is used), then we should be able to parameterize the size method name (plugins and test are the only places that refers to Size()). wrt to mutator: yes, basically the same as c++'s api where the mutator function is responsible for memory allocation |
My concern is there is a TODO in goprotobuf code. https://github.com/golang/protobuf/blob/master/proto/encode.go // Size returns the encoded size of a protocol buffer.func Size(pb Message) On 14 January 2015 at 11:36, Patrick notifications@github.com wrote:
|
I have no experience with the C++ api, maybe you could explain more about the memory allocation you have in mind? |
io is a library that is being used, not within gogoprotobuf, but by projects using gogoprotobuf. |
It seems like we can remove the Sizer interface in encode_gogo.go. I hope nobody is using it. |
I don't know how useful renaming the size method would be to others. |
https://developers.google.com/protocol-buffers/docs/reference/cpp-generated in summary non-repeated scalar fields support: Set(value), Clear() and Get() non-repeated msg fields support: Mutable(), Clear() and Get() repeated scalar fields support: Add(value), Set(index, value), Clear(), Get(index) and Size() repeated msg fields support: Add(), Mutable(index), Clear(), Get(index) and Size() |
Ok so is that where the msg Size() method gets into conflict with the repeated fields Size() ? |
oops, github markdown trim out parts of the method names. Let's try this again. Suppose your field name is Foo, then non-repeated scalar fields support: SetFoo(value), ClearFoo() and GetFoo() non-repeated msg fields support: MutableFoo(), ClearFoo() and GetFoo() repeated scalar fields support: AddFoo(value), SetFoo(index, value), ClearFoo(), GetFoo(index) and FooSize() repeated msg fields support: AddFoo(), MutableFoo(index), ClearFoo(), GetFoo(index) and FooSize() Note that the generated methods names do not conflict with Size. Size is a valid field name in standard (non-go) protobuf. We needed to rename Size to ProtoSize because we have numerous definitions of the form
that are already in used in our c++ / python code |
Aha ok that is good news. So what about changing the fieldname in go only, to avoid the name conflict?
|
So do you already have a working mutator API in dropbox/goprotoc? |
we want to avoid importing the gogo's proto since it doesn't behavior well with our python toolchain. Andrei wrote a working mutator API for dropbox/goprotoc. Unlike gogoproto / go proto, fields generated by goprotoc are private (so it's not backward compatible). The primary motivation for the change was to reduce programming errors such as setting nil in repeated message field array, accidentally sharing variable pointers, etc (my coworkers and I have made these mistakes repeatedly). The secondary motivation was to improve proto's performance; for example, we can cache the computed size during serialization, reduce gc by properly inlining optional fields (gogo sort of support this, but we actually care about empty fields), etc. (Note: I haven't had the chance to migrate dropbox internal to goprotoc.) |
1 similar comment
we want to avoid importing the gogo's proto since it doesn't behavior well with our python toolchain. Andrei wrote a working mutator API for dropbox/goprotoc. Unlike gogoproto / go proto, fields generated by goprotoc are private (so it's not backward compatible). The primary motivation for the change was to reduce programming errors such as setting nil in repeated message field array, accidentally sharing variable pointers, etc (my coworkers and I have made these mistakes repeatedly). The secondary motivation was to improve proto's performance; for example, we can cache the computed size during serialization, reduce gc by properly inlining optional fields (gogo sort of support this, but we actually care about empty fields), etc. (Note: I haven't had the chance to migrate dropbox internal to goprotoc.) |
So your python tool chain can't handle imports or why its it hard for the python tool chain? proto3 might make it hard for you to care about empty fields. I think that adding the mutator API support might be possible. As I understand it, documentation pending, proto3 also removes extensions, which really scares me, but they are replacing it with something different called Any. |
our python tool chain doesn't support extensions (we're using an in-house c++ binding that's ~6-30x faster than standard python proto; I haven't have the time to verify extension working correctly yet). I haven't been following proto3's progress. Are you referring to flatbuffers? I know for a fact that google (ads) uses empty fields in millions of places. I doubt they can actually migrate away from empty fields / proto2 syntax. |
Ok but you don't need to marshal or unmarshal the extensions in the No not flatbuffers. On 21 January 2015 at 09:47, Patrick notifications@github.com wrote:
|
This could also be interesting |
Any thoughts on proto3? |
TBH, it's unlikely we (dropbox) will switch over to proto3 any time soon. The ROI is very low. I know there's a lot of resistance to proto3 within google for the same reason. That's why there's a backward compatibility mode. |
That is very interesting to hear. Ok so I made a similar suggestion in the proto3 issue. |
But then you don't have import gogoproto or use any extensions. |
Hello? |
Sorry, your email got lost in my inbox (I'm drowning in work emails). For clarification wrt your binary comment, are you referring to 1) a secondary binary (on top of the standard gogo compiler) which mutates the compiled proto files and add the extensions and customnames, or 2) a parallel binary to the standard gogo compiler which ables all of the customizations? using 1) places extra burden on our developers (a lot of them are new to protos), which increases odds of messing up the compilation. We're basically doing 2) in house right now, so I wouldn't object to it. |
Cool no problem :) Yes I was thinking a parallel binary lets say protoc-gen-gogostd So I am pretty sure that is the same as number 2. |
Very interested in this change as well. Would love to make gogo protofiles look as similar as possible to "regular" ones. Do i understand correctly, that a user would be able to build a second protobuf generator plugin binary, with options of their choice already enabled by default. And therefore clean protofiles up ? |
There will be a library to make to make this easier and gogoprotobuf would also provide a binary using that library. The library functions would just walk through the fileDescriptorSet and annotate the structures with the current user specified extensions. For example there would be a function AllNonNullable (which would add nullable=false to all fields), AllTheSpeed (which would add marshaler_all, unmarshaler_all and sizer_all to all files), etc. |
I have created a new issue pertaining to the Size fieldname issue |
I have started some work on the vanity branch, here is the commit |
I would also like to know from @PatrickDropbox if this vanity branch and the Size fieldname bug would resolve this issue? |
yeah, probably. |
Please check out the size fieldname fix on the sizeunderscore branch. |
merged. |
Is there documentation how to use this new delicious stuff ? |
The Readme om the proto3 branch For golang/protobuf/proto import simply go to gogo.github.io/doc and Ctrl+f gogoproto_import I hope that answers your question. |
There are a bunch of dropbox internal customization which I'm interested in upstreaming. In particular:
To avoid breaking the rest of the world, I was thinking of creating a struct which would holds the default values (and we'll only patch this struct within dropbox). something like
the world would use:
while dropbox would override the defaults to:
Is this acceptable?
Also, on the experimental side, I want to backport plugins from https://github.com/dropbox/goprotoc to generate proper mutator APIs (we've got burn by goproto's lack of proper mutator api a few of time recently, especially around repeated field). Is this something you would be interested in?
Thanks,
Patrick
The text was updated successfully, but these errors were encountered: