back to index
Buffer
- a simple and general purpose binary buffer
- supports the << serialization operator
- transparent byte order conversion
- can be accessed by custom C++ extensions (e.g. used for TCP/IP networking)
Inheritance
Object -> Stream -> Buffer
Properties
size -(read-write), stores the current buffer size in bytes
byteOrder - BIG_ENDIAN or LITTLE_ENDIAN
offset -current byte offset (stream interface)
Methods
fillZero () - quickly zero <size> elements using memset
free () - delete buffer content, reset size and offset.
int getByteOrder () - return current buffer byteorder (BIG_ENDIAN/LITTLE_ENDIAN)
int getOffset () - return current read/write offset
int getSize () - return size of buffer
String getString (int _off, int _len) - extract a string from the buffer. if _len is 0, chars are copied until ASCIIZ is found
int gunzip (Buffer _src, int _off, int _clen, int _ulen) - compress buffer. adjust size, reset offset.
int gzip (Buffer _src, int _off, int _ulen, int _level) - uncompress buffer. adjust size, reset offset.
int peekI8 (int _off) - read byte at _off
int peekI16 (int _off) - read short at _off. swap byteorder if necessary.
int peekI32 (int _off) - read long at _off. swap byteorder if necessary.
int peekF32 (int _off) - read IEEE float at _off.
pokeI8 (int _off, int _val) - write byte to _off
pokeI16 (int _off, int _val) - write short to _off. convert byteorder if necessary.
pokeI32 (int _off, int _val) - write long to _off. convert byteorder if necessary.
pokeF32 (int _off, int _val) - write float to _off.
resize (int _size) - resize buffer. preserve elements (if _size>size).
setByteOrder (int _type) - set buffer byteorder (BIG_ENDIAN/LITTLE_ENDIAN).
setOffset (int _off) - set current read/write offset
setSize (int _size) - free buffer/discard elements and allocate new buffer
int setString (int _off, String _s) write string _s to offset _off in buffer
<Stream methods>
Examples
Buffer b; b.size=4096;
b.i8=1;
b.i16=24;
b.i32=0xdeadbeef;
b.f32=3.1415;
print "b.offset="+b.offset;
StdOutStream.writeBuffer(b, 0, b.offset);
back to index