27 #include <boost/predef/other/endian.h>
30 namespace RobotRaconteur
33 class ROBOTRACONTEUR_CORE_API ArrayBinaryReader :
private boost::noncopyable
36 ArrayBinaryReader(
const uint8_t* buffer,
size_t start_position,
size_t length,
bool nativeorder =
false);
38 size_t Length()
const;
40 size_t Position()
const;
41 void Seek(
size_t position);
43 size_t Read(
void* buffer,
size_t index,
size_t length);
49 Read(
reinterpret_cast<uint8_t*
>(&out), 0,
sizeof(T));
50 #if BOOST_ENDIAN_BIG_BYTE
52 std::reverse(
reinterpret_cast<uint8_t*
>(&out), (
reinterpret_cast<uint8_t*
>(&out)) +
sizeof(T));
57 void ReadArray(RR_INTRUSIVE_PTR<RRBaseArray>& arr);
59 MessageStringPtr ReadString8(
size_t length);
62 uint64_t ReadUintX2();
71 size_t CurrentLimit();
73 void PushRelativeLimit(
size_t limit);
75 void PushAbsoluteLimit(
size_t limit);
79 int32_t DistanceFromLimit();
82 const uint8_t* buffer;
87 #ifdef ROBOTRACONTEUR_USE_SMALL_VECTOR
88 boost::container::small_vector<size_t, 8> limits;
90 std::vector<size_t> limits;
94 class ROBOTRACONTEUR_CORE_API ArrayBinaryWriter :
private boost::noncopyable
97 ArrayBinaryWriter(uint8_t* buffer,
size_t start_position,
size_t length,
bool nativeorder =
false);
99 size_t Length()
const;
101 size_t Position()
const;
102 void Seek(
size_t position);
104 size_t Write(
const void* buffer,
size_t index,
size_t length);
106 template <
typename T>
107 void WriteNumber(T number)
109 void* n1 =
static_cast<void*
>(&number);
110 #if BOOST_ENDIAN_BIG_BYTE
112 std::reverse(
static_cast<uint8_t*
>(n1), (
static_cast<uint8_t*
>(n1)) +
sizeof(T));
114 Write(
static_cast<uint8_t*
>(n1), 0,
sizeof(T));
117 void WriteArray(RR_INTRUSIVE_PTR<RRBaseArray>& arr);
119 void WriteString8(MessageStringRef str);
120 void WriteString8WithXLen(MessageStringRef str);
122 void WriteUintX(uint32_t v);
123 void WriteUintX2(uint64_t v);
125 void WriteIntX(int32_t v);
126 void WriteIntX2(int64_t v);
128 static size_t GetStringByteCount8(MessageStringRef str);
129 static size_t GetStringByteCount8WithXLen(MessageStringRef str);
131 static size_t GetUintXByteCount(uint32_t v);
132 static size_t GetUintX2ByteCount(uint64_t v);
134 static size_t GetSizePlusUintX(
size_t s);
136 static size_t GetIntXByteCount(int32_t v);
137 static size_t GetIntX2ByteCount(int64_t v);
143 size_t CurrentLimit();
145 void PushRelativeLimit(
size_t limit);
147 void PushAbsoluteLimit(
size_t limit);
151 int32_t DistanceFromLimit();
159 #ifdef ROBOTRACONTEUR_USE_SMALL_VECTOR
160 boost::container::small_vector<size_t, 8> limits;
162 std::vector<size_t> limits;