Skip to content

Repository files navigation

struct

C struct style buffer views for reading and writing structures of varying types.

Installation

$ component install component/struct

Example

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);}

API

...

License

MIT

About

C style structs for reading and writing to Uint8Arrays

Resources

Stars

9 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages