tuningfork::ByteStream

#include <protobuf_nano_util.h>

关于 vec 中提供的字节的视图。

摘要

如果需要更多字节,Write 将调用 realloc,且调用方负责释放已分配的数据。

可以设置 vec=nullptrsize=0,在这种情况下,将使用 malloc 分配 vec

公共属性

it
size_t
解码或编码时在数据流中的当前位置。
size
size_t
vec 所指向的字节数大小。
vec
uint8_t *
指向数据流表示的字节数的指针。

公共静态函数

Read(pb_istream_t *stream, uint8_t *buf, size_t count)
bool
将数据流中的 count 字节读取至给定缓冲区。
Write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
bool
将给定缓冲区中的 count 字节写入数据流。

公共属性

it

size_t tuningfork::ByteStream::it

解码或编码时在数据流中的当前位置。

size

size_t tuningfork::ByteStream::size

vec 所指向的字节数大小。

vec

uint8_t * tuningfork::ByteStream::vec

指向数据流表示的字节数的指针。

公共静态函数

读取

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

将数据流中的 count 字节读取至给定缓冲区。

具体说明
参数
stream
需读取的数据流。
buf
需写入的缓冲区。
count
需读取的字节数。
返回值
如果成功则为 true;如果出现读取错误则为 false。

Write

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

将给定缓冲区中的 count 字节写入数据流。

具体说明
参数
stream
需写入的数据流。
buf
需读取的缓冲区。
count
需写入的字节数。
返回值
如果成功则为 true;如果出现写入错误则为 false。