1 #include "networktables2/connection/DataIOStream.h"
12 virtual int read(
void* ptr,
int numbytes) {
return numbytes;}
13 virtual int write(
const void* ptr,
int numbytes) {
return numbytes;}
14 virtual void flush() {}
15 virtual void close() {}
20 DataIOStream::DataIOStream(
IOStream* _iostream) :
24 DataIOStream::~DataIOStream()
27 if (iostream!=&s_InertStream)
31 void DataIOStream::SetIOStream(
IOStream* stream)
34 iostream=stream ? stream : &s_InertStream;
35 if (temp!=&s_InertStream)
39 void DataIOStream::close()
44 void DataIOStream::writeByte(uint8_t b)
46 iostream->write(&b, 1);
48 void DataIOStream::write2BytesBE(uint16_t s)
50 writeByte((uint8_t)(s >> 8));
51 writeByte((uint8_t)s);
53 void DataIOStream::writeString(std::string& str)
55 write2BytesBE(str.length());
56 iostream->write(str.c_str(), str.length());
58 void DataIOStream::flush()
62 uint8_t DataIOStream::readByte()
65 iostream->read(&value, 1);
68 uint16_t DataIOStream::read2BytesBE()
71 value = readByte()<<8 | readByte();
74 std::string* DataIOStream::readString()
77 unsigned int byteLength = read2BytesBE();
79 uint8_t bytes[byteLength+1];
81 uint8_t* bytes = (uint8_t*)alloca(byteLength+1);
83 iostream->read(bytes, byteLength);
84 bytes[byteLength] = 0;
85 return new std::string((
char*)bytes);
This is used in case NULL is passed so all logic calls to IOstream can continue to assume there is ne...