Chapel: Review of protobuf Any message type user-end APIs

Created on 25 Aug 2020  路  6Comments  路  Source: chapel-lang/chapel

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.

We need to choose names for the above two methods, currently called packFrom and unpackTo.

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

Common method names used by other languages are -

| Language | Write function | Parse function |
| ------------- | ------------- | ------------- |
| C++ | PackFrom | UnpackTo |
| Python | Pack | Unpack |
| JAVA | pack | unpack |

protobuf

Most helpful comment

I'd be inclined to use pack/unpack over packFrom/unpackTo for the sake of brevity. Do the prepositions add any value? (e.g., are there other types of pack/unpack that we expect to support?). I think we should use initial lowercase method names for consistency with other Chapel method names, as in your example code.

All 6 comments

@mppf @lydia-duncan please have a look!

I'd be inclined to use pack/unpack over packFrom/unpackTo for the sake of brevity. Do the prepositions add any value? (e.g., are there other types of pack/unpack that we expect to support?). I think we should use initial lowercase method names for consistency with other Chapel method names, as in your example code.

I second Brad in favoring pack and unpack. Thematically that puts these two verbs in line with serialize and deserialize (where the words themselves already imply directionality).

Do the prepositions add any value? (e.g., are there other types of pack/unpack that we expect to support?).

No, I don't think that we will have any other types of pack/unpack.

Thematically that puts these two verbs in line with serialize and deserialize (where the words themselves already imply directionality).

Yeah!..that makes sense.

@Aniket21mathur - it sounds like we have enough agreement to go with pack / unpack. Can you update PRs #16297 and #16309 with the change so that they can be merged? Thanks!

Yeah....Sure :)

Was this page helpful?
0 / 5 - 0 ratings