/* import { struct, varuint, string, InputOf } from "./"; const customStruct = struct({ num: varuint, str: string }); const source: InputOf = { num: 123, str: 'someString' }; console.log('source:', source); const json = customStruct.toJSON(source); console.log('json:', json); console.log('parsed json:', customStruct.fromJSON(json)); const buffer = customStruct.toBuffer(source); console.log('buffer:', buffer.toString('hex')); console.log('parsed buffer:', customStruct.fromBuffer(buffer)); */ /* import { bool } from "./"; console.log(bool.toJSON(true)); // true console.log(bool.fromJSON(false)); // false console.log(bool.toBuffer(true)); // console.log(bool.fromBuffer(Buffer.from('01', 'hex'))); // true */ /* import { empty } from "./"; console.log(empty.toJSON(undefined)); // null console.log(empty.fromJSON(null)); // undefined console.log(empty.toBuffer(undefined)); // console.log(empty.fromBuffer(Buffer.from([]))); // undefined */ /* import { optional, bool } from "./"; const serializer = optional(bool); console.log(serializer.toJSON(true)); // true console.log(serializer.toJSON(undefined)); // null console.log(serializer.toJSON(null)); // null console.log(serializer.fromJSON(false)); // false console.log(serializer.fromJSON(null)); // null console.log(serializer.toBuffer(true)); // console.log(serializer.toBuffer(undefined)); // console.log(serializer.fromBuffer(Buffer.from('0100', 'hex'))); // false console.log(serializer.fromBuffer(Buffer.from([0]))); // null */ /* import { string } from "./"; console.log(string.toJSON('qwe')); // "qwe" console.log(string.fromJSON('qwe')); // "qwe" console.log(string.toBuffer('qwe')); // console.log(string.fromBuffer(Buffer.from('83717765', 'hex'))); // "qwe" */ /* import { struct, bool, string } from "./"; const serializer = struct({ b: bool, s: string }); console.log(serializer.toJSON({ b: true, s: 'qwe' })); // { b: true, s: "qwe" } console.log(serializer.fromJSON({ s: 'qwe', b: true })); // { b: true, s: "qwe" } console.log(serializer.toBuffer({ s: 'qwe', b: true })); // console.log(serializer.fromBuffer(Buffer.from('0183717765', 'hex'))); // { b: true, s: "qwe" } */ /* import { varuint, BigNumber } from "./"; console.log(varuint.toJSON(new BigNumber(123))); // "123" console.log(varuint.toJSON(123)); // "123" console.log(varuint.toJSON('123')); // "123" console.log(varuint.fromJSON('123')); // console.log(varuint.toBuffer(123)); // console.log(varuint.fromBuffer(Buffer.from('fb', 'hex'))); // */ import { vector, varuint, BigNumber } from "./"; const serializer = vector(varuint); console.log(serializer.toJSON([123, '234', new BigNumber(345)])); // ["123", "234", "345"] console.log(serializer.fromJSON(['123', '234', '345'])); // [, , ] console.log(serializer.toBuffer([123, '234', new BigNumber(345)])); // console.log(serializer.fromBuffer(Buffer.from('83fb01ea02d9', 'hex'))); // [, , ]