How can I get the bytes/bytes size for variant field types in C++?

116 views
Skip to first unread message

bar sharvit

unread,
Dec 1, 2020, 10:18:19 AM12/1/20
to Protocol Buffers

Hi,
 I'm working on a gRPC validator where I need to validate the size of the client's variant fields.
For example, if the clients have this message:

---- 

message int64{ int64 int64 = 1; int32 int32 = 2; }

----

and the server has this message:
----  

message int64{ bool int64 = 1; bool int32 = 2; }
----  

I want to validate that the client is sending a value that has 1 byte, and with the value 1 or 0, and if not raise an error.



When sending the value:
----  
11000010001010110000000010 (0x0308ac02)
----  

(which translate to: field_number :1 wire_type : 0 compile_type : "uint64" data : 300)


The type that the server sees for this field is FieldDescriptor::TYPE_BOOL and using the function GetBool  (const Message& message, const FieldDescriptor* field) return 1.

Is there any way to get the size of the variant field? or get the bytes themselves from the msg for each field? If not there is some other way to validate that the type of the server and the client is really the same one?

Thanks, Bar Sharvit

Reply all
Reply to author
Forward
0 new messages