Skip to content
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

Protobuf Extensions and Oneof #42

Open
machinekoder opened this issue Dec 12, 2015 · 4 comments
Open

Protobuf Extensions and Oneof #42

machinekoder opened this issue Dec 12, 2015 · 4 comments

Comments

@machinekoder
Copy link
Member

The protobuf definitions might be easier to understand by using the Protobuf Extensions and Oneof features:
https://developers.google.com/protocol-buffers/docs/proto?hl=en

E.g. message types for a certain service could be defined in separate file instead of the types.proto. It would simplify documentation of things that belong together.

@mhaberler
Copy link
Contributor

certainly - also the dictionary feature might be useful

before adopting protobuf 3, I'd like to see a stable release with solid Python bindings (currently considered alpha: https://github.com/google/protobuf/releases)

@machinekoder
Copy link
Member Author

Both features are available in protobuf 2.6. Especially Extensions could be very helpful.

@machinekoder
Copy link
Member Author

Example:
The types and messages for a new protcol could be moved into a myprotocol.proto file:

package pb;

import "machinetalk/protobuf/message.proto";

enum MyCoolProtocolType {
   COOL_PING = 1,
   COOL_PONG = 2
}

message MyMessage {
    required MyCoolProtocolType type = 1;
    optional int32 easy = 2;
}

extend Container {
    optional MyMessage testus = 1000;
}

I think it is even possible to do this without recompiling the main Machinetalk library. The calling code looks a little bit different:

from machinetalk.protobuf.message_pb2 import Container
import machinetalk.protobuf.types_pb1 as types
import machinetalk.protobuf.myprotocol_pb2 as pb

x = Container()
...
if (x.type == types.MT_REQ) and x.HasExtension(pb.testus):
    testus = x.Extension[pb.testus]
    if testus.type == pb.COOL_PING:
         print(testus.easy)

Looks pretty easy and keeps things in place.

@machinekoder
Copy link
Member Author

However, the Extension type seems to breakable when a id is redefined and the type one the other side does not match the local type. It looks like this feature will be replaced in proto3 by the Any type which will bring type safety: https://developers.google.com/protocol-buffers/docs/proto3?hl=en#any

machinekoder added a commit that referenced this issue Nov 22, 2016
DigitalReadOut.qml: set default values for machine with 5+ axes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants