From 2b566afd7b16cae7f0a42b359952d20ba42f0778 Mon Sep 17 00:00:00 2001 From: Caleb Sander Date: Wed, 17 Aug 2016 13:59:36 -0400 Subject: [PATCH] Fixed #27 --- README.md | 36 +++++++++++++++++++------------- client-side/download.js | 4 ++-- doc/client-side_download.js.html | 4 ++-- doc/global.html | 4 ++-- doc/index.html | 36 +++++++++++++++++++------------- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 0c5050e..a697b53 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ const tribeType = new sb.StructType({ members: new sb.SetType(personType), money: new sb.MapType(personType, new sb.FloatType) }); - -console.log(tribeType.toBuffer()); +let typeBuffer = tribeType.toBuffer(); //ArrayBuffer { byteLength: 49 } +console.log(Buffer.from(typeBuffer)); // let louis = { @@ -110,7 +110,8 @@ let value = { members: new Set().add(louis).add(garfield), money: new Map().set(louis, 23.05).set(garfield, -10.07) }; -console.log(tribeType.valueBuffer(value)); +let valueBuffer = tribeType.valueBuffer(value); //ArrayBuffer { byteLength: 100 } +console.log(Buffer.from(valueBuffer)); // ```` ### Reading from type and value `Buffer`s @@ -118,8 +119,8 @@ console.log(tribeType.valueBuffer(value)); const sb = require('structure-bytes'); //Buffer obtained somehow -let tribeBuffer = Buffer.from([0x51, 0x03, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x51, 0x03, 0x03, 0x64, 0x6f, 0x62, 0x15, 0x02, 0x69, 0x64, 0x12, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x41, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x53, 0xff, 0x00, 0x1b, 0x05, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0xff, 0x00, 0x25, 0x20]); -let type = sb.r.type(tribeBuffer); +let tribeBuffer = new Uint8Array([0x51, 0x03, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x51, 0x03, 0x03, 0x64, 0x6f, 0x62, 0x15, 0x02, 0x69, 0x64, 0x12, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x41, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x53, 0xff, 0x00, 0x1b, 0x05, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0xff, 0x00, 0x25, 0x20]); +let type = sb.r.type(tribeBuffer.buffer); console.log(type); /* StructType { @@ -130,8 +131,8 @@ StructType { */ //Buffer obtained somehow -let buffer = Buffer.from([0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x20, 0x00, 0x0a, 0x4a, 0x6f, 0x65, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x21, 0x00, 0x09, 0x4c, 0x6f, 0x75, 0x69, 0x73, 0x00, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x22, 0x00, 0x11, 0x47, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x21, 0x00, 0x09, 0x4c, 0x6f, 0x75, 0x69, 0x73, 0x00, 0x41, 0xb8, 0x66, 0x66, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x22, 0x00, 0x11, 0x47, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x00, 0xc1, 0x21, 0x1e, 0xb8]); -console.log(sb.r.value({type, buffer})); +let valueBuffer = new Uint8Array([0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x20, 0x00, 0x0a, 0x4a, 0x6f, 0x65, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x21, 0x00, 0x09, 0x4c, 0x6f, 0x75, 0x69, 0x73, 0x00, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x22, 0x00, 0x11, 0x47, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x21, 0x00, 0x09, 0x4c, 0x6f, 0x75, 0x69, 0x73, 0x00, 0x41, 0xb8, 0x66, 0x66, 0x00, 0x00, 0x01, 0x4e, 0xb7, 0x2d, 0x6c, 0x22, 0x00, 0x11, 0x47, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x00, 0xc1, 0x21, 0x1e, 0xb8]); +console.log(sb.r.value({type, buffer: valueBuffer.buffer})); /* { leader: { dob: 2015-07-22T19:11:24.192Z, id: 10, name: 'Joe' }, members: @@ -161,9 +162,14 @@ let type = new sb.EnumType({ sb.writeType({ type, outStream: fs.createWriteStream('./type') -}, (err) => { +}, err => { sb.readType(fs.createReadStream('./type'), (err, readType) => { - console.log(type.equals(readType)); //true + console.log(readType); + /* + EnumType { + type: StringType {}, + values: [ 'ON_TIME', 'LATE', 'CANCELLED', 'UNKNOWN' ] } + */ }); }); let value = 'CANCELLED'; @@ -171,7 +177,7 @@ sb.writeValue({ type, value, outStream: fs.createWriteStream('./value') -}, (err) => { +}, err => { sb.readValue({ type, inStream: fs.createReadStream('./value') @@ -183,7 +189,7 @@ sb.writeTypeAndValue({ type, value, outStream: fs.createWriteStream('./type-value') -}, (err) => { +}, err => { sb.readTypeAndValue(fs.createReadStream('./type-value'), (err, type, value) => { console.log(value); //'CANCELLED' }); @@ -197,7 +203,7 @@ const sb = require('structure-bytes'); let type = new sb.DateType(); http.createServer((req, res) => { - sb.httpRespond({req, res, type, value: new Date()}, (err) => { + sb.httpRespond({req, res, type, value: new Date}, err => { console.log('Responded'); }); }).listen(80); @@ -231,8 +237,8 @@ http.createServer((req, res) => { ```` Client-side: ````html - - + +