43 store.reserve(length);
45 for(
int i = 0; i < length; ++i)
store.push_back(packet[i]);
58 unsigned char *p_a =
reinterpret_cast<unsigned char*
>(&a);
80 return static_cast<unsigned int>(std::distance(
store.begin(),
iter_));
106 throw std::invalid_argument(
"Storage::readChar(): invalid position");
118 store.push_back(value);
130 int i =
static_cast<int>(
readChar());
131 if (i < 128)
return i;
132 else return (i - 256);
142 if (value < -128 || value > 127)
144 throw std::invalid_argument(
"Storage::writeByte(): Invalid value, not in [-128, 127]");
146 writeChar(
static_cast<unsigned char>( (value+256) % 256 ) );
157 return static_cast<int>(
readChar());
167 if (value < 0 || value > 255)
169 throw std::invalid_argument(
"Storage::writeUnsignedByte(): Invalid value, not in [0, 255]");
171 writeChar(
static_cast<unsigned char>( value ));
184 StorageType::const_iterator
end =
iter_;
185 std::advance(
end, len);
199 writeInt(
static_cast<int>(s.length()));
201 store.insert(
store.end(), s.begin(), s.end());
213 std::vector<std::string> tmp;
216 for (
int i = 0; i < len; i++)
231 std::vector<double> tmp;
234 for (
int i = 0; i < len; i++)
249 writeInt(
static_cast<int>(s.size()));
250 for (std::vector<std::string>::const_iterator it = s.begin(); it!=s.end() ; it++)
264 writeInt(
static_cast<int>(s.size()));
265 for (std::vector<double>::const_iterator it = s.begin(); it!=s.end() ; it++)
283 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
292 if (value < -32768 || value > 32767)
294 throw std::invalid_argument(
"Storage::writeShort(): Invalid value, not in [-32768, 32767]");
297 short svalue =
static_cast<short>(value);
298 unsigned char *p_svalue =
reinterpret_cast<unsigned char*
>(&svalue);
314 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
323 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
339 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
348 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
356 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
365 unsigned char *p_value =
reinterpret_cast<unsigned char*
>(&value);
374 store.insert(
store.end(), &(packet[0]), &(packet[length]));
382 std::copy(packet.begin(), packet.end(), std::back_inserter(
store));
399 if (std::distance(
iter_,
store.end()) <
static_cast<int>(num))
401 std::ostringstream msg;
402 msg <<
"tcpip::Storage::readIsSafe: want to read " << num <<
" bytes from Storage, "
403 <<
"but only " << std::distance(
iter_,
store.end()) <<
" remaining";
404 throw std::invalid_argument(msg.str());
412 const unsigned char hb = *
iter_;
425 store.insert(
store.end(), std::reverse_iterator<const unsigned char *>(
end), std::reverse_iterator<const unsigned char *>(
begin));
436 for (
int i = 0; i <
size; ++i)
441 for (
int i =
size - 1; i >= 0; --i)
450 std::ostringstream dump;
451 for(StorageType::const_iterator it =
store.begin(); it !=
store.end(); ++it)
454 if (it !=
store.begin())
456 dump << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(*it);
virtual void writePacket(unsigned char *packet, int length)
StorageType::const_iterator begin() const
virtual void writeFloat(float)
virtual unsigned char readChar()
virtual std::string readString()
virtual void writeString(const std::string &s)
virtual float readFloat()
virtual unsigned int position() const
virtual void writeInt(int)
StorageType::const_iterator end() const
virtual void writeDouble(double)
virtual int readUnsignedByte()
virtual void writeStringList(const std::vector< std::string > &s)
virtual void writeChar(unsigned char)
StorageType::const_iterator iter_
virtual void writeUnsignedByte(int)
StorageType::size_type size() const
virtual void writeDoubleList(const std::vector< double > &s)
unsigned char readCharUnsafe()
Read a byte without validity check.
std::string hexDump() const
Dump storage content as series of hex values.
void writeByEndianess(const unsigned char *begin, unsigned int size)
Write size elements of array begin according to endianess.
Storage()
Standard Constructor.
virtual void writeByte(int)
virtual void writeStorage(tcpip::Storage &store)
void readByEndianess(unsigned char *array, int size)
Read size elements into array according to endianess.
virtual std::vector< std::string > readStringList()
virtual void writeShort(int)
void checkReadSafe(unsigned int num) const
Check if the next num bytes can be read safely.
void init()
Used in constructors to initialize local variables.
virtual double readDouble()
virtual std::vector< double > readDoubleList()