Consider this C structure:
struct someStruct {
unsigned long id;
char username[16];
float amountDue;
};
You can access a buffer containing data in this format like this:
var buffer = new ArrayBuffer(24);
// ... read the data into the buffer ...
var idView = new Uint32Array(buffer, 0, 1);
var usernameView = new Uint8Array(buffer, 4, 16);
var amountDueView = new Float32Array(buffer, 20, 1);
In the case of say, the ISP_TINY packet, that looks like this:
struct ISP_TINY {
byte Size = 4;
byte Type = ISP_TINY;
byte SubT = NULL;
byte ReqI = NULL;
};
var Packet = new ArrayBuffer(256);
var Size = new UInt8Array(Packet, 0, 1);
var Type = new UInt8Array(Packet, 1, 1);
var SubT = new UInt8Array(Packet, 2, 1);
var ReqI = new UInt8Array(Packet, 3, 1);