tuningfork::VectorStream

#include <protobuf_nano_util.h>

A view on the vector provided in vec.

Summary

No ownership is taken.

Details
Parameters
vec
Example usage:
std::vector<uint8_t> v;
VectorStream str {&v, 0};
pb_ostream_t stream = {VectorStream::Write, &str, SIZE_MAX, 0};
pb_encode(&stream, ...);

Public attributes

it
size_t
The current position in the vector while decoding or encoding.
vec
std::vector< uint8_t > *
A vector of bytes that must be valid while Read or Write are called.

Public static functions

Read(pb_istream_t *stream, uint8_t *buf, size_t count)
bool
Read count bytes from the stream to the given buffer.
Write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
bool
Write count bytes from the given buffer to the stream.

Public attributes

it

size_t tuningfork::VectorStream::it

The current position in the vector while decoding or encoding.

vec

std::vector< uint8_t > * tuningfork::VectorStream::vec

A vector of bytes that must be valid while Read or Write are called.

The vector will be resized as needed by Write.

Public static functions

Read

bool tuningfork::VectorStream::Read(
  pb_istream_t *stream,
  uint8_t *buf,
  size_t count
)

Read count bytes from the stream to the given buffer.

Details
Parameters
stream
The stream to read from.
buf
The buffer to write to.
count
The number of bytes to read.
Returns
true if successful, false on a read error.

Write

bool tuningfork::VectorStream::Write(
  pb_ostream_t *stream,
  const uint8_t *buf,
  size_t count
)

Write count bytes from the given buffer to the stream.

Details
Parameters
stream
The stream to write to.
buf
The buffer to read from.
count
The number of bytes to write.
Returns
true if successful, false on a write error.