More work on new serialization/parsing functions. Added more tests.

This commit is contained in:
Stefan Thomas
2013-07-30 22:48:07 -07:00
parent 815e2af3cf
commit 78b1e4f570
6 changed files with 497 additions and 53 deletions

View File

@@ -5,8 +5,16 @@ var binformat = require('./binformat'),
var UInt256 = require('./uint256').UInt256;
var SerializedObject = function () {
this.buffer = [];
var SerializedObject = function (buf) {
if (Array.isArray(buf)) {
this.buffer = buf;
} else if ("string" === typeof buf) {
this.buffer = sjcl.codec.bytes.fromBits(sjcl.codec.hex.toBits(buf));
} else if (!buf) {
this.buffer = [];
} else {
throw new Error("Invalid buffer passed.");
}
this.pointer = 0;
};