| 15 | namespace Protobuf |
| 16 | { |
| 17 | bool InputStream::decode(const pb_msgdesc_t* fields, void* dest_struct) |
| 18 | { |
| 19 | int avail = stream.available(); |
| 20 | if(avail <= 0) { |
| 21 | return false; |
| 22 | } |
| 23 | pb_istream_t is{}; |
| 24 | is.callback = [](pb_istream_t* stream, pb_byte_t* buf, size_t count) -> bool { |
| 25 | auto self = static_cast<InputStream*>(stream->state); |
| 26 | assert(self != nullptr); |
| 27 | self->stream.readBytes(reinterpret_cast<char*>(buf), count); |
| 28 | return true; |
| 29 | }; |
| 30 | is.state = this; |
| 31 | is.bytes_left = size_t(avail); |
| 32 | is.errmsg = nullptr; |
| 33 | return pb_decode(&is, fields, dest_struct); |
| 34 | } |
| 35 | |
| 36 | size_t OutputStream::encode(const pb_msgdesc_t* fields, const void* src_struct) |
| 37 | { |