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

Escape extension field names #371

Closed
jamesray1 opened this issue Jan 7, 2019 · 2 comments
Closed

Escape extension field names #371

jamesray1 opened this issue Jan 7, 2019 · 2 comments

Comments

@jamesray1
Copy link
Contributor

Basically the generated code is using the illegal keyword type in place of a variable representing the type of a Rust enum field.

Rust compiler error in generated proto file:

expected identifier, found keyword `type`

expected identifier, found keyword

rpc_proto.rs(2094, 15): expected identifier, found keyword
pub const type: ::protobuf::ext::ExtFieldOptional<::protobuf::descriptor::EnumValueOptions, ::protobuf::types::ProtobufTypeString> = ::protobuf::ext::ExtFieldOptional

Full line: (pub const type: ::protobuf::ext::ExtFieldOptional<::protobuf::descriptor::EnumValueOptions, ::protobuf::types::ProtobufTypeString> = ::protobuf::ext::ExtFieldOptional { field_number: 51234, phantom: ::std::marker::PhantomData }; line 2094 of the generated file (avaliable here)

Proto file:


syntax = "proto2";

import "google/protobuf/descriptor.proto";

extend google.protobuf.EnumValueOptions {
	optional string type= 51234;
	optional string code= 51235;
  }

package pubsub.pb;

message RPC {
	repeated SubOpts subscriptions = 1;
	repeated Message publish = 2;

	message SubOpts {
		optional bool subscribe = 1; // subscribe or unsubcribe
		optional string topicid = 2;
	}

	optional ControlMessage control = 3;
}

message Message {
	optional bytes from = 1;
	optional bytes data = 2;
	optional bytes seqno = 3;
	repeated string topicIDs = 4;
	// TODO: use
	// optional bytes signature = 5;
	// optional bytes key = 6;
}

message ControlMessage {
	repeated ControlIHave ihave = 1;
	repeated ControlIWant iwant = 2;
	repeated ControlGraft graft = 3;
	repeated ControlPrune prune = 4;
}


// While this may not be strictly necessary as a messageID and a messageHash
// are both strings, it would be useful to differentiate between them in the
// protobuf file, e.g. due to the accessors and for clarity.
enum MessageRep {
	ID = 0 [(type) = "ID", (code) = 'I'];
	HASH = 1 [(type) = "HSH", (code) = 'H'];
}

message ControlIHave {
	optional string topicID = 1;
	// We could have a repeated string messageIDs field and repeated string
	// messageHash field here, which would be better for backwards
	// compatibility, although hiding both behind one type has its advantages.
	repeated MessageRep mRep = 2;
}

message ControlIWant {
	repeated string MessageRep = 1;
}

message ControlGraft {
	optional string topicID = 1;
}

message ControlPrune {
	optional string topicID = 1;
}

message TopicDescriptor {
	optional string name = 1;
	// TODO: use
	// optional AuthOpts auth = 2;
	// optional EncOpts enc = 3;

	// message AuthOpts {
	// 	optional AuthMode mode = 1;
	// 	repeated bytes keys = 2; // root keys to trust

	// 	enum AuthMode {
	// 		NONE = 0; // no authentication, anyone can publish
	// 		KEY = 1; // only messages signed by keys in the topic descriptor are accepted
	// 		WOT = 2; // web of trust, certificates can allow publisher set to grow
	// 	}
	// }

	// message EncOpts {
	// 	optional EncMode mode = 1;
	// 	repeated bytes keyHashes = 2; // the hashes of the shared keys used (salted)

	// 	enum EncMode {
	// 		NONE = 0; // no encryption, anyone can read
	// 		SHAREDKEY = 1; // messages are encrypted with shared key
	// 		WOT = 2; // web of trust, certificates can allow publisher set to grow
	// 	}
	// }
}
@stepancheg stepancheg changed the title Compiler error expected identifier, found keyword type with enum Escape extension field names Jan 20, 2019
stepancheg added a commit that referenced this issue Jan 20, 2019
@stepancheg
Copy link
Owner

Published version 2.2.5. Thank you for the bugreport!

@jamesray1
Copy link
Contributor Author

Thank you!

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