struct-parser
v0.0.0
Published
USAGE =============================================================
Downloads
3
Readme
USAGE
var sp = require("struct-parser"); var br = require("bufferreader");
assume: buffer = NetStreamBuffer;
var structFCgiHeader = [ {name:"version", type:sp.types.byte}, {name:"type", type:sp.types.byte}, {name:"req_id", type:sp.types.ns}, {name:"content_len", type:sp.types.ns}, {name:"padding_len", type:sp.types.byte}, {name:"reserve", type:sp.types.byte}, {name:"content", type:sp.types.buffer, count:"@content_len"}, {name:"padding", type:sp.types.buffer, count:"@padding_len"}, ];
var structKV = [ {name:"klen", type:[sp.types.byte, sp.types.nl], typecond:["and:128"]}, {name:"vlen", type:[sp.types.byte, sp.types.nl], typecond:["and:128"]}, {name:"key", type:sp.types.buffer, count:"@klen"}, {name:"value", type:sp.types.buffer, count:"@vlen"}, ];
var reader = br.create(buffer);
console.log(sp.parse(reader, structFCgiHeader));
result:
{ version : 1, type : 4, req_id : 1, ..... }