|
ASL
|
This class is a buffer that can be written to as a binary stream.
The buffer is initially empty and grows as you append variables. You can change endianness at any moment.
You can then get the content as a ByteArray and for example write it to a file or send it through a socket.
#include <StreamBuffer.h>
Inherits Array< byte >.
Public Member Functions | |
| void | setEndian (Endian e) |
| Set endianness for binary writing. | |
| template<class T > | |
| StreamBuffer & | operator<< (const T &x) |
| Writes variable x to the buffer respecting endianness in binary form. | |
Public Member Functions inherited from Array< byte > | |
| Array () | |
| Creates an empty array. | |
| Array (int n) | |
| Creates an array of n elements. | |
| Array (const byte *p, int n) | |
| Creates an array of n elements and copies them from the pointer p. | |
| Array (int n, const byte &x) | |
| Creates an array of n elements and gives them the value x. | |
| Array & | operator= (const Array &b) |
| Assigns array b into this array by reference. | |
| bool | operator== (const Array &b) const |
| Tests for equality of all elements of both arrays. | |
| Array< K > | with () const |
| Returns a copy of this array with all element converted to another type. | |
| int | length () const |
| Returns the number of elements in the array. | |
| Array & | reserve (int m) |
| Reserves space for m elements without increasing actual length (to make appending faster) | |
| Array & | resize (int m) |
| Resizes the array to m elements; up to m existing elements are preserved. | |
| void | clear () |
| Removes all elements in the array. | |
| operator const byte * () const | |
| Returns a pointer to the base of the array. | |
| byte * | data () |
| Returns a pointer to the first element. | |
| const byte * | data () const |
| Returns a pointer to the first element. | |
| operator byte * () | |
| Returns a pointer to the base of the array. | |
| const byte * | ptr () const |
| Returns a pointer to the first element. | |
| byte * | ptr () |
| Returns a pointer to the first element. | |
| const byte & | operator[] (int i) const |
| Returns the element at index i. | |
| byte & | operator[] (int i) |
| Returns the element at index i. | |
| const byte & | last () const |
| Returns a reference to the last element. | |
| byte & | last () |
| Returns a reference to the last element. | |
| int | indexOf (const byte &x, int j=0) const |
| Returns the index of the first element with value x; The search starts at position j; The value -1 is returned if no such element is found. | |
| bool | contains (const byte &x) const |
| Returns true if the array contains an element equal to x. | |
| Array & | dup () |
| Makes this array independent of others. | |
| Array | clone () const |
| Returns an independent copy of this array. | |
| void | copy (const Array &b) |
| Copies another array's contents into this array. | |
| void | copy (const byte *p, int n) |
| Copies n elements pointed to by p (the array is resized to n) | |
| Array & | operator<< (const byte &x) |
| Adds element x at the end of the array. | |
| Array & | operator, (const byte &x) |
The same as <<, useful to create pseudo-array-literals. | |
| Array & | remove (int i, int n=1) |
| Removes n elements (1 be default) starting at position i. | |
| bool | removeOne (const byte &x, int i0=0) |
| Removes the first element with value x starting at index i0; Returns true if an element was found and removed. | |
| Array & | insert (int k, const byte &x) |
| Inserts x at position k. | |
| Array | reversed () const |
| Returns the elements of the array in reversed order. | |
| Array | slice (int i1, int i2=0) const |
| Returns a section of the array, from element i1 up to but not including element i2; If i2 is omitted the subarray will take elements up te the last. | |
| Array & | append (const Array &b) |
| Adds all elements from array b at the end of the array. | |
| Array & | append (const byte *p, int n) |
| Adds n elements from array pointed by p at the end of this array. | |
| Array | concat (const Array &b) const |
| Returns the concatenation of this array and b. | |
| Array | operator| (const Array &b) const |
| Returns the concatenation of this array and b. | |
| Array & | sort () |
| Sorts the array using the elements' < operator "in place". | |
| Array & | sort (Less f) |
| Sorts the array using the elements' < operator "in place". | |
| Array & | sortBy (F f, bool ascending=true) |
| Sorts the array by the elements' f comparable property (in ascending order by default) | |
| String | join (const String &sep) const |
| Returns a string representation of the array, formed by joining its elements with the given separator string sep; The elements need to be convertible to String. | |
| Array | map (F f) const |
| Returns an array formed by applying a function to each item. | |
| Array< K > | map_ (F f) const |
| Returns an array of another type formed by applying a function to each item. | |
| Array | filter (F f) const |
| Returns an array containing the items in this array satisfying a condition. | |
| Array & | removeIf (F f) |
| Removes items that meet a predicate. | |
| Array & | removeLast () |
| Removes the last item in the array. | |