39 #ifndef CRL_MULTISENSE_BUFFERSTREAM_HH 40 #define CRL_MULTISENSE_BUFFERSTREAM_HH 52 namespace multisense {
75 #ifndef SENSORPOD_FIRMWARE 77 #endif // SENSORPOD_FIRMWARE 79 virtual void read (
void *bufferP, std::size_t length) {
84 virtual void write(
const void *bufferP, std::size_t length) {
93 void seek(std::size_t idx) {
119 m_bufferP =
new (std::nothrow) uint8_t[size];
138 #ifdef SENSORPOD_FIRMWARE 155 #ifndef SENSORPOD_FIRMWARE 157 #endif // SENSORPOD_FIRMWARE 169 #ifndef SENSORPOD_FIRMWARE 171 #endif // SENSORPOD_FIRMWARE 183 #ifndef SENSORPOD_FIRMWARE 185 #endif // SENSORPOD_FIRMWARE 200 virtual void read (
void *bufferP, std::size_t length) {
203 CRL_EXCEPTION(
"read overflow: tell=%d, size=%d, length=%d\n",
211 this->
read(&value,
sizeof(T));
221 for(uint32_t i=0; i<num; i++)
229 this->
read(&length,
sizeof(length));
233 else if (length > 0) {
235 buffer[length] =
'\0';
236 this->
read(buffer, length);
237 value = std::string(buffer);
244 uint32_t microseconds;
246 this->
read(&seconds,
sizeof(seconds));
247 this->
read(µseconds,
sizeof(microseconds));
249 value = seconds + 1e-6 * microseconds;
267 virtual void write(
const void *bufferP, std::size_t length) {
270 CRL_EXCEPTION(
"write overflow: tell=%d, size=%d, length=%d\n",
278 this->
write(&value,
sizeof(T));
283 uint16_t version = T::VERSION;
284 uint32_t num =
static_cast<uint32_t
> (v.size());
287 for(uint32_t i=0; i<num; i++)
288 const_cast<T*>(&v[i])->serialize(*
this, version);
293 size_t length = value.
size();
298 uint16_t length16 =
static_cast<uint16_t
> (length);
299 this->
write(&length16,
sizeof(length16));
302 this->
write(value.c_str(), length);
310 this->
write(&seconds,
sizeof(seconds));
311 this->
write(µseconds,
sizeof(microseconds));
virtual void read(void *bufferP, std::size_t length)
#define CRL_EXCEPTION(fmt,...)
BufferStreamWriter(BufferStream &s)
BufferStreamWriter & operator&(const TimeStamp &value)
BufferStreamReader(const uint8_t *p, std::size_t s)
virtual void write(const void *bufferP, std::size_t length)
uint32_t getSeconds() const
BufferStreamWriter & operator&(const T &value)
BufferStreamWriter & operator&(const std::string &value)
virtual void write(const void *bufferP, std::size_t length)
BufferStreamReader & operator&(TimeStamp &value)
BufferStreamReader(BufferStream &s)
BufferStream(uint8_t *bufP, std::size_t size)
void serialize(Stream &stream, const T &t)
virtual void read(void *bufferP, std::size_t length)
BufferStreamWriter & operator&(const std::vector< T > &v)
void seek(std::size_t idx)
BufferStreamWriter(uint8_t *b, std::size_t s)
BufferStreamReader & operator&(std::vector< T > &v)
BufferStream(const BufferStream &source)
BufferStreamReader(std::size_t s)
BufferStreamWriter(std::size_t s)
uint32_t getMicroSeconds() const
BufferStream & operator=(const BufferStream &source)
BufferStreamReader & operator&(std::string &value)
BufferStream(std::size_t size)
BufferStreamReader & operator&(T &value)