LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Namespaces | Classes | Functions
LogCabin::Core::ProtoBuf Namespace Reference

Namespaces

namespace  Internal

Classes

struct  InputStream
 An abstract stream from which ProtoBufs may be read. More...
struct  OutputStream
 An abstract stream to which ProtoBufs may be written. More...

Functions

std::string dumpString (const google::protobuf::Message &protoBuf, bool forCopyingIntoTest=false)
 Dumps a protocol buffer message.
std::unique_ptr
< google::protobuf::Message > 
copy (const google::protobuf::Message &protoBuf)
 Copy the contents of a protocol buffer into a new one.
bool parse (const Core::Buffer &from, google::protobuf::Message &to, uint32_t skipBytes=0)
 Parse a protocol buffer message out of a Core::Buffer.
void serialize (const google::protobuf::Message &from, Core::Buffer &to, uint32_t skipBytes=0)
 Serialize a protocol buffer message into a Core::Buffer.
template<typename ProtoBuf >
ProtoBuf fromString (const std::string &str)
 Create a protocol buffer message form a text format.

Function Documentation

std::string LogCabin::Core::ProtoBuf::dumpString ( const google::protobuf::Message &  protoBuf,
bool  forCopyingIntoTest = false 
)

Dumps a protocol buffer message.

This is useful for debugging and for testing.

Parameters:
protoBufThe protocol buffer message to dump out. It is safe to call this even if you haven't filled in all required fields, but the generated string will not be directly parse-able.
forCopyingIntoTestIf set to true, this will return a string in a format most useful for writing unit tests. You can basically copy and paste this from your terminal into your test file without manual processing. If set to false (default), the output will be nicer to read but harder to copy into a test file.
Returns:
Textual representation. This will be printable ASCII; binary will be escaped.

Definition at line 90 of file ProtoBuf.cc.

std::unique_ptr< google::protobuf::Message > LogCabin::Core::ProtoBuf::copy ( const google::protobuf::Message &  protoBuf)

Copy the contents of a protocol buffer into a new one.

Definition at line 132 of file ProtoBuf.cc.

bool LogCabin::Core::ProtoBuf::parse ( const Core::Buffer &  from,
google::protobuf::Message &  to,
uint32_t  skipBytes = 0 
)

Parse a protocol buffer message out of a Core::Buffer.

Parameters:
fromThe Core::Buffer from which to extract a protocol buffer.
[out]toThe empty protocol buffer to fill in with the contents of the Core::Buffer.
skipBytesThe number of bytes to skip at the beginning of 'from' (defaults to 0).
Returns:
True if the protocol buffer was parsed successfully; false otherwise (for example, if a required field is missing).

Definition at line 140 of file ProtoBuf.cc.

void LogCabin::Core::ProtoBuf::serialize ( const google::protobuf::Message &  from,
Core::Buffer &  to,
uint32_t  skipBytes = 0 
)

Serialize a protocol buffer message into a Core::Buffer.

Parameters:
fromThe protocol buffer containing the contents to serialize into the Core::Buffer. All required fields must be set or this will PANIC.
[out]toThe Core::Buffer to fill in with the contents of the protocol buffer.
skipBytesThe number of bytes to allocate at the beginning of 'to' but leave uninitialized for someone else to fill in (defaults to 0).

Definition at line 157 of file ProtoBuf.cc.

template<typename ProtoBuf >
ProtoBuf LogCabin::Core::ProtoBuf::fromString ( const std::string &  str)

Create a protocol buffer message form a text format.

This is useful for testing.

Template Parameters:
ProtoBufA derived class of ProtoBuf::Message.
Parameters:
strThe string representation of the protocol buffer message. Fields that are missing will not throw an error, but the resulting protocol buffer may be less useful.
Returns:
The parsed protocol buffer.

Definition at line 81 of file ProtoBuf.h.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines