Skip to content

Commit

Permalink
Fixed #42; version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
calebsander committed Nov 18, 2016
1 parent f7d5de4 commit 208c54e
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 88 deletions.
36 changes: 18 additions & 18 deletions compiled/download.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions compiled/upload-download.js

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions compiled/upload.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/ArrayType.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1002">line 1002</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1007">line 1007</a>
</li></ul></dd>


Expand Down Expand Up @@ -1152,7 +1152,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1043">line 1043</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1048">line 1048</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/ChoiceType.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1219">line 1219</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1224">line 1224</a>
</li></ul></dd>


Expand Down Expand Up @@ -1159,7 +1159,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1253">line 1253</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1258">line 1258</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/EnumType.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ <h6>Properties</h6>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1151">line 1151</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1156">line 1156</a>
</li></ul></dd>


Expand Down Expand Up @@ -1232,7 +1232,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1196">line 1196</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1201">line 1201</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion docs/GrowableBuffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ <h4 class="name" id="toBuffer"><span class="type-signature"></span>toBuffer<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_growable-buffer.js.html">lib/growable-buffer.js</a>, <a href="lib_growable-buffer.js.html#line158">line 158</a>
<a href="lib_growable-buffer.js.html">lib/growable-buffer.js</a>, <a href="lib_growable-buffer.js.html#line159">line 159</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/MapType.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1089">line 1089</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1094">line 1094</a>
</li></ul></dd>


Expand Down Expand Up @@ -1178,7 +1178,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1122">line 1122</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1127">line 1127</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/NamedChoiceType.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1302">line 1302</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1307">line 1307</a>
</li></ul></dd>


Expand Down Expand Up @@ -1189,7 +1189,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1368">line 1368</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1373">line 1373</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/OptionalType.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1522">line 1522</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1527">line 1527</a>
</li></ul></dd>


Expand Down Expand Up @@ -1162,7 +1162,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1555">line 1555</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1560">line 1560</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/PointerType.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1588">line 1588</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1593">line 1593</a>
</li></ul></dd>


Expand Down Expand Up @@ -1165,7 +1165,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1630">line 1630</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1635">line 1635</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/RecursiveType.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1405">line 1405</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1410">line 1410</a>
</li></ul></dd>


Expand Down Expand Up @@ -1163,7 +1163,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1479">line 1479</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1484">line 1484</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions docs/SetType.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h4 class="name" id="SetType"><span class="type-signature"></span>new SetType<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1059">line 1059</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1064">line 1064</a>
</li></ul></dd>


Expand Down Expand Up @@ -1104,7 +1104,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1071">line 1071</a>
<a href="structure-types.js.html">structure-types.js</a>, <a href="structure-types.js.html#line1076">line 1076</a>
</li></ul></dd>


Expand Down
1 change: 1 addition & 0 deletions docs/lib_growable-buffer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ <h1 class="page-title">Source: lib/growable-buffer.js</h1>
* @return {GrowableBuffer} {@link this}
*/
addAll(buffer) {
assert.instanceOf(buffer, ArrayBuffer)
const oldSize = this.size
const newSize = this.size + buffer.byteLength
this.grow(newSize)
Expand Down
9 changes: 7 additions & 2 deletions docs/structure-types.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,13 @@ <h1 class="page-title">Source: structure-types.js</h1>
assert.instanceOf(value, Object)
for (const field of this.fields) {
const fieldValue = value[field[NAME]]
if (fieldValue === undefined) assert.fail('Value for field "' + field[NAME] + '" missing')
field[TYPE].writeValue(buffer, fieldValue, false)
try { field[TYPE].writeValue(buffer, fieldValue, false) }
catch (writeError) {
//Reporting that field is missing is more useful than, for example,
//Saying "undefined is not an instance of Number"
if (fieldValue === undefined) assert.fail('Value for field "' + field[NAME] + '" missing')
throw writeError //throw original error if field is defined, but just invalid
}
}
setPointers(buffer, root)
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "structure-bytes",
"version": "2.20.9",
"version": "2.21.9",
"description": "A library for more efficient data transfers by separating the structure from the values and efficiently storing each as binary data",
"main": "index.js",
"dependencies": {
Expand All @@ -15,7 +15,7 @@
"browserify": "13.1.x",
"coveralls": "2.11.x",
"google-closure-compiler-js": "20161024.0.0",
"nyc": "8.4.x"
"nyc": "9.0.x"
},
"directories": {
"test": "test"
Expand Down
9 changes: 7 additions & 2 deletions structure-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,13 @@ class StructType extends AbsoluteType {
assert.instanceOf(value, Object)
for (const field of this.fields) {
const fieldValue = value[field[NAME]]
if (fieldValue === undefined) assert.fail('Value for field "' + field[NAME] + '" missing')
field[TYPE].writeValue(buffer, fieldValue, false)
try { field[TYPE].writeValue(buffer, fieldValue, false) }
catch (writeError) {
//Reporting that field is missing is more useful than, for example,
//Saying "undefined is not an instance of Number"
if (fieldValue === undefined) assert.fail('Value for field "' + field[NAME] + '" missing')
throw writeError //throw original error if field is defined, but just invalid
}
}
setPointers(buffer, root)
}
Expand Down
22 changes: 21 additions & 1 deletion test/value-bytes/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ assert.throws(
() => type.writeValue(gb, {b: [true]}),
'Value for field "i" missing'
)
assert.throws(
() => type.writeValue(gb, {b: 2}),
'2 is not an instance of Array'
)
const VALUE = {
b: [true, false, true],
i: 675,
Expand All @@ -17,4 +21,20 @@ const VALUE = {
gb = new GrowableBuffer
type.writeValue(gb, VALUE)
assert.equal(gb.toBuffer(), bufferFrom([0, 0, 0, 3, 0b10100000, 0x00, 0x00, 0x02, 0xa3, 0xc3, 0xa0, 0xc3, 0x9f, 0xc3, 0xa7, 0xc3, 0xb0, 0xc3, 0xaa, 0]))
assert.equal(r.value({buffer: gb.toBuffer(), type}), VALUE)
assert.equal(r.value({buffer: gb.toBuffer(), type}), VALUE)

let typeWithOptionalField = new t.StructType({
optional: new t.OptionalType(new t.StringType),
required: new t.DoubleType
})
assert.equal(typeWithOptionalField.valueBuffer({
required: 2.0, optional: 'test'
}), bufferFrom([
0xff,
0x74, 0x65, 0x73, 0x74, 0, //eslint-disable-line indent
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]))
assert.equal(typeWithOptionalField.valueBuffer({required: 2.0}), bufferFrom([
0,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]))

0 comments on commit 208c54e

Please sign in to comment.