8 #ifndef NT_WIREDECODER_H_ 9 #define NT_WIREDECODER_H_ 13 #include "networktables/NetworkTableValue.h" 14 #include "support/leb128.h" 15 #include "support/raw_istream.h" 33 void set_proto_rev(
unsigned int proto_rev) { m_proto_rev = proto_rev; }
36 unsigned int proto_rev()
const {
return m_proto_rev; }
42 void Reset() { m_error =
nullptr; }
47 const char* error()
const {
return m_error; }
49 void set_error(
const char* error) { m_error = error; }
56 bool Read(
const char** buf, std::size_t len) {
57 if (len > m_allocated) Realloc(len);
59 m_is.read(m_buf, len);
61 if (m_logger.min_level() <= NT_LOG_DEBUG4 && m_logger.HasLogger()) {
62 std::ostringstream oss;
63 oss <<
"read " << len <<
" bytes:" << std::hex;
67 for (std::size_t i=0; i < len; ++i)
68 oss <<
' ' << (
unsigned int)((*buf)[i]);
70 m_logger.Log(NT_LOG_DEBUG4, __FILE__, __LINE__, oss.str().c_str());
73 return !m_is.has_error();
77 bool Read8(
unsigned int* val) {
79 if (!Read(&buf, 1))
return false;
80 *val = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
85 bool Read16(
unsigned int* val) {
87 if (!Read(&buf, 2))
return false;
88 unsigned int v = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
91 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
97 bool Read32(
unsigned long* val) {
99 if (!Read(&buf, 4))
return false;
100 unsigned int v = (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
103 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
106 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
109 v |= (*
reinterpret_cast<const unsigned char*
>(buf)) & 0xff;
115 bool ReadDouble(
double* val);
118 bool ReadUleb128(
unsigned long* val) {
return wpi::ReadUleb128(m_is, val); }
120 bool ReadType(NT_Type* type);
121 bool ReadString(std::string* str);
122 std::shared_ptr<Value> ReadValue(NT_Type type);
129 unsigned int m_proto_rev;
136 void Realloc(std::size_t len);
148 std::size_t m_allocated;
153 #endif // NT_WIREDECODER_H_ Definition: raw_istream.h:23
Definition: IEntryNotifier.h:15
Definition: WireDecoder.h:27