Doubler
uupaa edited this page Aug 1, 2015
·
20 revisions
Doubler オブジェクトは、WebModule 名前空間以下に配置(WebModule.Doubler
)されています。
Doubler.js を読み込む前に WebModule.publish = true;
を行うと、
Doubler オブジェクトを GLOBAL 名前空間以下に直接配置 できます。
var Doubler = {
"encode": Doubler_encode, // Doubler.encode(source:Uint8Array):Uint16Array
"decode": Doubler_decode // Doubler.decode(source:Uint16Array):Uint8Array
};
Doubler.encode(source:Uint8Array):Uint16Array は、Uint8Array を Uint16Array にエンコードします。
var key = "testDoublerStorage";
var source = new Uint8Array([0x00, 0x01,
0x02, 0x03,
0x04, 0x05,
0x09, 0x20,
0x21, 0x32,
0x33, 0x48,
0xfd, 0xfe,
0xff, 0x00]);
localStorage.setItem(key, Codec.Uint8ArrayToString( Doubler.encode( source )));
var result = Doubler.decode( Codec.StringToUint16Array( localStorage.getItem(key) || ""));
if ( Array.prototype.slice.call(source).join("") === Array.prototype.slice.call(result).join("") ) {
console.log("ok");
}
Doubler.decode(source:Uint16Array):Uint8Array は、Uint16Array を Uint8Array にデコードします。