字节流
概述
演示字节流的基本用法。
代码
var a = Bytes.create(10);
print(a, typeof(a), a.length);
a.sets("abcd");
a.sets("efgh", 6);
print(a.hex());
print(a.gets(2));
print(a[2],a.geti(2));
var b = a.sub();
b.seti(2, 1, "1b");
b.seti(1000, 2, "2b");
b.seti(1000, 4, "2l");
b.seti(10000, 6, "4b");
print(b.hex(), b.hex(true));
print(b.geti(2, "2b"));
print(b.sub(2, 4).hex());
var c = Bytes.create(4);
c.copy(a);
print(c.hex());
var d = Bytes.create("hello", "str");
print(d.gets());
var e = Bytes.create("112233DDEEFF", "hex");
print(e.hex());
var st = ["abc", "2b", "def", "4b", "name", "s10"];
var obj = {abc: 20, def: 1000, name: "jack"};
var f = Bytes.create(16);
f.setv(st, obj);
print(f.hex());
var g = f.getv(st);
for(var i in g)
{
print(i, g[i]);
}
print(JSON.stringify(g));
下载代码(右键另存为):bytes.js