8 #ifndef NTCORE_WIREDECODER_H_ 9 #define NTCORE_WIREDECODER_H_ 17 #include <support/leb128.h> 18 #include <support/raw_istream.h> 21 #include "networktables/NetworkTableValue.h" 38 void set_proto_rev(
unsigned int proto_rev) { m_proto_rev = proto_rev; }
41 unsigned int proto_rev()
const {
return m_proto_rev; }
47 void Reset() { m_error =
nullptr; }
52 const char* error()
const {
return m_error; }
54 void set_error(
const char* error) { m_error = error; }
61 bool Read(
const char** buf,
size_t len) {
62 if (len > m_allocated) Realloc(len);
64 m_is.read(m_buf, len);
66 if (m_logger.min_level() <= NT_LOG_DEBUG4 && m_logger.HasLogger()) {
67 std::ostringstream oss;
68 oss <<
"read " << len <<
" bytes:" << std::hex;
72 for (
size_t i = 0; i < len; ++i)
73 oss <<
' ' << static_cast<unsigned int>((*buf)[i]);
75 m_logger.Log(NT_LOG_DEBUG4, __FILE__, __LINE__, oss.str().c_str());
78 return !m_is.has_error();
82 bool Read8(
unsigned int* val) {
84 if (!Read(&buf, 1))
return false;
85 *val = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
90 bool Read16(
unsigned int* val) {
92 if (!Read(&buf, 2))
return false;
93 unsigned int v = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
96 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
102 bool Read32(uint32_t* val) {
104 if (!Read(&buf, 4))
return false;
105 unsigned int v = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
108 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
111 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
114 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
120 bool ReadDouble(
double* val);
123 bool ReadUleb128(uint64_t* val) {
return wpi::ReadUleb128(m_is, val); }
125 bool ReadType(NT_Type* type);
126 bool ReadString(std::string* str);
127 std::shared_ptr<Value> ReadValue(NT_Type type);
134 unsigned int m_proto_rev;
141 void Realloc(
size_t len);
158 #endif // NTCORE_WIREDECODER_H_ Definition: raw_istream.h:21
Definition: IEntryNotifier.h:16
Definition: WireDecoder.h:32