hedera-services icon indicating copy to clipboard operation
hedera-services copied to clipboard

Write protobuf delimited events to PCES and gossip

Open lpetrovic05 opened this issue 5 months ago • 1 comments

Atm, the events serialized to PCES and gossip use protobuf, but the field length is determined externally, outside of PBJ. This is because there is no simple API to write a delimited message using the PBJ codec. In order to write an event as a delimited message, the following approach would need to be taken:

FieldDefinition EVENT_CORE = new FieldDefinition("gossip_event", FieldType.MESSAGE, false, false, false, 0);
ProtoWriterTools.writeDelimited(writableSequentialData, fieldDefinition, GossipEvent.PROTOBUF.measureRecord(record), out -> GossipEvent.PROTOBUF.write(record, out));

This is not a friendly API. It would be better for the Codec to have methods like writeDelimited and parseDelimited. To make it even simpler, the records could have methods write and writeDelimited, so that we don't need to reference the codec at all when writing.

The writeDelimited and parseDelimited methods should also have extra checks to see if the appropriate amount of data was written/read.

This needs a discussion on what the best way forward is.

lpetrovic05 avatar Sep 18 '24 10:09 lpetrovic05