Set the UBinary you want to parse. You have to call the 'set' function before calling the 'read' function. Return 0 in case of success, and 1 in case of error.
Read formated binary data from the UBinary, and return a list corresponding to the data which was read.
'format' is a list of type identifiants separated by ','.
The type identifiants describe a type, and are of the form Type[:n] where Type can be:
and where 'n' specify the number of time the UBinaryReader should read a value of this type.
'n' is optional (that is the meaning of the enclosing '[' ']' which are not part of the syntax).
The function return a list of values corresponding to the data read. In case of character data, if you specify the 'n' parameter, then the characters are concateneted and put in a string.
ex:
p = new UBinaryReader();
a = BIN 10;abcdefghij /// Create an UBinary which contains abcdefghij
p.set (a); /// Set the UBinary in the reader.
p.read ("c,i8"); /// we read: a character then an 8 bits integer
[00175588] ["a", 98] /// a is for the 'a' and 98 for the 'b' (8 bit ascii
/// code is 98)
p.index = 0; /// Set the reading cursor to the begining.
p.read ("c,c:3,i8:2,i16"),
[00161064] ["a", "bcd", 101, 102, 26727]
p.index = 4; /// Set the reading cursor to read the 5th character
p.read ("c:5"),
[00169480] ["efghi"]
In case of error, the function stop reading, and return a list containing the values that were successfully read until the error occur. The function then set the reading cursor 'index' to -1, and set an error message in the 'error' attribute.
Index of the reading cursor. When you read from an UBinary with the 'read' function, this index is automatically updated so that the next read will occur where the previous read stopped.
You can change the position of the reading cursor by assigning a new value to 'index'. Note that the begining of the UBinary is associated to a value of 0 for 'index'.
'index' cannot be greater than the UBinary size.
When a reading error occur, 'index' is set to -1, and you have to change it's value manually to continue reading.
The size of the UBinary currently read.
In case of error, this attribute contains a readable error message corresponding to the error.