External Issue: Review of protobuf Any message type user-end APIs

16286, “Aniket21mathur”, “Review of protobuf Any message type user-end APIs”, “2020-08-25T13:32:49Z”

Any message type lets you use messages as embedded types without having their .proto definition available in the particular proto file.

For packing and unpacking different message types to the Any message type we need runtime library helpers.

  • packFrom - This method enables the user to pack a random proto message type to the Any type.

  • unpackTo - This method enables the user to unpack a random message type from the parsed Any type.

Example usage of the methods->

write.chpl(code written by a user to set message field values and serialize these to byte stream)

var file = open("out", iomode.cw);
var writingChannel = file.writer();

var messageObj: anyTest; //object of the message type having the `anyfield`  
var obj: test; //object of any random message type (may or maybe not present in the same proto file as `anyTest` ).

obj.a = "chapel";
obj.b = true;
messageObj.anyfield.packFrom(obj); // pack `test` type obj to `Any`.

messageObj.serialize(writingChannel);

read.chpl(code written by another user to parse the input byte stream and access the set message field values )

var messageObj: anyTest;
var obj: test;
var file = open("out", iomode.r);
var readingChannel = file.reader();

messageObj.deserialize(readingChannel);

messageObj.anyfield.unpackTo(obj);

writeln(obj.a == "chapel"); // true
writeln(obj.b == true); // true

What names should we use for the methods currently called packFrom and unpackTo?

Common method names used by other languages are -