[fpc-pascal] How to use Google Protocol Buffer

Dennis dec12 at avidsoft.com.hk
Mon Jul 9 18:40:35 CEST 2018


To connect to a server, I need to use Google's Protocol Buffer format.

The only workable parser to convert the protocol definition file to 
pascal reader/writer source code is:

the ProtoBufCodeGen in
https://github.com/fundamentalslib/fundamentals5/releases

Still, there is no documentation on how to call the generated codes.

For example, it generated these:

procedure RequestRecordInit(var A: TRequestRecord);
procedure RequestRecordFinalise(var A: TRequestRecord);

function  pbEncodeDataRequestRecord(var Buf; const BufSize: Integer; 
const A: TRequestRecord): Integer;

function  pbDecodeValueRequestRecord(const Buf; const BufSize: Integer; 
var Value: TRequestRecord): Integer;

function  pbEncodeFieldRequestRecord(var Buf; const BufSize: Integer; 
const FieldNum: Integer; const A: TRequestRecord): Integer;
procedure pbDecodeFieldRequestRecord(const Field: 
TpbProtoBufDecodeField; var Value: TRequestRecord);


I could call pbEncodeDataRequestRecord to convert the TRequestRecord to 
a stream of byte and store in the Buf
but there is not a routine to convert it back from a stream of bytes to 
the TRequestRecord.

The only seemingly useful routine pbDecodeValueRequestRecord, when 
called with the Buf generated by pbEncodeDataRequestRecord will raise 
exception "Invalid buffer "

Any help?

Dennis




More information about the fpc-pascal mailing list