C struct style buffer views for reading and writing structures of varying types.
$ component install component/struct
varstruct=require('struct');// buffer big enough for all 3 structsvarbuf=newUint8Array(3*(32+5+16));varPet=struct({id: 'uint32',name: 'string',age: 'uint16'});// writevartobi=newPet({id: 1,name: 'Tobi',age: 2});varloki=newPet({id: 2,name: 'Loki',age: 2});varjane=newPet({id: 3,name: 'Jane',age: 6});varoff=0;varpets=[tobi,loki,jane];for(vari=0;i<pets.length;i++){off=pets[i].write(buf,off);}// readvarn=3;varoff=0;varpet=newPet;while(n--){off=pet.read(buf,off);console.log('%s (%s) is %s years old',pet.name,pet.id,pet.age);}...
MIT