buffer.putValue(value[, valueSize[, valueType]])
value - the value, a number, to be put into the buffer at the position indicated by the cursor property.
valueSize - a positive number describing the number of bytes to be used and defaults to 1. The following are acceptable values: 1,2,3,4,8, and 10
valueType - One of the following types: "signed", "unsigned", or "float". The default type is: "signed."
The value is put into buffer at the current cursor position, and the cursor value is automatically incremented by the size of the value to reflect this addition.
This method puts the specified value into a buffer. The value must be a number. The parameter valueSize or both valueSize and valueType may be passed as additional parameters. The parameter valueSize is a positive number describing the number of bytes to be used and defaults to 1. Acceptable values for valueSize are 1, 2, 3, 4, 8, and 10, providing that it does not conflict with the optional valueType flag. (See listing below.)
The parameter valueType must be one of the following: "signed", "unsigned", or "float". It defaults to "signed." The valueType parameter describes the type of data to be read. Combined with valueSize, any type of data can be put. The following list describes the acceptable combinations of valueSize and valueType:
1 signed, unsigned
2 signed, unsigned
3 signed, unsigned
4 signed, unsigned, float
10 float (Not supported on every system)
Any other combination will cause an error. The value is put into buffer at the current cursor position, and the cursor value is automatically incremented by the size of the value to reflect this addition.
To explicitly put a value at a specific location
while preserving the cursor location,
do something similar to the following.
var oldCursor = foo.cursor;
// Save the old cursor location
foo.cursor = 20;
// Set to new location
// Put goo at offset 20
foo.cursor = oldCursor
// Restore cursor location
The value is put into the buffer with byte-ordering
according to the current setting of the .bigEndian
flag. Note that when putting float values as a
smaller size, such as 4, some significant figures
are lost. A value such as "1.4" will actually be
converted to something to the effect
of "1.39999974". This is sufficiently
insignificant to ignore, but note
that the following does not hold true.
foo.cursor -= 4;
if( foo.getValue(4,"float") != 1.4 )
// This is not necessarily true due
// to significant figure loss.
This situation can be prevented by using 8 or 10
as a valueSize instead of 4. A valueSize of 4
may still be used for floating point values,
but be aware that some loss of significant figures
may occur (though it may not be enough
to affect most calculations).