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) {
82 virtual void write(
const void *bufferP, std::size_t length) {
89 void seek(std::size_t idx) {
115 m_bufferP =
new (std::nothrow) uint8_t[size];
134 #ifdef SENSORPOD_FIRMWARE 151 #ifndef SENSORPOD_FIRMWARE 153 #endif // SENSORPOD_FIRMWARE 163 #ifndef SENSORPOD_FIRMWARE 165 #endif // SENSORPOD_FIRMWARE 180 virtual void read (
void *bufferP, std::size_t length) {
183 CRL_EXCEPTION(
"read overflow: tell=%d, size=%d, length=%d\n",
191 this->
read(&value,
sizeof(T));
201 for(uint32_t i=0; i<num; i++)
209 this->
read(&length,
sizeof(length));
213 else if (length > 0) {
215 buffer[length] =
'\0';
216 this->
read(buffer, length);
217 value = std::string(buffer);
224 uint32_t microseconds;
226 this->
read(&seconds,
sizeof(seconds));
227 this->
read(µseconds,
sizeof(microseconds));
229 value = seconds + 1e-6 * microseconds;
247 virtual void write(
const void *bufferP, std::size_t length) {
250 CRL_EXCEPTION(
"write overflow: tell=%d, size=%d, length=%d\n",
258 this->
write(&value,
sizeof(T));
263 uint16_t version = T::VERSION;
264 uint32_t num = v.
size();
267 for(uint32_t i=0; i<num; i++)
268 const_cast<T*>(&v[i])->serialize(*
this, version);
273 uint16_t length = value.
size();
278 this->
write(&length,
sizeof(length));
280 this->
write(value.c_str(), length);
288 this->
write(&seconds,
sizeof(seconds));
289 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
BufferStreamReader & operator&(std::string &value)
BufferStream(std::size_t size)
BufferStreamReader & operator&(T &value)