bytewise-core
Advanced tools
Comparing version 1.2.2 to 1.2.3
52
index.js
@@ -37,10 +37,7 @@ var assert = require('./util').assert | ||
bytewise.encode = function(source, options) { | ||
// | ||
// check for invalid/incomparable values | ||
// | ||
assert(!base.invalid(source), 'Invalid value') | ||
// | ||
// encode bound types (ranges) | ||
// | ||
var boundary = base.bound.getBoundary(source) | ||
@@ -50,5 +47,3 @@ if (boundary) | ||
// | ||
// encode standard value-typed sorts | ||
// | ||
var order = base.order | ||
@@ -60,6 +55,6 @@ var sort | ||
if (sort.is(source)) { | ||
// | ||
// loop over any subsorts defined on sort | ||
// | ||
var subsorts = sort.sorts || { '': sort } // TODO: clean up | ||
// TODO: clean up | ||
var subsorts = sort.sorts || { '': sort } | ||
for (key in subsorts) { | ||
@@ -70,5 +65,4 @@ var subsort = subsorts[key] | ||
} | ||
// | ||
// source is an unsupported subsort | ||
// | ||
assert(false, 'Unsupported sort value') | ||
@@ -78,5 +72,3 @@ } | ||
// | ||
// no type descriptor found | ||
// | ||
assert(false, 'Unknown value') | ||
@@ -89,18 +81,14 @@ } | ||
bytewise.decode = function (buffer, options) { | ||
assert(!buffer || !buffer.undecodable, 'Encoded value not decodable') | ||
// | ||
// attempt to decode string input using configurable codec | ||
// | ||
if (typeof buffer === 'string') | ||
if (typeof buffer === 'string') { | ||
buffer = bytewise.stringCodec.encode(buffer) | ||
} | ||
assert(!buffer || !buffer.undecodable, 'Encoded value not decodable') | ||
var byte = buffer[0] | ||
var type = bytewise.getType(byte) | ||
assert(type, 'Invalid encoding: ' + buffer) | ||
// | ||
// if type provides a decoder it is passed the base type system as second arg | ||
// | ||
var codec = type.codec | ||
@@ -116,5 +104,3 @@ if (codec) { | ||
// | ||
// nullary types without a codec must provide a value for their decoded form | ||
// | ||
assert('value' in type, 'Unsupported encoding: ' + buffer) | ||
@@ -137,7 +123,6 @@ return postDecode(type.value, options) | ||
// | ||
bytewise.postEncode = function (encoded) { | ||
bytewise.postEncode = function (encoded, options) { | ||
// | ||
// override buffer toString method to default to hex to help coercion issues | ||
// | ||
// TODO: just return pure buffer, do this toString hackery in bytewise | ||
encoded.toString = function (encoding) { | ||
@@ -163,3 +148,3 @@ if (!encoding) | ||
// | ||
bytewise.postDecode = function (decoded) { | ||
bytewise.postDecode = function (decoded, options) { | ||
return decoded | ||
@@ -195,21 +180,14 @@ } | ||
bytewise.getType = function (byte) { | ||
// | ||
// construct and memoize byte prefix registry on first run | ||
// | ||
if (!PREFIX_REGISTRY) { | ||
PREFIX_REGISTRY = {} | ||
// | ||
// register sorts | ||
// | ||
var sort | ||
for (var key in sorts) { | ||
sort = sorts[key] | ||
// | ||
// if sort has subsorts register these instead | ||
// | ||
if (sort.sorts) | ||
registerTypes(sort.sorts) | ||
else | ||
registerType(sort) | ||
sort.sorts ? registerTypes(sort.sorts) : registerType(sort) | ||
} | ||
@@ -216,0 +194,0 @@ } |
{ | ||
"name": "bytewise-core", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Binary serialization of arbitrarily complex structures that sort element-wise", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31845
920