Hind Forsum
Hind Forsum

Reputation: 10497

Other target types provided by protobuf and Serialized Array/String/Ostream

I read the tutorial of protobuf C++ programming guide, and it seems to provide SerializeWithCachedSizeToArray inside its .h function, and I can also call SerializeToString() and SerializeToOstream().

I wish to know:

(1) Does pb provide other default serialize/de-serialize functions for cpp code?

(2) How to use the generated function of

void SerializeWithCachedSizes(
  ::google::protobuf::io::CodedOutputStream* output

I searched google but didn't get when and where should I use CodedOutputStream.

Any explanations? Thanks.

Upvotes: 2

Views: 214

Answers (1)

xosp7tom
xosp7tom

Reputation: 2183

1) Three main operations must be done to serialize: a) calculate total size, b) encode, and c) dump. For example, SerializeWithCachedSizeToArray implies that a) use cached size, and c) dump to char Array.

Depending on how/where to do those operations, there are lots of variants of Serialize function and you can mix/match library-provided utility or what-you-wrote utility to create other types. The most common function would be 'SerializeToString/Ostream', as you can see. There are string, char array, ostream, zlibstream, to name a few.

2) CodedOutputStream is a utility class to encode tagged stream. Tag - the number you put in proto after '='. You instantiate it with dump target, such as stream, char array, etc...

Upvotes: 2

Related Questions