-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
protoc-gen-go: simplify generated oneof implementation #708
Comments
dsnet
added a commit
that referenced
this issue
Nov 26, 2018
The marshaler, unmarshaler, and sizer functions are unused ever since the underlying implementation was switched to be table-driven. Change the function to only return the wrapper structs. This change: * enables generated protos to drop dependencies on certain proto types * reduces the size of generated protos * simplifies the implementation of oneofs in protoc-gen-go Updates #708
dsnet
added a commit
that referenced
this issue
Nov 27, 2018
…760) The marshaler, unmarshaler, and sizer functions are unused ever since the underlying implementation was switched to be table-driven. Change the function to only return the wrapper structs. This change: * enables generated protos to drop dependencies on certain proto types * reduces the size of generated protos * simplifies the implementation of oneofs in protoc-gen-go Updates #708
dsnet
added a commit
that referenced
this issue
Nov 27, 2018
The marshaler, unmarshaler, and sizer functions are unused ever since the underlying implementation was switched to be table-driven. Change the function to only return the wrapper structs. This change: * enables generated protos to drop dependencies on certain proto types * reduces the size of generated protos * simplifies the implementation of oneofs in protoc-gen-go Updates #708 Change-Id: I845c9009bc0236d1b51d34b014dc3e184303c0f2 Reviewed-on: https://go-review.googlesource.com/c/151357 Reviewed-by: Damien Neil <[email protected]>
dsnet
added a commit
that referenced
this issue
Nov 27, 2018
…760) The marshaler, unmarshaler, and sizer functions are unused ever since the underlying implementation was switched to be table-driven. Change the function to only return the wrapper structs. This change: * enables generated protos to drop dependencies on certain proto types * reduces the size of generated protos * simplifies the implementation of oneofs in protoc-gen-go Updates #708 Change-Id: I5d45dacc72549864a0fe5b2bf27de9a31ea91607 Cherry-Pick: github.com/golang/protobuf@8d0c54c1246661d9a51ca0ba455d22116d485eaa Original-Author: Joe Tsai <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/151399 Reviewed-by: Damien Neil <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The logic to generate support for oneofs are a significant source of complexity:
proto
package as the generated code depends on the following types, functions, variables, and constants:Buffer
,SizeVarint
,ErrInternalBadWireType
,WireBytes
,WireEndGroup
,WireFixed
,WireStartGroup
, andWireVarint
.XXX_OneofFuncs
.However, this does not need to be the case:
proto
runtime, since switching to the table-driven approach, usesXXX_OneofFuncs
in marshal and unmarshal only to obtain type information about the wrappers.Since the type information is the only information needed, we can accomplish this in a cleaner way. Instead of adding the method, we add an unexported, zero-length field with all the wrapper types:
This has the following properties:
proto
since we don't have to type assert for a method with a relatively complex signature.unsafe.Sizeof(FooMessage{})
remains unchanged\cc @neild
The text was updated successfully, but these errors were encountered: