I need to create a byte array with deferent data types in it, For example: i will have data that will contain Byte (0-100), Byte(0-10), Two bytes(-30-+100), Bool(0/1), Byte, Two Bytes(0-300).
The client will receive the bytes array (using Buffer) and will get the data from the hax that Buffer creates by using offsets. So i need to always retain the number of bytes as in the API specs i'm getting from the client.
Example:
Battery.protorype.onSubscribe = function(maxValuesSize, updateValueCallback) {
var bytes = Array(6);
bytes[0] = 50;
bytes[1] = 2;
bytes[2] = -20;
bytes[3] = true;
bytes[4] = 32;
bytes[5] = 290;
updateValueCallback(new Buffer(bytes));
Will return: 0x3202ec012022
This of course is not good because of two things:
-20 is ec? and 290 is 22? (what happen to the first byte? 290 dec is 0x122 and this is two bytes)
Event if that was correct (if the numbers were contained in a single byte), I need to keep the sizes to maintain offsets and this does not maintain offsets as all the numbers over here are of size of one byte.
Does any one knows how to solve this issue?