Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAPIv2: types/dynamicpb: add support for dynamic messages #199
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
awalterschulze
Jul 1, 2016
I like using https://github.com/katydid/katydid/blob/master/parser/proto/proto.go#L121
Here are some usage docs http://katydid.github.io/parser/parserusage.html
awalterschulze
commented
Jul 1, 2016
|
I like using https://github.com/katydid/katydid/blob/master/parser/proto/proto.go#L121 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
abe-winter
Jan 22, 2017
I have a proof-of-concept of this working in a fork
https://github.com/abe-winter/dynproto
abe-winter
commented
Jan 22, 2017
|
I have a proof-of-concept of this working in a fork |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Merovius
Jan 23, 2017
@abe-winter Awesome :) IIt would be great if it wouldn't depend on cgo, though. Is there a reason you didn't use descriptors in proto-encoding?
Merovius
commented
Jan 23, 2017
|
@abe-winter Awesome :) IIt would be great if it wouldn't depend on cgo, though. Is there a reason you didn't use descriptors in proto-encoding? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
abe-winter
Jan 23, 2017
@Merovius the output of ParseSchema is a FileDescriptorProto, and all the downstream code uses the proto. My use case requires schema parsing. An alternative is to shell out to the protoc program, but then protoc needs to be installed everywhere.
Would it make sense to set a // +build cgo on the parsing code? I'm not super-familiar with golang, but I think that makes cgo a soft dependency.
abe-winter
commented
Jan 23, 2017
|
@Merovius the output of ParseSchema is a FileDescriptorProto, and all the downstream code uses the proto. My use case requires schema parsing. An alternative is to shell out to the protoc program, but then protoc needs to be installed everywhere. Would it make sense to set a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
abe-winter
Jan 23, 2017
I'll move schema parsing to its own package so it's truly optional.
abe-winter
commented
Jan 23, 2017
|
I'll move schema parsing to its own package so it's truly optional. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Merovius
Jan 23, 2017
Great, I think it's a good idea to have the schema-parsing in a separate package.
Another change I would suggest, is to add a DynamicMessage (or similar) struct which implements proto.Message statically and embeds/contains a *reflect.Type. DynStruct could then return a []*DynamicMessage, instead of a []*reflect.Type. The advantage would be, that a) Marshal/Unmarshal could remain type-safe and take a proto.Message and b) packages which wrap proto in a message-type agnostic way (grpc reflection comes to mind), could also use the dynamic message without breaking their type-safety.
Merovius
commented
Jan 23, 2017
|
Great, I think it's a good idea to have the schema-parsing in a separate package. Another change I would suggest, is to add a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
abe-winter
Jan 23, 2017
Hmm. You have two points here:
- grpc and other codebases use proto.Message internally and so DynStruct should support the Message interface.
- This sounds right but I'm worried about making this change without a testing plan. I don't know what grpc would do with dynamic messages and what the requirements would be in practice.
- Buffer.Marshal/Unmarshal gain a safety advantage from taking Message instead of empty
interface{}.- This sounds wrong to me. Nothing inside those functions calls the Message methods. We can implement
MessageandMarshalerfor yourDynamicMessagestruct, but this would just be copying around parts of Marshal/Unmarshal. Not sure there's any advantage.
- This sounds wrong to me. Nothing inside those functions calls the Message methods. We can implement
abe-winter
commented
Jan 23, 2017
|
Hmm. You have two points here:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jhump
Feb 17, 2017
Contributor
I've been working on something related to this, to be able to use the service reflection to build clients. I haven't gotten to a point of implementing the equivalent of DynamicMessage, but I do have better descriptors (like protobuf provides in Java and C++ runtimes) as well as a better client interface for the reflection service. I think the descriptors would be a suitable base for pure-Go implementation of a dynamic message.
https://github.com/jhump/protoreflect
|
I've been working on something related to this, to be able to use the service reflection to build clients. I haven't gotten to a point of implementing the equivalent of |
jhump
referenced this issue
Feb 17, 2017
Closed
APIv2: reflect/protoreflect: add API to retrieve Descriptors #293
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jhump
Apr 3, 2017
Contributor
FWIW, I have an all-Go implementation of dynamic messages:
https://godoc.org/github.com/jhump/protoreflect/dynamic
And there's also a dynamic RPC stub, that invokes RPCs using method descriptors and dynamic messages:
https://godoc.org/github.com/jhump/protoreflect/dynamic/grpcdynamic
It's not 100% yet -- mainly missing useful support for proto3 well-known-types and knobs for better controlling JSON output (for example). I'd say it's currently beta-quality right now -- not a lot of miles on it other than the tests, and there are several TODOs for more tests (though a lot of the code does get exercised by the tests that are present).
The *dynamic.Message type does implement proto.Message and it also has a Descriptor method that is compatible with that of generated messages. It implements proto.Marshaler, proto.Unmarshaler, encoding.TextMarshaler, and encoding.TextUnmarshaler so it can also be used with functions in the proto package for serializing and de-serializing.
It can't yet be used with the jsonpb package. I've opened a pull request that, if merged, would remedy that (#325).
Of course, APIs that accept a proto.Message which in turn use proto.GetProperties, proto.MessageName, or any of the extension-related messages in the proto package will not work with this new type. Those methods all assume the object not only implements the interface, but that it also is a registered generated type.
|
FWIW, I have an all-Go implementation of dynamic messages: It's not 100% yet -- mainly missing useful support for proto3 well-known-types and knobs for better controlling JSON output (for example). I'd say it's currently beta-quality right now -- not a lot of miles on it other than the tests, and there are several TODOs for more tests (though a lot of the code does get exercised by the tests that are present). The It can't yet be used with the Of course, APIs that accept a |
geeknoid
referenced this issue
Apr 18, 2017
Closed
Consider simplifying our Aspect configuration proto format. #565
dsnet
changed the title from
Add support for DynamicMessages
to
proposal: add support for DynamicMessages
Feb 14, 2018
dsnet
added
the
proposal
label
Feb 14, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Placing on hold until #364 is complete. |
dsnet
added
the
proposal-hold
label
Mar 9, 2018
dsnet
added
the
api-v2
label
Aug 2, 2018
dsnet
changed the title from
proposal: add support for DynamicMessages
to
APIv2: types/dynamicpb: add support for dynamic messages
Aug 18, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dsnet
Aug 18, 2018
Member
Work on #364 is in full swing and support for dynamic messages is planned.
|
Work on #364 is in full swing and support for dynamic messages is planned. |
mwitkow commentedJul 1, 2016
Since gRPC now has support for server-side reflection (https://github.com/grpc/grpc-go/tree/master/reflection, basically
stubby ls) it would be able to process dynamic messages in Go.I'd be interested in adding this support either in
protobufor in an outside, but would probably need some restructuring inprotobufitself: e.g. allowing to use the same encoding/decoding methods but with the schema driven from aFileDescriptorProtoinstead of Golang tags.