Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from kig/test.js
Created November 10, 2013 18:01
Show Gist options
  • Select an option

  • Save JT5D/7401574 to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/7401574 to your computer and use it in GitHub Desktop.
var embed = [
'tag', 'uint32be',
'code', 'uint32le',
'greet', 'cstring'
];
var def = [
'tag', 'cstring:4',
'code', 'uint32le',
'embed', embed,
'length', 'uint16be',
'data', ['[]', 'float32be', function(s, ds){ return (s.length-2) / 4; }],
'greet', 'cstring:20',
'endNote', {
get: function(ds, s){ return ds.readUint8(); },
set: function(ds, v){ ds.writeUint8(v); }
}
];
var u = [137, 80, 78, 71, 0, 136, 136, 254, 137, 80,
78, 71, 0, 136, 136, 255, 72, 101, 108, 108,
111, 44, 32, 87, 111, 114, 108, 100, 33, 0,
0, 10, 0, 1, 2, 3, 1, 2, 3, 4,
72, 101, 108, 108, 111, 44, 32, 87, 111, 114,
108, 100, 33, 0, 0, 0, 0, 0, 0, 0,
255];
var ds = new DataStream();
ds.writeUint8Array(u);
ds.seek(0);
var obj = ds.readStruct(def);
var p = ds.position;
ds.writeStruct(def, obj);
ds.seek(p);
var obj2 = ds.readStruct(def);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment