Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1609fa1155 | ||
|
|
f575e4013c | ||
|
|
6525163b1b | ||
|
|
7afd129314 | ||
|
|
f2bfd6f95f | ||
|
|
888f772ef3 | ||
|
|
fbdb9959a9 | ||
|
|
816cbc38e0 | ||
|
|
8497d70320 | ||
|
|
4f251bedc6 | ||
|
|
8dbc7e700d | ||
|
|
1d0caa3f30 | ||
|
|
302ae1779f | ||
|
|
8e001b1ff1 | ||
|
|
492b1c9905 | ||
|
|
dd23d9bc5c | ||
|
|
74958750f1 | ||
|
|
05d868bc8f | ||
|
|
f48e50e7ff | ||
|
|
674090dba2 | ||
|
|
2b241848f5 | ||
|
|
4f2ee9bb8f | ||
|
|
8d57b61bba | ||
|
|
0c60f1f777 | ||
|
|
e3ce43e2be | ||
|
|
f7066436e9 | ||
|
|
533aa8043d | ||
|
|
22a56c1607 | ||
|
|
7965ca80f5 | ||
|
|
2bdf71bbe2 | ||
|
|
3d5d0c9d38 | ||
|
|
4128f687a8 | ||
|
|
eba8a33e66 |
No files matched your search
+2
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "capnp",
|
||||
"version": "0.1.11",
|
||||
"version": "0.2.0",
|
||||
"description": "A wrapper for the C++ Cap'n Proto library",
|
||||
"keywords": [ "capnproto", "serialization" ],
|
||||
"homepage": "http://capnproto.org",
|
||||
@@ -17,9 +17,6 @@
|
||||
],
|
||||
|
||||
"main": "src/node-capnp/capnp.js",
|
||||
"peerDependencies": {
|
||||
"es6-promise": "1.x"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node ./build.js",
|
||||
"test": "node src/node-capnp/capnp-test.js"
|
||||
@@ -29,7 +26,7 @@
|
||||
"url": "git://github.com/kentonv/node-capnp.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": "0.10.x"
|
||||
"node": ">=0.12"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
+150
-11
@@ -22,16 +22,24 @@
|
||||
var fs = require("fs");
|
||||
var capnp = require("./capnp");
|
||||
var assert = require("assert");
|
||||
var Promise = require("es6-promise").Promise;
|
||||
var spawn = require("child_process").spawn;
|
||||
|
||||
var goldenBinary;
|
||||
var goldenPackedBinary;
|
||||
var goldenFlatBinary;
|
||||
var goldenPackedFlatBinary;
|
||||
try {
|
||||
// Works in Ekam build.
|
||||
goldenBinary = fs.readFileSync("node-capnp/testdata/binary");
|
||||
goldenPackedBinary = fs.readFileSync("node-capnp/testdata/packedbinary");
|
||||
goldenFlatBinary = fs.readFileSync("node-capnp/testdata/flat");
|
||||
goldenPackedFlatBinary = fs.readFileSync("node-capnp/testdata/packedflat");
|
||||
} catch (ex) {
|
||||
// Works in npm build.
|
||||
goldenBinary = fs.readFileSync("src/node-capnp/testdata/binary");
|
||||
goldenPackedBinary = fs.readFileSync("src/node-capnp/testdata/packedbinary");
|
||||
goldenFlatBinary = fs.readFileSync("src/node-capnp/testdata/flat");
|
||||
goldenPackedFlatBinary = fs.readFileSync("src/node-capnp/testdata/packedflat");
|
||||
}
|
||||
|
||||
var test = require("./test.capnp");
|
||||
@@ -54,11 +62,142 @@ assert.equal("foo", test.TestConstants.textConst);
|
||||
assert.equal("baz", test.TestConstants.structConst.textField);
|
||||
assert.equal("xyzzy", test.TestConstants.textListConst[1]);
|
||||
|
||||
// =======================================================================================
|
||||
// Test packed serialization/deserialization
|
||||
|
||||
/*
|
||||
// TODO(someday): Revive this test. The main problem is that it depends on calculator-server from
|
||||
// the Cap'n Proto samples directory.
|
||||
var parsedPacked = capnp.parsePacked(test.TestAllTypes, goldenPackedBinary);
|
||||
var roundTrippedPacked = capnp.serializePacked(test.TestAllTypes, parsedPacked);
|
||||
assert.equal(goldenPackedBinary.length, roundTrippedPacked.length, "Round trip changed size?");
|
||||
assert.equal(goldenPackedBinary.toString("base64"), roundTrippedPacked.toString("base64"), "Round trip lost data?");
|
||||
|
||||
var parsedFlat = capnp.parse(test.TestAllTypes, goldenFlatBinary, {flat: true});
|
||||
var roundTrippedFlat = capnp.serialize(test.TestAllTypes, parsedFlat, {flat: true});
|
||||
assert.equal(goldenFlatBinary.length, roundTrippedFlat.length, "Round trip changed size?");
|
||||
assert.equal(goldenFlatBinary.toString("base64"), roundTrippedFlat.toString("base64"), "Round trip lost data?");
|
||||
|
||||
var parsedPackedFlat = capnp.parse(test.TestAllTypes, goldenPackedFlatBinary, {packed: true, flat: true});
|
||||
var roundTrippedPackedFlat = capnp.serialize(test.TestAllTypes, parsedPackedFlat, {packed: true, flat: true});
|
||||
assert.equal(goldenPackedFlatBinary.length, roundTrippedPackedFlat.length, "Round trip changed size?");
|
||||
assert.equal(goldenPackedFlatBinary.toString("base64"), roundTrippedPackedFlat.toString("base64"), "Round trip lost data?");
|
||||
|
||||
// TODO(someday): do a more thorough deep equality comparison of parsed and parsedPacked
|
||||
var keys = ["voidField", "boolField", "int8Field", "int16Field", "int32Field", "int64Field"];
|
||||
for (var key in keys) {
|
||||
assert.equal(parsed[key], parsedPacked[key]);
|
||||
assert.equal(parsed[key], parsedFlat[key]);
|
||||
assert.equal(parsed[key], parsedPackedFlat[key]);
|
||||
}
|
||||
|
||||
console.log("serialization: pass");
|
||||
|
||||
// =======================================================================================
|
||||
// Test matchPowerboxQuery
|
||||
|
||||
if (capnp.matchPowerboxQuery) {
|
||||
|
||||
var tag1 = capnp.serialize(test.TestAllTypes, {int32Field: 123});
|
||||
var tag2 = capnp.serialize(test.TestAllTypes, {int32Field: 321});
|
||||
var tag3 = capnp.serialize(test.TestAllTypes, {});
|
||||
|
||||
assert(capnp.matchPowerboxQuery(tag1, tag1));
|
||||
assert(capnp.matchPowerboxQuery(tag2, tag2));
|
||||
assert(capnp.matchPowerboxQuery(tag3, tag3));
|
||||
|
||||
assert(!capnp.matchPowerboxQuery(tag1, tag2));
|
||||
assert(!capnp.matchPowerboxQuery(tag2, tag3));
|
||||
assert(!capnp.matchPowerboxQuery(tag3, tag1));
|
||||
|
||||
var emptyTag = capnp.serialize(test.TestEmptyStruct, {});
|
||||
assert(!capnp.matchPowerboxQuery(emptyTag, tag1));
|
||||
assert(!capnp.matchPowerboxQuery(emptyTag, tag2));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tag3));
|
||||
assert(!capnp.matchPowerboxQuery(tag1, emptyTag));
|
||||
assert(!capnp.matchPowerboxQuery(tag2, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(tag3, emptyTag));
|
||||
|
||||
// Test comparing pointers.
|
||||
var tagStr1 = capnp.serialize(test.TestAllTypes, {textField: "foo"});
|
||||
var tagStr2 = capnp.serialize(test.TestAllTypes, {textField: "bar"});
|
||||
var tagStr3 = capnp.serialize(test.TestAllTypes, {textField: ""});
|
||||
assert(capnp.matchPowerboxQuery(tagStr1, tagStr1));
|
||||
assert(capnp.matchPowerboxQuery(tagStr2, tagStr2));
|
||||
assert(capnp.matchPowerboxQuery(tagStr3, tagStr3));
|
||||
assert(!capnp.matchPowerboxQuery(tagStr1, tagStr2));
|
||||
assert(!capnp.matchPowerboxQuery(tagStr2, tagStr3));
|
||||
assert(!capnp.matchPowerboxQuery(tagStr3, tagStr1));
|
||||
assert(capnp.matchPowerboxQuery(tagStr1, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(tagStr2, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(tagStr3, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagStr1));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagStr2));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagStr3));
|
||||
|
||||
// Note that string comparisons are actually list comparisons. But let's make sure an exact match
|
||||
// is required (which is not the case for list-of-structs).
|
||||
var tagStr4 = capnp.serialize(test.TestAllTypes, {textField: "oof"});
|
||||
assert(!capnp.matchPowerboxQuery(tagStr1, tagStr4));
|
||||
|
||||
// Test list-of-structs.
|
||||
var tagFooBar = capnp.serialize(test.TestAllTypes,
|
||||
{structList: [{textField: "foo"}, {textField: "bar"}]});
|
||||
var tagBarFoo = capnp.serialize(test.TestAllTypes,
|
||||
{structList: [{textField: "bar"}, {textField: "foo"}]});
|
||||
var tagFooOnly = capnp.serialize(test.TestAllTypes,
|
||||
{structList: [{textField: "foo"}]});
|
||||
var tagBarOnly = capnp.serialize(test.TestAllTypes,
|
||||
{structList: [{textField: "bar"}]});
|
||||
var tagEmptyList = capnp.serialize(test.TestAllTypes,
|
||||
{structList: []});
|
||||
|
||||
assert(capnp.matchPowerboxQuery(tagFooBar, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(tagFooBar, tagBarFoo));
|
||||
assert(capnp.matchPowerboxQuery(tagBarFoo, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(tagFooOnly, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(tagBarOnly, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(tagFooOnly, tagBarFoo));
|
||||
assert(capnp.matchPowerboxQuery(tagBarOnly, tagBarFoo));
|
||||
assert(!capnp.matchPowerboxQuery(tagFooBar, tagFooOnly));
|
||||
assert(!capnp.matchPowerboxQuery(tagFooBar, tagBarOnly));
|
||||
assert(!capnp.matchPowerboxQuery(tagBarFoo, tagFooOnly));
|
||||
assert(!capnp.matchPowerboxQuery(tagBarFoo, tagBarOnly));
|
||||
|
||||
assert(capnp.matchPowerboxQuery(tagFooBar, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(tagFooOnly, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(tagBarOnly, emptyTag));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagFooOnly));
|
||||
assert(capnp.matchPowerboxQuery(emptyTag, tagBarOnly));
|
||||
|
||||
assert(!capnp.matchPowerboxQuery(tagFooBar, tagEmptyList));
|
||||
assert(!capnp.matchPowerboxQuery(tagFooOnly, tagEmptyList));
|
||||
assert(!capnp.matchPowerboxQuery(tagBarOnly, tagEmptyList));
|
||||
assert(capnp.matchPowerboxQuery(tagEmptyList, tagFooBar));
|
||||
assert(capnp.matchPowerboxQuery(tagEmptyList, tagFooOnly));
|
||||
assert(capnp.matchPowerboxQuery(tagEmptyList, tagBarOnly));
|
||||
|
||||
// Test list-of-pointers.
|
||||
var tagStrList1 = capnp.serialize(test.TestAllTypes, {textList: ["foo", "bar"]});
|
||||
var tagStrList2 = capnp.serialize(test.TestAllTypes, {textList: ["bar", "foo"]});
|
||||
var tagStrList3 = capnp.serialize(test.TestAllTypes, {textList: ["foo"]});
|
||||
var tagStrList4 = capnp.serialize(test.TestAllTypes, {textList: ["foo", null]});
|
||||
|
||||
assert(capnp.matchPowerboxQuery(tagStrList1, tagStrList1));
|
||||
assert(capnp.matchPowerboxQuery(tagStrList2, tagStrList2));
|
||||
assert(!capnp.matchPowerboxQuery(tagStrList1, tagStrList2));
|
||||
assert(!capnp.matchPowerboxQuery(tagStrList2, tagStrList1));
|
||||
assert(!capnp.matchPowerboxQuery(tagStrList3, tagStrList1));
|
||||
assert(capnp.matchPowerboxQuery(tagStrList4, tagStrList1));
|
||||
|
||||
console.log("matchPowerboxQuery: pass");
|
||||
|
||||
}
|
||||
|
||||
// =======================================================================================
|
||||
// Test RPC, if possible.
|
||||
|
||||
if (!fs.existsSync("capnp-samples")) {
|
||||
console.warn("skipping RPC because capnp-samples not present");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
var Fiber = require("fibers");
|
||||
|
||||
@@ -110,7 +249,7 @@ child.stdio[1].once("readable", function() {
|
||||
doFiber(function() {
|
||||
var conn = capnp.connect("127.0.0.1:21311");
|
||||
var Calculator = capnp.import("capnp-samples/calculator.capnp").Calculator;
|
||||
var calc = conn.restore("calculator", Calculator);
|
||||
var calc = conn.restore(null, Calculator);
|
||||
|
||||
var add = calc.getOperator("add").func;
|
||||
var subtract = calc.getOperator("subtract").func;
|
||||
@@ -144,7 +283,10 @@ child.stdio[1].once("readable", function() {
|
||||
value = calc.evaluate(
|
||||
{call: {"function": pow, params: [{literal: 2}, {literal: 4}]}}).value;
|
||||
assert.equal(16, wait(value.read()).value);
|
||||
assert(pow.closed); // Not kept past return.
|
||||
|
||||
// Wait a moment to give the capability a chance to be dropped.
|
||||
wait(new Promise((resolve, reject) => setTimeout(resolve, 10)));
|
||||
assert(pow.closed);
|
||||
value.close();
|
||||
|
||||
// Try wrapping a promise as a capability -- calls are queued until resolution.
|
||||
@@ -177,12 +319,9 @@ child.stdio[1].once("readable", function() {
|
||||
|
||||
add.close();
|
||||
subtract.close();
|
||||
calc.close();
|
||||
conn.close();
|
||||
|
||||
console.log("rpc: pass");
|
||||
}, child);
|
||||
});
|
||||
*/
|
||||
|
||||
console.log("pass");
|
||||
|
||||
+813
-372
File diff suppressed because it is too large.
Load diff
+38
-14
@@ -40,12 +40,11 @@ try {
|
||||
} catch (ex) {
|
||||
// Give up.
|
||||
throw new Error(
|
||||
"`" + modPath+ ".node` is missing. Try reinstalling `node-capnp`?");
|
||||
"`capnp.node` is missing. Try reinstalling `node-capnp`?");
|
||||
}
|
||||
}
|
||||
|
||||
var v8capnp = require(modPath);
|
||||
var Promise = require("es6-promise").Promise;
|
||||
|
||||
var importPath = [];
|
||||
for (var i in module.paths) {
|
||||
@@ -100,7 +99,7 @@ function closeAll(obj) {
|
||||
var member = obj[name];
|
||||
if (member instanceof Capability) {
|
||||
member.close();
|
||||
} else {
|
||||
} else if (typeof member === "object") {
|
||||
closeAll(member);
|
||||
}
|
||||
}
|
||||
@@ -167,9 +166,13 @@ function makeMethod(cap, method) {
|
||||
|
||||
function wrapLocalMethod(self, method) {
|
||||
return function (request) {
|
||||
var params = v8capnp.toJsParams(request, Capability);
|
||||
v8capnp.releaseParams(request);
|
||||
Promise.resolve(method.apply(self, params)).then(function (results) {
|
||||
// We start with Promise.resolve().then(...) so that any exceptions thrown immediately
|
||||
// propagate through the promise chain.
|
||||
Promise.resolve().then(function () {
|
||||
var params = v8capnp.toJsParams(request, Capability);
|
||||
v8capnp.releaseParams(request);
|
||||
return method.apply(self, params);
|
||||
}).then(function (results) {
|
||||
if (typeof results !== "object") {
|
||||
if (results === undefined) {
|
||||
results = [];
|
||||
@@ -253,26 +256,47 @@ exports.connect = function (addr, bootstrapCap) {
|
||||
if (bootstrapCap && !v8capnp.isCap(bootstrapCap)) {
|
||||
throw new Error("Invalid bootstrap capability.");
|
||||
}
|
||||
return new Connection(v8capnp.connect(addr, bootstrapCap));
|
||||
|
||||
if (addr.capabilityStreamFd) {
|
||||
return new Connection(v8capnp.connectUnixFd(addr.capabilityStreamFd, bootstrapCap));
|
||||
} else {
|
||||
return new Connection(v8capnp.connect(addr, bootstrapCap));
|
||||
}
|
||||
}
|
||||
|
||||
exports.parse = function (schema, buffer) {
|
||||
var reader = v8capnp.fromBytes(buffer, schema);
|
||||
exports.expectedSizeFromPrefix = v8capnp.expectedSizeFromPrefix;
|
||||
|
||||
exports.parse = function (schema, buffer, options) {
|
||||
var reader = v8capnp.fromBytes(buffer, schema, options || {});
|
||||
return v8capnp.toJs(reader, Capability);
|
||||
}
|
||||
|
||||
exports.serialize = function (schema, value) {
|
||||
exports.parsePacked = function (schema, buffer) {
|
||||
// TODO(cleanup): Remove in favor of options.
|
||||
return exports.parse(schema, buffer, {packed: true});
|
||||
}
|
||||
|
||||
exports.serialize = function (schema, value, options) {
|
||||
var builder = v8capnp.newBuilder(schema);
|
||||
v8capnp.fromJs(builder, value, LocalCapWrapper);
|
||||
return v8capnp.toBytes(builder);
|
||||
return v8capnp.toBytes(builder, options || {});
|
||||
}
|
||||
|
||||
exports.serializePacked = function (schema, value) {
|
||||
// TODO(cleanup): Remove in favor of options.
|
||||
return exports.serialize(schema, value, {packed: true});
|
||||
}
|
||||
|
||||
exports.Capability = Capability;
|
||||
|
||||
exports.bytesToPreorder = function(schema, buf) {
|
||||
exports.bytesToPreorder = function(schema, buf, options) {
|
||||
// Parse, copy, serialize, to get a preorder traversal.
|
||||
var reader = v8capnp.fromBytes(buf, schema);
|
||||
var reader = v8capnp.fromBytes(buf, schema, options || {});
|
||||
var builder = v8capnp.copyBuilder(reader);
|
||||
return v8capnp.toBytes(builder);
|
||||
return v8capnp.toBytes(builder, options || {});
|
||||
}
|
||||
|
||||
if (v8capnp.matchPowerboxQuery) exports.matchPowerboxQuery = v8capnp.matchPowerboxQuery;
|
||||
if (v8capnp.chacha20) exports.chacha20 = v8capnp.chacha20;
|
||||
|
||||
exports.dumpLocalCapTypeCounts = v8capnp.dumpLocalCapTypeCounts;
|
||||
@@ -1,32 +0,0 @@
|
||||
#! /bin/sh
|
||||
# Copyright (c) 2014 Sandstorm Development Group, Inc. and contributors
|
||||
# Licensed under the MIT License:
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
set -eu
|
||||
|
||||
echo newOutput node-capnp/es6-promise.js
|
||||
read OUTPUT
|
||||
|
||||
curl -s https://es6-promises.s3.amazonaws.com/es6-promise-2.0.1.min.js > "$OUTPUT"
|
||||
|
||||
echo "4f423e916c1ced14fc56c83478bd1ff17000f32ea399fda24fd131989265719c $OUTPUT" | sha256sum --quiet --strict -c - >&2
|
||||
|
||||
echo $OUTPUT >&2
|
||||
@@ -1,3 +1,2 @@
|
||||
capnp.node node_modules
|
||||
capnp.js node_modules
|
||||
es6-promise.js node_modules
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Reference in new issue
Block a user