From 72b6ea437eb5b238d3d61431fbf99a601d5ec858 Mon Sep 17 00:00:00 2001 From: navaneethkn Date: Mon, 24 Feb 2014 17:18:59 +0530 Subject: [PATCH] JS implementation --- java/.idea/workspace.xml | 199 +- javascript/node_modules/.bin/proto2js | 1 + javascript/node_modules/bytebuffer/.npmignore | 3 + .../node_modules/bytebuffer/.travis.yml | 4 + .../node_modules/bytebuffer/ByteBuffer.js | 2320 +++ .../node_modules/bytebuffer/ByteBuffer.min.js | 55 + .../bytebuffer/ByteBuffer.min.map | 8 + .../bytebuffer/ByteBuffer.noexpose.js | 2207 +++ javascript/node_modules/bytebuffer/LICENSE | 202 + javascript/node_modules/bytebuffer/NOTICE | 2 + javascript/node_modules/bytebuffer/README.md | 121 + javascript/node_modules/bytebuffer/bower.json | 12 + javascript/node_modules/bytebuffer/build.js | 35 + .../bytebuffer/docs/ByteBuffer.Long.html | 4269 +++++ .../bytebuffer/docs/ByteBuffer.html | 15285 +++++++++++++++ .../node_modules/bytebuffer/docs/index.html | 60 + .../bytebuffer/docs/module-ByteBuffer.html | 15872 ++++++++++++++++ .../bytebuffer/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../docs/scripts/prettify/lang-css.js | 2 + .../docs/scripts/prettify/prettify.js | 28 + .../bytebuffer/docs/styles/jsdoc-esoccer.css | 296 + .../bytebuffer/docs/styles/prettify-jsdoc.css | 111 + .../docs/styles/prettify-tomorrow.css | 132 + .../bytebuffer/externs/ByteBuffer.js | 791 + .../node_modules/bytebuffer/externs/Long.js | 328 + .../bytebuffer/externs/minimal-env.js | 40 + javascript/node_modules/bytebuffer/jsdoc.json | 13 + .../bytebuffer/node_modules/long/.npmignore | 2 + .../bytebuffer/node_modules/long/.travis.yml | 6 + .../bytebuffer/node_modules/long/LICENSE | 202 + .../bytebuffer/node_modules/long/Long.js | 940 + .../bytebuffer/node_modules/long/Long.min.js | 26 + .../bytebuffer/node_modules/long/NOTICE | 2 + .../bytebuffer/node_modules/long/README.md | 75 + .../bytebuffer/node_modules/long/bower.json | 9 + .../node_modules/long/docs/Long.html | 5380 ++++++ .../node_modules/long/docs/index.html | 60 + .../node_modules/long/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../long/docs/scripts/prettify/lang-css.js | 2 + .../long/docs/scripts/prettify/prettify.js | 28 + .../long/docs/styles/jsdoc-esoccer.css | 296 + .../long/docs/styles/prettify-jsdoc.css | 111 + .../long/docs/styles/prettify-tomorrow.css | 132 + .../node_modules/long/externs/Long.js | 328 + .../bytebuffer/node_modules/long/jsdoc.json | 13 + .../bytebuffer/node_modules/long/long.png | Bin 0 -> 3793 bytes .../bytebuffer/node_modules/long/package.json | 39 + .../node_modules/long/tests/suite.js | 156 + .../node_modules/bytebuffer/package.json | 53 + .../node_modules/bytebuffer/src/ByteBuffer.js | 2320 +++ .../node_modules/bytebuffer/src/bower.json | 12 + .../node_modules/bytebuffer/tests/suite.js | 929 + javascript/node_modules/long/.npmignore | 2 + javascript/node_modules/long/.travis.yml | 6 + javascript/node_modules/long/LICENSE | 202 + javascript/node_modules/long/Long.js | 940 + javascript/node_modules/long/Long.min.js | 26 + javascript/node_modules/long/NOTICE | 2 + javascript/node_modules/long/README.md | 75 + javascript/node_modules/long/bower.json | 9 + javascript/node_modules/long/docs/Long.html | 5380 ++++++ javascript/node_modules/long/docs/index.html | 60 + .../node_modules/long/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../long/docs/scripts/prettify/lang-css.js | 2 + .../long/docs/scripts/prettify/prettify.js | 28 + .../long/docs/styles/jsdoc-esoccer.css | 296 + .../long/docs/styles/prettify-jsdoc.css | 111 + .../long/docs/styles/prettify-tomorrow.css | 132 + javascript/node_modules/long/externs/Long.js | 328 + javascript/node_modules/long/jsdoc.json | 13 + javascript/node_modules/long/long.png | Bin 0 -> 3793 bytes javascript/node_modules/long/package.json | 39 + javascript/node_modules/long/tests/suite.js | 156 + .../node_modules/protobufjs/.idea/.name | 1 + .../protobufjs/.idea/ProtoBuf.iml | 9 + .../protobufjs/.idea/encodings.xml | 5 + .../node_modules/protobufjs/.idea/misc.xml | 5 + .../node_modules/protobufjs/.idea/modules.xml | 9 + .../.idea/scopes/scope_settings.xml | 5 + .../node_modules/protobufjs/.idea/vcs.xml | 7 + .../protobufjs/.idea/workspace.xml | 255 + javascript/node_modules/protobufjs/.npmignore | 2 + .../node_modules/protobufjs/.travis.yml | 4 + javascript/node_modules/protobufjs/LICENSE | 202 + javascript/node_modules/protobufjs/NOTICE | 2 + .../node_modules/protobufjs/ProtoBuf.js | 3721 ++++ .../node_modules/protobufjs/ProtoBuf.min.js | 93 + .../node_modules/protobufjs/ProtoBuf.min.map | 8 + .../protobufjs/ProtoBuf.noparse.js | 2747 +++ .../protobufjs/ProtoBuf.noparse.min.js | 64 + .../protobufjs/ProtoBuf.noparse.min.map | 8 + .../node_modules/protobufjs/ProtoBuf.png | Bin 0 -> 6889 bytes javascript/node_modules/protobufjs/README.md | 52 + .../node_modules/protobufjs/bin/proto2js | 263 + javascript/node_modules/protobufjs/bower.json | 19 + javascript/node_modules/protobufjs/build.js | 49 + .../docs/ProtoBuf.Builder.Message.html | 2707 +++ .../docs/ProtoBuf.Builder.Service.html | 574 + .../protobufjs/docs/ProtoBuf.Builder.html | 2243 +++ .../docs/ProtoBuf.DotProto.Parser.html | 422 + .../docs/ProtoBuf.DotProto.Tokenizer.html | 705 + .../protobufjs/docs/ProtoBuf.DotProto.html | 124 + .../protobufjs/docs/ProtoBuf.Lang.html | 114 + .../docs/ProtoBuf.Reflect.Enum.Value.html | 692 + .../docs/ProtoBuf.Reflect.Enum.html | 1758 ++ .../docs/ProtoBuf.Reflect.Message.Field.html | 1774 ++ .../docs/ProtoBuf.Reflect.Message.html | 2103 ++ .../docs/ProtoBuf.Reflect.Namespace.html | 1649 ++ .../docs/ProtoBuf.Reflect.Service.Method.html | 790 + .../ProtoBuf.Reflect.Service.RPCMethod.html | 1038 + .../docs/ProtoBuf.Reflect.Service.html | 1852 ++ .../protobufjs/docs/ProtoBuf.Reflect.T.html | 593 + .../protobufjs/docs/ProtoBuf.Reflect.html | 131 + .../protobufjs/docs/ProtoBuf.Util.html | 564 + .../protobufjs/docs/ProtoBuf.html | 2120 +++ .../node_modules/protobufjs/docs/index.html | 60 + .../protobufjs/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../docs/scripts/prettify/lang-css.js | 2 + .../docs/scripts/prettify/prettify.js | 28 + .../protobufjs/docs/styles/jsdoc-esoccer.css | 296 + .../protobufjs/docs/styles/prettify-jsdoc.css | 111 + .../docs/styles/prettify-tomorrow.css | 132 + .../protobufjs/examples/websocket/.npmignore | 3 + .../protobufjs/examples/websocket/README.md | 8 + .../websocket/node_modules/open/.jshintignore | 2 + .../websocket/node_modules/open/.jshintrc | 27 + .../websocket/node_modules/open/.npmignore | 1 + .../websocket/node_modules/open/LICENSE | 22 + .../websocket/node_modules/open/README.md | 24 + .../websocket/node_modules/open/lib/open.js | 60 + .../websocket/node_modules/open/package.json | 52 + .../node_modules/open/vendor/xdg-open | 767 + .../examples/websocket/package.json | 16 + .../protobufjs/examples/websocket/server.js | 97 + .../examples/websocket/www/example.proto | 3 + .../examples/websocket/www/index.html | 59 + .../protobufjs/externs/ByteBuffer.js | 767 + .../node_modules/protobufjs/externs/Long.js | 328 + .../protobufjs/externs/ProtoBuf.js | 875 + .../node_modules/protobufjs/externs/fs.js | 644 + javascript/node_modules/protobufjs/jsdoc.json | 13 + .../protobufjs/node_modules/ascli/.npmignore | 4 + .../protobufjs/node_modules/ascli/LICENSE | 202 + .../protobufjs/node_modules/ascli/README.md | 61 + .../node_modules/ascli/alphabet/straight.json | 212 + .../protobufjs/node_modules/ascli/ascli.js | 150 + .../ascli/node_modules/colour/.npmignore | 3 + .../ascli/node_modules/colour/LICENSE | 20 + .../ascli/node_modules/colour/README.md | 101 + .../ascli/node_modules/colour/colour.js | 335 + .../ascli/node_modules/colour/colour.min.js | 14 + .../ascli/node_modules/colour/colour.png | Bin 0 -> 9415 bytes .../node_modules/colour/examples/example.css | 25 + .../node_modules/colour/examples/example.html | 91 + .../node_modules/colour/examples/example.js | 71 + .../node_modules/colour/externs/colour.js | 136 + .../colour/externs/minimal-env.js | 37 + .../ascli/node_modules/colour/package.json | 40 + .../ascli/node_modules/colour/tests/test.js | 80 + .../ascli/node_modules/optjs/README.md | 44 + .../ascli/node_modules/optjs/opt.js | 8 + .../ascli/node_modules/optjs/opt.png | Bin 0 -> 2912 bytes .../ascli/node_modules/optjs/package.json | 26 + .../ascli/node_modules/optjs/test.js | 2 + .../node_modules/ascli/package.json | 39 + .../node_modules/ascli/tests/test.js | 9 + .../node_modules/bytebuffer/.npmignore | 3 + .../node_modules/bytebuffer/.travis.yml | 4 + .../node_modules/bytebuffer/ByteBuffer.js | 2320 +++ .../node_modules/bytebuffer/ByteBuffer.min.js | 55 + .../bytebuffer/ByteBuffer.min.map | 8 + .../bytebuffer/ByteBuffer.noexpose.js | 2207 +++ .../node_modules/bytebuffer/LICENSE | 202 + .../protobufjs/node_modules/bytebuffer/NOTICE | 2 + .../node_modules/bytebuffer/README.md | 121 + .../node_modules/bytebuffer/bower.json | 12 + .../node_modules/bytebuffer/build.js | 35 + .../bytebuffer/docs/ByteBuffer.Long.html | 4269 +++++ .../bytebuffer/docs/ByteBuffer.html | 15285 +++++++++++++++ .../node_modules/bytebuffer/docs/index.html | 60 + .../bytebuffer/docs/module-ByteBuffer.html | 15872 ++++++++++++++++ .../bytebuffer/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../docs/scripts/prettify/lang-css.js | 2 + .../docs/scripts/prettify/prettify.js | 28 + .../bytebuffer/docs/styles/jsdoc-esoccer.css | 296 + .../bytebuffer/docs/styles/prettify-jsdoc.css | 111 + .../docs/styles/prettify-tomorrow.css | 132 + .../bytebuffer/externs/ByteBuffer.js | 791 + .../node_modules/bytebuffer/externs/Long.js | 328 + .../bytebuffer/externs/minimal-env.js | 40 + .../node_modules/bytebuffer/jsdoc.json | 13 + .../bytebuffer/node_modules/long/.npmignore | 2 + .../bytebuffer/node_modules/long/.travis.yml | 6 + .../bytebuffer/node_modules/long/LICENSE | 202 + .../bytebuffer/node_modules/long/Long.js | 940 + .../bytebuffer/node_modules/long/Long.min.js | 26 + .../bytebuffer/node_modules/long/NOTICE | 2 + .../bytebuffer/node_modules/long/README.md | 75 + .../bytebuffer/node_modules/long/bower.json | 9 + .../node_modules/long/docs/Long.html | 5380 ++++++ .../node_modules/long/docs/index.html | 60 + .../node_modules/long/docs/scripts/html5.js | 9 + .../scripts/prettify/Apache-License-2.0.txt | 202 + .../long/docs/scripts/prettify/lang-css.js | 2 + .../long/docs/scripts/prettify/prettify.js | 28 + .../long/docs/styles/jsdoc-esoccer.css | 296 + .../long/docs/styles/prettify-jsdoc.css | 111 + .../long/docs/styles/prettify-tomorrow.css | 132 + .../node_modules/long/externs/Long.js | 328 + .../bytebuffer/node_modules/long/jsdoc.json | 13 + .../bytebuffer/node_modules/long/long.png | Bin 0 -> 3793 bytes .../bytebuffer/node_modules/long/package.json | 43 + .../node_modules/long/tests/suite.js | 156 + .../node_modules/bytebuffer/package.json | 57 + .../node_modules/bytebuffer/src/ByteBuffer.js | 2320 +++ .../node_modules/bytebuffer/src/bower.json | 12 + .../node_modules/bytebuffer/tests/suite.js | 929 + .../node_modules/protobufjs/package.json | 66 + .../node_modules/protobufjs/src/ProtoBuf.js | 370 + .../protobufjs/src/ProtoBuf/Builder.js | 643 + .../protobufjs/src/ProtoBuf/DotProto.js | 27 + .../src/ProtoBuf/DotProto/Parser.js | 743 + .../src/ProtoBuf/DotProto/Tokenizer.js | 184 + .../protobufjs/src/ProtoBuf/Lang.js | 70 + .../protobufjs/src/ProtoBuf/Reflect.js | 1673 ++ .../protobufjs/src/ProtoBuf/Util.js | 145 + .../node_modules/protobufjs/src/bower.json | 19 + .../protobufjs/tests/PingExample.proto | 12 + .../node_modules/protobufjs/tests/T139.proto | 4 + .../protobufjs/tests/camelcase.proto | 14 + .../protobufjs/tests/comments.proto | 10 + .../protobufjs/tests/complex.json | 123 + .../protobufjs/tests/complex.proto | 34 + .../protobufjs/tests/custom-options.proto | 53 + .../protobufjs/tests/dupimport/dep1.proto | 6 + .../protobufjs/tests/dupimport/dep2.proto | 5 + .../protobufjs/tests/dupimport/main.proto | 8 + .../protobufjs/tests/example1.proto | 5 + .../protobufjs/tests/example1u.proto | 3 + .../protobufjs/tests/example2.proto | 5 + .../protobufjs/tests/example3.proto | 9 + .../protobufjs/tests/example4.proto | 5 + .../protobufjs/tests/extend.proto | 19 + .../tests/google/protobuf/descriptor.proto | 620 + .../protobufjs/tests/gtfs-realtime.proto | 552 + .../protobufjs/tests/importRoot/file1.proto | 1 + .../protobufjs/tests/importRoot/file2.proto | 1 + .../protobufjs/tests/importRoot/file3.proto | 1 + .../protobufjs/tests/import_a.proto | 5 + .../protobufjs/tests/import_b.proto | 5 + .../protobufjs/tests/import_common.proto | 2 + .../protobufjs/tests/imports-toplevel.proto | 13 + .../protobufjs/tests/imports.proto | 9 + .../node_modules/protobufjs/tests/inner.proto | 10 + .../node_modules/protobufjs/tests/negid.proto | 9 + .../protobufjs/tests/nodeunit-browser/LICENSE | 19 + .../tests/nodeunit-browser/nodeunit.css | 70 + .../tests/nodeunit-browser/nodeunit.js | 2108 ++ .../protobufjs/tests/numberformats.proto | 11 + .../protobufjs/tests/optional.proto | 3 + .../protobufjs/tests/options.proto | 8 + .../protobufjs/tests/proto2js/Bar.json | 46 + .../protobufjs/tests/proto2js/Bar.proto | 7 + .../protobufjs/tests/proto2js/Foo.proto | 4 + .../protobufjs/tests/protobufnet.proto | 19 + .../protobufjs/tests/repeated.proto | 17 + .../protobufjs/tests/setarray.proto | 7 + .../node_modules/protobufjs/tests/suite.html | 16 + .../node_modules/protobufjs/tests/suite.js | 1367 ++ .../protobufjs/tests/toplevel.proto | 10 + .../node_modules/protobufjs/tests/x64.proto | 10 + javascript/step_implementation.js | 15 + javascript/twist.js | 126 + javascript/twist.sh | 2 + manifest.json | 4 +- runner/js.json | 6 + 281 files changed, 160761 insertions(+), 102 deletions(-) create mode 120000 javascript/node_modules/.bin/proto2js create mode 100644 javascript/node_modules/bytebuffer/.npmignore create mode 100644 javascript/node_modules/bytebuffer/.travis.yml create mode 100644 javascript/node_modules/bytebuffer/ByteBuffer.js create mode 100644 javascript/node_modules/bytebuffer/ByteBuffer.min.js create mode 100644 javascript/node_modules/bytebuffer/ByteBuffer.min.map create mode 100644 javascript/node_modules/bytebuffer/ByteBuffer.noexpose.js create mode 100644 javascript/node_modules/bytebuffer/LICENSE create mode 100644 javascript/node_modules/bytebuffer/NOTICE create mode 100644 javascript/node_modules/bytebuffer/README.md create mode 100644 javascript/node_modules/bytebuffer/bower.json create mode 100644 javascript/node_modules/bytebuffer/build.js create mode 100644 javascript/node_modules/bytebuffer/docs/ByteBuffer.Long.html create mode 100644 javascript/node_modules/bytebuffer/docs/ByteBuffer.html create mode 100644 javascript/node_modules/bytebuffer/docs/index.html create mode 100644 javascript/node_modules/bytebuffer/docs/module-ByteBuffer.html create mode 100644 javascript/node_modules/bytebuffer/docs/scripts/html5.js create mode 100644 javascript/node_modules/bytebuffer/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/bytebuffer/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/bytebuffer/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/bytebuffer/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/bytebuffer/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/bytebuffer/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/bytebuffer/externs/ByteBuffer.js create mode 100644 javascript/node_modules/bytebuffer/externs/Long.js create mode 100644 javascript/node_modules/bytebuffer/externs/minimal-env.js create mode 100644 javascript/node_modules/bytebuffer/jsdoc.json create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/.npmignore create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/.travis.yml create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/LICENSE create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/Long.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/Long.min.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/NOTICE create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/README.md create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/bower.json create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/Long.html create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/index.html create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/externs/Long.js create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/jsdoc.json create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/long.png create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/package.json create mode 100644 javascript/node_modules/bytebuffer/node_modules/long/tests/suite.js create mode 100644 javascript/node_modules/bytebuffer/package.json create mode 100644 javascript/node_modules/bytebuffer/src/ByteBuffer.js create mode 100644 javascript/node_modules/bytebuffer/src/bower.json create mode 100644 javascript/node_modules/bytebuffer/tests/suite.js create mode 100644 javascript/node_modules/long/.npmignore create mode 100644 javascript/node_modules/long/.travis.yml create mode 100644 javascript/node_modules/long/LICENSE create mode 100644 javascript/node_modules/long/Long.js create mode 100644 javascript/node_modules/long/Long.min.js create mode 100644 javascript/node_modules/long/NOTICE create mode 100644 javascript/node_modules/long/README.md create mode 100644 javascript/node_modules/long/bower.json create mode 100644 javascript/node_modules/long/docs/Long.html create mode 100644 javascript/node_modules/long/docs/index.html create mode 100644 javascript/node_modules/long/docs/scripts/html5.js create mode 100644 javascript/node_modules/long/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/long/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/long/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/long/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/long/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/long/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/long/externs/Long.js create mode 100644 javascript/node_modules/long/jsdoc.json create mode 100644 javascript/node_modules/long/long.png create mode 100644 javascript/node_modules/long/package.json create mode 100644 javascript/node_modules/long/tests/suite.js create mode 100644 javascript/node_modules/protobufjs/.idea/.name create mode 100644 javascript/node_modules/protobufjs/.idea/ProtoBuf.iml create mode 100644 javascript/node_modules/protobufjs/.idea/encodings.xml create mode 100644 javascript/node_modules/protobufjs/.idea/misc.xml create mode 100644 javascript/node_modules/protobufjs/.idea/modules.xml create mode 100644 javascript/node_modules/protobufjs/.idea/scopes/scope_settings.xml create mode 100644 javascript/node_modules/protobufjs/.idea/vcs.xml create mode 100644 javascript/node_modules/protobufjs/.idea/workspace.xml create mode 100644 javascript/node_modules/protobufjs/.npmignore create mode 100644 javascript/node_modules/protobufjs/.travis.yml create mode 100644 javascript/node_modules/protobufjs/LICENSE create mode 100644 javascript/node_modules/protobufjs/NOTICE create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.js create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.min.js create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.min.map create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.noparse.js create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.noparse.min.js create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.noparse.min.map create mode 100644 javascript/node_modules/protobufjs/ProtoBuf.png create mode 100644 javascript/node_modules/protobufjs/README.md create mode 100755 javascript/node_modules/protobufjs/bin/proto2js create mode 100644 javascript/node_modules/protobufjs/bower.json create mode 100644 javascript/node_modules/protobufjs/build.js create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Message.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Service.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Parser.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Tokenizer.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Lang.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.Value.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.Field.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Namespace.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.Method.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.RPCMethod.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.T.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.Util.html create mode 100644 javascript/node_modules/protobufjs/docs/ProtoBuf.html create mode 100644 javascript/node_modules/protobufjs/docs/index.html create mode 100644 javascript/node_modules/protobufjs/docs/scripts/html5.js create mode 100644 javascript/node_modules/protobufjs/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/protobufjs/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/protobufjs/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/protobufjs/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/protobufjs/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/protobufjs/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/protobufjs/examples/websocket/.npmignore create mode 100644 javascript/node_modules/protobufjs/examples/websocket/README.md create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/.jshintignore create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/.jshintrc create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/.npmignore create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/LICENSE create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/README.md create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/lib/open.js create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/package.json create mode 100644 javascript/node_modules/protobufjs/examples/websocket/node_modules/open/vendor/xdg-open create mode 100644 javascript/node_modules/protobufjs/examples/websocket/package.json create mode 100644 javascript/node_modules/protobufjs/examples/websocket/server.js create mode 100644 javascript/node_modules/protobufjs/examples/websocket/www/example.proto create mode 100644 javascript/node_modules/protobufjs/examples/websocket/www/index.html create mode 100644 javascript/node_modules/protobufjs/externs/ByteBuffer.js create mode 100644 javascript/node_modules/protobufjs/externs/Long.js create mode 100644 javascript/node_modules/protobufjs/externs/ProtoBuf.js create mode 100644 javascript/node_modules/protobufjs/externs/fs.js create mode 100644 javascript/node_modules/protobufjs/jsdoc.json create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/.npmignore create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/LICENSE create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/README.md create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/alphabet/straight.json create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/ascli.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/.npmignore create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/LICENSE create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/README.md create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.min.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.png create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.css create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.html create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/colour.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/minimal-env.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/package.json create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/tests/test.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/README.md create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.png create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/package.json create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/test.js create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/package.json create mode 100644 javascript/node_modules/protobufjs/node_modules/ascli/tests/test.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/.npmignore create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/.travis.yml create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.map create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.noexpose.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/LICENSE create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/NOTICE create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/README.md create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/bower.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/build.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.Long.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/index.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/module-ByteBuffer.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/html5.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/externs/ByteBuffer.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/externs/Long.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/externs/minimal-env.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/jsdoc.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.npmignore create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.travis.yml create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/LICENSE create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.min.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/NOTICE create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/README.md create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/bower.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/Long.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/index.html create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/lang-css.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/styles/jsdoc-esoccer.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/styles/prettify-jsdoc.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/styles/prettify-tomorrow.css create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/externs/Long.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/jsdoc.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/long.png create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/package.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/tests/suite.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/package.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/src/ByteBuffer.js create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/src/bower.json create mode 100644 javascript/node_modules/protobufjs/node_modules/bytebuffer/tests/suite.js create mode 100644 javascript/node_modules/protobufjs/package.json create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/Builder.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/DotProto.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Parser.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Tokenizer.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/Lang.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/Reflect.js create mode 100644 javascript/node_modules/protobufjs/src/ProtoBuf/Util.js create mode 100644 javascript/node_modules/protobufjs/src/bower.json create mode 100644 javascript/node_modules/protobufjs/tests/PingExample.proto create mode 100644 javascript/node_modules/protobufjs/tests/T139.proto create mode 100644 javascript/node_modules/protobufjs/tests/camelcase.proto create mode 100644 javascript/node_modules/protobufjs/tests/comments.proto create mode 100644 javascript/node_modules/protobufjs/tests/complex.json create mode 100644 javascript/node_modules/protobufjs/tests/complex.proto create mode 100644 javascript/node_modules/protobufjs/tests/custom-options.proto create mode 100644 javascript/node_modules/protobufjs/tests/dupimport/dep1.proto create mode 100644 javascript/node_modules/protobufjs/tests/dupimport/dep2.proto create mode 100644 javascript/node_modules/protobufjs/tests/dupimport/main.proto create mode 100644 javascript/node_modules/protobufjs/tests/example1.proto create mode 100644 javascript/node_modules/protobufjs/tests/example1u.proto create mode 100644 javascript/node_modules/protobufjs/tests/example2.proto create mode 100644 javascript/node_modules/protobufjs/tests/example3.proto create mode 100644 javascript/node_modules/protobufjs/tests/example4.proto create mode 100644 javascript/node_modules/protobufjs/tests/extend.proto create mode 100644 javascript/node_modules/protobufjs/tests/google/protobuf/descriptor.proto create mode 100644 javascript/node_modules/protobufjs/tests/gtfs-realtime.proto create mode 100644 javascript/node_modules/protobufjs/tests/importRoot/file1.proto create mode 100644 javascript/node_modules/protobufjs/tests/importRoot/file2.proto create mode 100644 javascript/node_modules/protobufjs/tests/importRoot/file3.proto create mode 100644 javascript/node_modules/protobufjs/tests/import_a.proto create mode 100644 javascript/node_modules/protobufjs/tests/import_b.proto create mode 100644 javascript/node_modules/protobufjs/tests/import_common.proto create mode 100644 javascript/node_modules/protobufjs/tests/imports-toplevel.proto create mode 100644 javascript/node_modules/protobufjs/tests/imports.proto create mode 100644 javascript/node_modules/protobufjs/tests/inner.proto create mode 100644 javascript/node_modules/protobufjs/tests/negid.proto create mode 100644 javascript/node_modules/protobufjs/tests/nodeunit-browser/LICENSE create mode 100644 javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.css create mode 100644 javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.js create mode 100644 javascript/node_modules/protobufjs/tests/numberformats.proto create mode 100644 javascript/node_modules/protobufjs/tests/optional.proto create mode 100644 javascript/node_modules/protobufjs/tests/options.proto create mode 100644 javascript/node_modules/protobufjs/tests/proto2js/Bar.json create mode 100644 javascript/node_modules/protobufjs/tests/proto2js/Bar.proto create mode 100644 javascript/node_modules/protobufjs/tests/proto2js/Foo.proto create mode 100644 javascript/node_modules/protobufjs/tests/protobufnet.proto create mode 100644 javascript/node_modules/protobufjs/tests/repeated.proto create mode 100644 javascript/node_modules/protobufjs/tests/setarray.proto create mode 100644 javascript/node_modules/protobufjs/tests/suite.html create mode 100644 javascript/node_modules/protobufjs/tests/suite.js create mode 100644 javascript/node_modules/protobufjs/tests/toplevel.proto create mode 100644 javascript/node_modules/protobufjs/tests/x64.proto create mode 100644 javascript/step_implementation.js create mode 100755 javascript/twist.js create mode 100755 javascript/twist.sh create mode 100644 runner/js.json diff --git a/java/.idea/workspace.xml b/java/.idea/workspace.xml index b3e1517..d6d1884 100644 --- a/java/.idea/workspace.xml +++ b/java/.idea/workspace.xml @@ -67,10 +67,8 @@ - - - - + + @@ -78,10 +76,8 @@ - - - - + + @@ -89,7 +85,7 @@ - + @@ -99,11 +95,7 @@ - - - - - + @@ -111,7 +103,7 @@ - + @@ -120,11 +112,8 @@ - - - - - + + @@ -132,7 +121,7 @@ - + @@ -166,8 +155,8 @@ @@ -195,8 +184,6 @@ - - @@ -355,6 +342,8 @@ + + @@ -442,19 +431,6 @@ - + @@ -588,7 +577,6 @@ - @@ -599,8 +587,9 @@ - + + @@ -624,12 +613,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + @@ -650,9 +686,7 @@ - - - + @@ -666,9 +700,7 @@ - - - + @@ -679,9 +711,7 @@ - - - + @@ -692,9 +722,7 @@ - - - + @@ -706,9 +734,7 @@ - - - + @@ -729,9 +755,7 @@ - - - + @@ -746,9 +770,7 @@ - - - + @@ -760,30 +782,22 @@ - - - + - - - + - - - + - - - + @@ -803,28 +817,21 @@ - - - - + - - - - + + - - - + @@ -837,16 +844,12 @@ - - - + - - - + @@ -859,17 +862,13 @@ - - - - - + - + diff --git a/javascript/node_modules/.bin/proto2js b/javascript/node_modules/.bin/proto2js new file mode 120000 index 0000000..bf8828c --- /dev/null +++ b/javascript/node_modules/.bin/proto2js @@ -0,0 +1 @@ +../protobufjs/bin/proto2js \ No newline at end of file diff --git a/javascript/node_modules/bytebuffer/.npmignore b/javascript/node_modules/bytebuffer/.npmignore new file mode 100644 index 0000000..81023b6 --- /dev/null +++ b/javascript/node_modules/bytebuffer/.npmignore @@ -0,0 +1,3 @@ +node_modules/ +npm-debug.log +ByteBuffer.png diff --git a/javascript/node_modules/bytebuffer/.travis.yml b/javascript/node_modules/bytebuffer/.travis.yml new file mode 100644 index 0000000..a118245 --- /dev/null +++ b/javascript/node_modules/bytebuffer/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 + - 0.10 diff --git a/javascript/node_modules/bytebuffer/ByteBuffer.js b/javascript/node_modules/bytebuffer/ByteBuffer.js new file mode 100644 index 0000000..23f0bbc --- /dev/null +++ b/javascript/node_modules/bytebuffer/ByteBuffer.js @@ -0,0 +1,2320 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + * @expose + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + * @expose + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + * @expose + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + * @expose + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + * @expose + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + * @expose + */ + ByteBuffer.VERSION = "2.3.1"; + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + * @expose + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + * @expose + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + * @expose + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @expose + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + * @expose + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + * @expose + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + * @expose + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + * @expose + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + * @expose + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + * @expose + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + * @expose + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + * @expose + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + * @expose + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @expose + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + * @expose + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + * @expose + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + * @expose + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + * @expose + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + * @expose + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + * @expose + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + * @expose + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + * @expose + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + * @expose + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + * @expose + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + * @expose + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + * @expose + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + * @expose + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + * @expose + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + * @expose + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + * @expose + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + * @expose + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + * @expose + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + * @expose + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/bytebuffer/ByteBuffer.min.js b/javascript/node_modules/bytebuffer/ByteBuffer.min.js new file mode 100644 index 0000000..4bc46b7 --- /dev/null +++ b/javascript/node_modules/bytebuffer/ByteBuffer.min.js @@ -0,0 +1,55 @@ +/* + ByteBuffer.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/ByteBuffer.js for details +*/ +(function(n){function q(l){function c(a,b,d){a="undefined"!==typeof a?parseInt(a,10):c.DEFAULT_CAPACITY;1>a&&(a=c.DEFAULT_CAPACITY);this.array=d?null:new ArrayBuffer(a);this.view=d?null:new DataView(this.array);this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof b?!!b:!1}var p=null;if("function"===typeof require)try{var n=require("buffer"),p=n&&"function"===typeof n.Buffer&&"function"===typeof n.Buffer.isBuffer?n.Buffer:null}catch(q){}c.VERSION="2.3.1";c.DEFAULT_CAPACITY= +16;c.LITTLE_ENDIAN=!0;c.BIG_ENDIAN=!1;c.Long=l||null;c.isByteBuffer=function(a){return a&&(a instanceof c||"object"===typeof a&&(null===a.array||a.array instanceof ArrayBuffer)&&(null===a.view||a.view instanceof DataView)&&"number"===typeof a.offset&&"number"===typeof a.markedOffset&&"number"===typeof a.length&&"boolean"===typeof a.littleEndian)};c.allocate=function(a,b){return new c(a,b)};c.wrap=function(a,b,d){"boolean"===typeof b&&(d=b,b="utf8");if("string"===typeof a)switch(b){case "base64":return c.decode64(a, +d);case "hex":return c.decodeHex(a,d);case "binary":return c.decodeBinary(a,d);default:return(new c(c.DEFAULT_CAPACITY,d)).writeUTF8String(a).flip()}if(p&&p.isBuffer(a)){b=(new Uint8Array(a)).buffer;if(b===a){b=new ArrayBuffer(a.length);for(var e=new Uint8Array(b),f=0,g=a.length;fa)return!1;null===this.array&&(this.array=new ArrayBuffer(a),this.view=new DataView(this.array));if(this.array.byteLengtha||a>this.array.byteLength||1>b||b>this.array.byteLength)throw Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+a+"-"+b+")");d=this.clone();d.offset= +a;d.length=b;return d};c.prototype.ensureCapacity=function(a){return null===this.array?this.resize(a):this.array.byteLength=a?2*this.array.byteLength:a):this};c.prototype.flip=function(){this.length=null==this.array?0:this.offset;this.offset=0;return this};c.prototype.mark=function(a){if(null==this.array)throw Error(this+" cannot be marked: Already destroyed");a="undefined"!==typeof a?parseInt(a,10):this.offset;if(0>a||a>this.array.byteLength)throw Error(this+ +" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+a);this.markedOffset=a;return this};c.prototype.reset=function(){if(null===this.array)throw Error(this+" cannot be reset: Already destroyed");0<=this.markedOffset?(this.offset=this.markedOffset,this.markedOffset=-1):this.length=this.offset=0;return this};c.prototype.clone=function(){var a=new c(-1,this.littleEndian,!0);a.array=this.array;a.view=this.view;a.offset=this.offset;a.markedOffset= +this.markedOffset;a.length=this.length;return a};c.prototype.copy=function(){if(null==this.array)return this.clone();var a=new c(this.array.byteLength,this.littleEndian),b=new Uint8Array(this.array);(new Uint8Array(a.array)).set(b);a.offset=this.offset;a.markedOffset=this.markedOffset;a.length=this.length;return a};c.prototype.remaining=function(){return null===this.array?0:this.length-this.offset};c.prototype.capacity=function(){return null!=this.array?this.array.byteLength:0};c.prototype.compact= +function(){if(null==this.array)throw Error(this+" cannot be compacted: Already destroyed");this.offset>this.length&&this.flip();if(this.offset===this.length)return this.array=new ArrayBuffer(0),this.view=null,this;if(0===this.offset&&this.length===this.array.byteLength)return this;var a=new Uint8Array(this.array),b=new ArrayBuffer(this.length-this.offset);(new Uint8Array(b)).set(a.subarray(this.offset,this.length));this.array=b;this.markedOffset=this.markedOffset>=this.offset?this.markedOffset-this.offset: +-1;this.offset=0;this.length=this.array.byteLength;return this};c.prototype.destroy=function(){null!==this.array&&(this.view=this.array=null,this.offset=0,this.markedOffset=-1,this.length=0);return this};c.prototype.reverse=function(){if(null===this.array)throw Error(this+" cannot be reversed: Already destroyed");Array.prototype.reverse.call(new Uint8Array(this.array));var a=this.offset;this.offset=this.array.byteLength-this.length;this.markedOffset=-1;this.length=this.array.byteLength-a;this.view= +new DataView(this.array);return this};c.prototype.append=function(a,b){a instanceof c||(a=c.wrap(a));if(null===a.array)throw Error(a+" cannot be appended to "+this+": Already destroyed");var d=a.length-a.offset;if(0==d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);b="undefined"!==typeof b?b:(this.offset+=d)-d;this.ensureCapacity(b+d);d=new Uint8Array(a.array);(new Uint8Array(this.array)).set(d.subarray(a.offset,a.length),b);return this};c.prototype.prepend=function(a,b){a instanceof c|| +(a=c.wrap(a));if(null===a.array)throw a+" cannot be prepended to "+this+": Already destroyed";var d=a.length-a.offset;if(0==d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);var e="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=d-b;0=this.array.byteLength)throw Error("Cannot read int8 from "+this+" at "+a+": Capacity overflow");return this.view.getInt8(a)};c.prototype.writeByte=c.prototype.writeInt8;c.prototype.readByte=c.prototype.readInt8;c.prototype.writeUint8=function(a,b){b="undefined"!==typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setUint8(b,a);return this}; +c.prototype.readUint8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a+1>this.array.byteLength)throw Error("Cannot read uint8 from "+this+" at "+a+": Capacity overflow");return this.view.getUint8(a)};c.prototype.writeInt16=function(a,b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setInt16(b,a,this.littleEndian);return this};c.prototype.readInt16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+ +this+" at "+a+": Capacity overflow");return this.view.getInt16(a,this.littleEndian)};c.prototype.writeShort=c.prototype.writeInt16;c.prototype.readShort=c.prototype.readInt16;c.prototype.writeUint16=function(a,b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setUint16(b,a,this.littleEndian);return this};c.prototype.readUint16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+this+" at "+a+ +": Capacity overflow");return this.view.getUint16(a,this.littleEndian)};c.prototype.writeInt32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setInt32(b,a,this.littleEndian);return this};c.prototype.readInt32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read int32 from "+this+" at "+a+": Capacity overflow");return this.view.getInt32(a,this.littleEndian)};c.prototype.writeInt=c.prototype.writeInt32; +c.prototype.readInt=c.prototype.readInt32;c.prototype.writeUint32=function(a,b){b="undefined"!=typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setUint32(b,a,this.littleEndian);return this};c.prototype.readUint32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read uint32 from "+this+" at "+a+": Capacity overflow");return this.view.getUint32(a,this.littleEndian)};c.prototype.writeFloat32=function(a,b){b="undefined"!==typeof b? +b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setFloat32(b,a,this.littleEndian);return this};c.prototype.readFloat32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(null===this.array||a+4>this.array.byteLength)throw Error("Cannot read float32 from "+this+" at "+a+": Capacity overflow");return this.view.getFloat32(a,this.littleEndian)};c.prototype.writeFloat=c.prototype.writeFloat32;c.prototype.readFloat=c.prototype.readFloat32;c.prototype.writeFloat64=function(a,b){b="undefined"!== +typeof b?b:(this.offset+=8)-8;this.ensureCapacity(b+8);this.view.setFloat64(b,a,this.littleEndian);return this};c.prototype.readFloat64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw Error("Cannot read float64 from "+this+" at "+a+": Capacity overflow");return this.view.getFloat64(a,this.littleEndian)};c.prototype.writeDouble=c.prototype.writeFloat64;c.prototype.readDouble=c.prototype.readFloat64;l&&(c.prototype.writeInt64=function(a, +b){b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));this.ensureCapacity(b+8);this.littleEndian?(this.view.setInt32(b,a.getLowBits(),!0),this.view.setInt32(b+4,a.getHighBits(),!0)):(this.view.setInt32(b,a.getHighBits(),!1),this.view.setInt32(b+4,a.getLowBits(),!1));return this},c.prototype.readInt64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+ +this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getInt32(a,!0),this.view.getInt32(a+4,!0),!1):l.fromBits(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!1)},c.prototype.writeUint64=function(a,b){b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!0));this.ensureCapacity(b+8);this.littleEndian?(this.view.setUint32(b,a.getLowBitsUnsigned(),!0),this.view.setUint32(b+4,a.getHighBitsUnsigned(),!0)):(this.view.setUint32(b, +a.getHighBitsUnsigned(),!1),this.view.setUint32(b+4,a.getLowBitsUnsigned(),!1));return this},c.prototype.readUint64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getUint32(a,!0),this.view.getUint32(a+4,!0),!0):l.fromBits(this.view.getUint32(a+4,!1),this.view.getUint32(a,!1),!0)},c.prototype.writeLong=c.prototype.writeInt64, +c.prototype.readLong=c.prototype.readInt64);c.MAX_VARINT32_BYTES=5;c.prototype.writeVarint32=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;a>>>=0;this.ensureCapacity(b+c.calculateVarint32(a));var e=this.view,f=0;e.setUint8(b,a|128);128<=a?(e.setUint8(b+1,a>>7|128),16384<=a?(e.setUint8(b+2,a>>14|128),2097152<=a?(e.setUint8(b+3,a>>21|128),268435456<=a?(e.setUint8(b+4,a>>28&127),f=5):(e.setUint8(b+3,e.getUint8(b+3)&127),f=4)):(e.setUint8(b+2,e.getUint8(b+2)&127),f= +3)):(e.setUint8(b+1,e.getUint8(b+1)&127),f=2)):(e.setUint8(b,e.getUint8(b)&127),f=1);return d?(this.offset+=f,this):f};c.prototype.readVarint32=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d=0,e,f=this.view,g=0;do e=f.getUint8(a+d),d>>0),++d;while(e&128);g|=0;return b?(this.offset+=d,g):{value:g,length:d}};c.prototype.writeZigZagVarint32=function(a,b){return this.writeVarint32(c.zigZagEncode32(a),b)};c.prototype.readZigZagVarint32= +function(a){a=this.readVarint32(a);return"object"===typeof a?(a.value=c.zigZagDecode32(a.value),a):c.zigZagDecode32(a)};c.MAX_VARINT64_BYTES=10;l&&(c.prototype.writeVarint64=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var e=a.toInt()>>>0,f=a.shiftRightUnsigned(28).toInt()>>>0,g=a.shiftRightUnsigned(56).toInt()>>>0,k=c.calculateVarint64(a);this.ensureCapacity(b+k);var h=this.view;switch(k){case 10:h.setUint8(b+ +9,g>>>7|128);case 9:h.setUint8(b+8,g|128);case 8:h.setUint8(b+7,f>>>21|128);case 7:h.setUint8(b+6,f>>>14|128);case 6:h.setUint8(b+5,f>>>7|128);case 5:h.setUint8(b+4,f|128);case 4:h.setUint8(b+3,e>>>21|128);case 3:h.setUint8(b+2,e>>>14|128);case 2:h.setUint8(b+1,e>>>7|128);case 1:h.setUint8(b+0,e|128)}h.setUint8(b+k-1,h.getUint8(b+k-1)&127);return d?(this.offset+=k,this):k},c.prototype.readVarint64=function(a){var b="undefined"===typeof a,d=a="undefined"!==typeof a?a:this.offset,c=this.view,f,g=0, +k=0,h;h=c.getUint8(a++);f=h&127;if(h&128&&(h=c.getUint8(a++),f|=(h&127)<<7,h&128&&(h=c.getUint8(a++),f|=(h&127)<<14,h&128&&(h=c.getUint8(a++),f|=(h&127)<<21,h&128&&(h=c.getUint8(a++),g=h&127,h&128&&(h=c.getUint8(a++),g|=(h&127)<<7,h&128&&(h=c.getUint8(a++),g|=(h&127)<<14,h&128&&(h=c.getUint8(a++),g|=(h&127)<<21,h&128&&(h=c.getUint8(a++),k=h&127,h&128&&(h=c.getUint8(a++),k|=(h&127)<<7,h&128))))))))))throw Error("Data must be corrupt: Buffer overrun");c=l.from28Bits(f,g,k,!1);return b?(this.offset= +a,c):{value:c,length:a-d}},c.prototype.writeZigZagVarint64=function(a,b){return this.writeVarint64(c.zigZagEncode64(a),b)},c.prototype.readZigZagVarint64=function(a){a=this.readVarint64(a);return"object"!==typeof a||a instanceof l?c.zigZagDecode64(a):(a.value=c.zigZagDecode64(a.value),a)});c.prototype.writeVarint=c.prototype.writeVarint32;c.prototype.readVarint=c.prototype.readVarint32;c.prototype.writeZigZagVarint=c.prototype.writeZigZagVarint32;c.prototype.readZigZagVarint=c.prototype.readZigZagVarint32; +c.calculateVarint32=function(a){a>>>=0;return 128>a?1:16384>a?2:2097152>a?3:268435456>a?4:5};l&&(c.calculateVarint64=function(a){"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var b=a.toInt()>>>0,d=a.shiftRightUnsigned(28).toInt()>>>0;a=a.shiftRightUnsigned(56).toInt()>>>0;return 0==a?0==d?16384>b?128>b?1:2:2097152>b?3:4:16384>d?128>d?5:6:2097152>d?7:8:128>a?9:10});c.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0};c.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};l&&(c.zigZagEncode64= +function(a){"object"===typeof a&&a instanceof l?a.unsigned&&(a=a.toSigned()):a=l.fromNumber(a,!1);return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()},c.zigZagDecode64=function(a){"object"===typeof a&&a instanceof l?a.unsigned||(a=a.toUnsigned()):a=l.fromNumber(a,!0);return a.shiftRightUnsigned(1).xor(a.and(l.ONE).toSigned().negate()).toSigned()});c.decodeUTF8Char=function(a,b){var d=a.readUint8(b),c,f,g,k,h,l=b;if(0==(d&128))b+=1;else if(192==(d&224))c=a.readUint8(b+1),d=(d&31)<<6|c&63,b+=2; +else if(224==(d&240))c=a.readUint8(b+1),f=a.readUint8(b+2),d=(d&15)<<12|(c&63)<<6|f&63,b+=3;else if(240==(d&248))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),d=(d&7)<<18|(c&63)<<12|(f&63)<<6|g&63,b+=4;else if(248==(d&252))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),d=(d&3)<<24|(c&63)<<18|(f&63)<<12|(g&63)<<6|k&63,b+=5;else if(252==(d&254))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),h=a.readUint8(b+5),d=(d&1)<<30|(c&63)<<24| +(f&63)<<18|(g&63)<<12|(k&63)<<6|h&63,b+=6;else throw Error("Cannot decode UTF8 character at offset "+b+": charCode (0x"+d.toString(16)+") is invalid");return{"char":d,length:b-l}};c.encodeUTF8Char=function(a,b,c){var e=c;if(0>a)throw Error("Cannot encode UTF8 character: charCode ("+a+") is negative");if(128>a)b.writeUint8(a&127,c),c+=1;else if(2048>a)b.writeUint8(a>>6&31|192,c).writeUint8(a&63|128,c+1),c+=2;else if(65536>a)b.writeUint8(a>>12&15|224,c).writeUint8(a>>6&63|128,c+1).writeUint8(a&63|128, +c+2),c+=3;else if(2097152>a)b.writeUint8(a>>18&7|240,c).writeUint8(a>>12&63|128,c+1).writeUint8(a>>6&63|128,c+2).writeUint8(a&63|128,c+3),c+=4;else if(67108864>a)b.writeUint8(a>>24&3|248,c).writeUint8(a>>18&63|128,c+1).writeUint8(a>>12&63|128,c+2).writeUint8(a>>6&63|128,c+3).writeUint8(a&63|128,c+4),c+=5;else if(2147483648>a)b.writeUint8(a>>30&1|252,c).writeUint8(a>>24&63|128,c+1).writeUint8(a>>18&63|128,c+2).writeUint8(a>>12&63|128,c+3).writeUint8(a>>6&63|128,c+4).writeUint8(a&63|128,c+5),c+=6;else throw Error("Cannot encode UTF8 character: charCode (0x"+ +a.toString(16)+") is too large (>= 0x80000000)");return c-e};c.calculateUTF8Char=function(a){if(0>a)throw Error("Cannot calculate length of UTF8 character: charCode ("+a+") is negative");if(128>a)return 1;if(2048>a)return 2;if(65536>a)return 3;if(2097152>a)return 4;if(67108864>a)return 5;if(2147483648>a)return 6;throw Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");};c.a=function(a){a=""+a;for(var b=0,d=0,e=a.length;dg?a.readUint8(g++):0,e=a.length>g?a.readUint8(g++):0,f=b<<16|d<<8|e,b=f>>18&63,d=f>>12&63,e=f>>6&63,f&=63,h[k++]=m.charAt(b)+m.charAt(d)+m.charAt(e)+m.charAt(f);while(gd||0>e||0>g||0>k)throw Error("Illegal argument: Not a valid base64 encoded string");f=d<<18|e<<12|g<<6|k;d=f>>16&255;e=f>>8&255;f&=255;64==g?l.writeUint8(d):64==k?l.writeUint8(d).writeUint8(e):l.writeUint8(d).writeUint8(e).writeUint8(f)}while(h< +a.length);return l.flip()};c.encodeHex=function(a){a instanceof c?a.lengthb.length&&(b="0"+b),d.push(b);return d.join("")};c.decodeHex=function(a,b){if("string"!==typeof a)throw Error("Illegal argument: Not a string");if(0!==a.length%2)throw Error("Illegal argument: Not a hex encoded string");for(var d=new c(a.length/2,b),e=0,f=a.length;e< +f;e+=2)d.writeUint8(parseInt(a.substring(e,e+2),16));return d.flip()};c.encodeBinary=function(a){a instanceof c?a.lengtha?"+":"")+b-a)+" bytes");return d?(this.offset=b,f):{string:f,length:b-g}};c.prototype.writeLString=function(a,b){a= +""+a;var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var e=c.encodeUTF8Char(a.length,this,b),e=e+this.writeUTF8String(a,b+e);return d?(this.offset+=e,this):e};c.prototype.readLString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d=c.decodeUTF8Char(this,a);a=this.readUTF8String(d["char"],a+d.length);return b?(this.offset+=d.length+a.length,a.string):{string:a.string,length:d.length+a.length}};c.prototype.writeVString=function(a,b){a=""+a;var d= +"undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var e=this.writeVarint32(c.a(a),b),e=e+this.writeUTF8String(a,b+e);return d?(this.offset+=e,this):e};c.prototype.readVString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var c=this.readVarint32(a);a=this.readUTF8StringBytes(c.value,a+c.length);return b?(this.offset+=c.length+a.length,a.string):{string:a.string,length:c.length+a.length}};c.prototype.writeCString=function(a,b){var c="undefined"===typeof b; +b="undefined"!==typeof b?b:this.offset;var e=this.writeUTF8String(""+a,b);this.writeUint8(0,b+e);return c?(this.offset+=e+1,this):e+1};c.prototype.readCString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d,e="",f=a;do d=c.decodeUTF8Char(this,a),a+=d.length,0!=d["char"]&&(e+=String.fromCharCode(d["char"]));while(0!=d["char"]);return b?(this.offset=a,e):{string:e,length:a-f}};c.prototype.writeJSON=function(a,b,c){c="function"===typeof c?c:JSON.stringify;return this.writeLString(c(a), +b)};c.prototype.readJSON=function(a,b){b="function"===typeof b?b:JSON.parse;var c=this.readLString(a);return"string"===typeof c?b(c):{data:b(c.string),length:c.length}};c.prototype.toColumns=function(a){if(null===this.array)return"DESTROYED";a="undefined"!==typeof a?parseInt(a,10):16;1>a&&(a=16);for(var b="",c=[],e,f=this.view,b=0==this.offset&&0==this.length?b+"|":0==this.length?b+">":0==this.offset?b+"<":b+" ",g=0,k=this.array.byteLength;ge.length&&(e="0"+e);b+=e;b=g+1==this.offset&&g+1==this.length?b+"|":g+1==this.offset?b+"<":g+1==this.length?b+">":b+" "}" "!=b&&c.push(b);g=0;for(k=c.length;ge?String.fromCharCode(e):".";""!=b&&(c[h]+=" "+b);return c.join("\n")};c.prototype.printDebug=function(a){"function"!==typeof a&&(a= +console.log.bind(console));a((null!=this.array?"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n"+this.toColumns()+"\n")};c.prototype.toHex=function(a){var b="",d=this.view,e,f;if(a){if(null===this.array)return"DESTROYED";b=0==this.offset&&0==this.length?b+"|":0==this.length?b+">":0==this.offset?b+"<":b+" ";e=0;for(f=this.array.byteLength;e< +f;++e)a=d.getUint8(e).toString(16).toUpperCase(),2>a.length&&(a="0"+a),b+=a,b=e+1===this.offset&&e+1===this.length?b+"|":e+1==this.offset?b+"<":e+1==this.length?b+">":b+" ";return b}return c.encodeHex(this)};c.prototype.toBinary=function(){return c.encodeBinary(this)};c.prototype.toBase64=function(){return null===this.array||this.offset>=this.length?"":c.encode64(this)};c.prototype.toUTF8=function(){return null===this.array||this.offset>=this.length?"":this.readUTF8StringBytes(this.length-this.offset, +this.offset).string};c.prototype.toString=function(a){switch(a||""){case "utf8":return this.toUTF8();case "base64":return this.toBase64();case "hex":return this.toHex();case "binary":return this.toBinary();case "debug":return this.toHex(!0);default:return null===this.array?"ByteBuffer(DESTROYED)":"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"}};c.prototype.toArrayBuffer=function(a){if(null===this.array)return null; +var b=this.clone();b.offset>b.length&&b.flip();var c=!1;if(0b)var c=a,a=b,b=c;return new p((new Uint8Array(this.array)).subarray(a,b))});return c}"undefined"!==typeof module&&module.exports?module.exports=q(require("long")):"undefined"!==typeof define&&define.amd?define("ByteBuffer",["Math/Long"],function(l){return q(l)}): +(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ByteBuffer=q(n.dcodeIO.Long))})(this); diff --git a/javascript/node_modules/bytebuffer/ByteBuffer.min.map b/javascript/node_modules/bytebuffer/ByteBuffer.min.map new file mode 100644 index 0000000..80f5d4a --- /dev/null +++ b/javascript/node_modules/bytebuffer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AAA0C,QAAA,EACA,CAAAyP,CAAA,CAAS,CAAA,CAEb,OAAOD,EAAA,EAAcC,CAAAA,CAAd,CAAuBnS,CAAAoC,KAAA,EAAAjE,MAAvB,CAAwC6B,CAAA7B,MAXM,CAerDO,EAAJ,GASIb,CAAAyC,UAAA8R,SATJ,CASoCC,QAAQ,EAAG,CACvC,GAAmB,IAAnB,GAAI,IAAAlU,MAAJ,CAAyB,MAAO,KADO,KAEnCI,EAAS,IAAAA,OAF0B,CAEbE,EAAS,IAAAA,OACnC,IAAIF,CAAJ,CAAaE,CAAb,CACI,IAAI6T,EAAO/T,CAAX,CACAA,EAASE,CADT,CAEAA,EAAS6T,CAEb,OAAO,KAAI5T,CAAJ,CAAWkE,CAAA,IAAI3C,UAAJ,CAAe,IAAA9B,MAAf,CAAAyE,UAAA,CAAoCrE,CAApC,CAA4CE,CAA5C,CAAX,CARgC,CAT/C,CAsBA,OAAOZ,EAjuEmB,CAquER,WAAtB,GAAI,MAAO0U,OAAX,EAAqCA,MAAA,QAArC,CACIA,MAAA,QADJ,CACwB5U,CAAA,CAAegB,OAAA,CAAQ,MAAR,CAAf,CADxB,CAE6B,WAAtB,GAAI,MAAO6T,OAAX,EAAqCA,MAAA,IAArC,CACHA,MAAA,CAAO,YAAP,CAAqB,CAAC,WAAD,CAArB,CAAoC,QAAQ,CAAC5U,CAAD,CAAO,CAAE,MAAOD,EAAA,CAAeC,CAAf,CAAT,CAAnD,CADG;CAGEF,CAAA,QACL,GADwBA,CAAA,QACxB,CAD4C,EAC5C,EAAAA,CAAA,QAAA,WAAA,CAAkCC,CAAA,CAAeD,CAAA,QAAA,KAAf,CAJ/B,CAnvEO,CAAjB,CAAA,CA0vEE,IA1vEF;", +"sources":["ByteBuffer.js"], +"names":["global","loadByteBuffer","Long","ByteBuffer","capacity","littleEndian","sparse","parseInt","DEFAULT_CAPACITY","array","ArrayBuffer","view","DataView","offset","markedOffset","length","Buffer","require","nodeBuffer","e","VERSION","LITTLE_ENDIAN","BIG_ENDIAN","isByteBuffer","ByteBuffer.isByteBuffer","bb","allocate","ByteBuffer.allocate","wrap","ByteBuffer.wrap","buffer","enc","decode64","decodeHex","decodeBinary","writeUTF8String","flip","isBuffer","b","Uint8Array","ab","i","k","Error","prototype","clone","call","constructor","name","byteLength","LE","ByteBuffer.prototype.LE","BE","ByteBuffer.prototype.BE","bigEndian","resize","ByteBuffer.prototype.resize","srcView","dst","set","dstView","slice","ByteBuffer.prototype.slice","begin","end","t","ensureCapacity","ByteBuffer.prototype.ensureCapacity","ByteBuffer.prototype.flip","mark","ByteBuffer.prototype.mark","reset","ByteBuffer.prototype.reset","ByteBuffer.prototype.clone","copy","ByteBuffer.prototype.copy","src","remaining","ByteBuffer.prototype.remaining","ByteBuffer.prototype.capacity","compact","ByteBuffer.prototype.compact","subarray","destroy","ByteBuffer.prototype.destroy","reverse","ByteBuffer.prototype.reverse","Array","o","append","ByteBuffer.prototype.append","n","prepend","ByteBuffer.prototype.prepend","modify","diff","writeInt8","ByteBuffer.prototype.writeInt8","value","setInt8","readInt8","ByteBuffer.prototype.readInt8","getInt8","writeByte","readByte","writeUint8","ByteBuffer.prototype.writeUint8","setUint8","readUint8","ByteBuffer.prototype.readUint8","getUint8","writeInt16","ByteBuffer.prototype.writeInt16","setInt16","readInt16","ByteBuffer.prototype.readInt16","getInt16","writeShort","readShort","writeUint16","ByteBuffer.prototype.writeUint16","setUint16","readUint16","ByteBuffer.prototype.readUint16","getUint16","writeInt32","ByteBuffer.prototype.writeInt32","setInt32","readInt32","ByteBuffer.prototype.readInt32","getInt32","writeInt","readInt","writeUint32","ByteBuffer.prototype.writeUint32","setUint32","readUint32","ByteBuffer.prototype.readUint32","getUint32","writeFloat32","ByteBuffer.prototype.writeFloat32","setFloat32","readFloat32","ByteBuffer.prototype.readFloat32","getFloat32","writeFloat","readFloat","writeFloat64","ByteBuffer.prototype.writeFloat64","setFloat64","readFloat64","ByteBuffer.prototype.readFloat64","getFloat64","writeDouble","readDouble","writeInt64","ByteBuffer.prototype.writeInt64","fromNumber","getLowBits","getHighBits","readInt64","ByteBuffer.prototype.readInt64","fromBits","writeUint64","ByteBuffer.prototype.writeUint64","getLowBitsUnsigned","getHighBitsUnsigned","readUint64","ByteBuffer.prototype.readUint64","writeLong","readLong","MAX_VARINT32_BYTES","writeVarint32","ByteBuffer.prototype.writeVarint32","advance","calculateVarint32","size","readVarint32","ByteBuffer.prototype.readVarint32","count","writeZigZagVarint32","ByteBuffer.prototype.writeZigZagVarint32","zigZagEncode32","readZigZagVarint32","ByteBuffer.prototype.readZigZagVarint32","dec","zigZagDecode32","MAX_VARINT64_BYTES","writeVarint64","ByteBuffer.prototype.writeVarint64","part0","toInt","part1","shiftRightUnsigned","part2","calculateVarint64","readVarint64","ByteBuffer.prototype.readVarint64","start","from28Bits","writeZigZagVarint64","ByteBuffer.prototype.writeZigZagVarint64","zigZagEncode64","readZigZagVarint64","ByteBuffer.prototype.readZigZagVarint64","zigZagDecode64","writeVarint","readVarint","writeZigZagVarint","readZigZagVarint","ByteBuffer.calculateVarint32","TWO_PWR_7_DBL","TWO_PWR_14_DBL","TWO_PWR_21_DBL","TWO_PWR_28_DBL","ByteBuffer.calculateVarint64","ByteBuffer.zigZagEncode32","ByteBuffer.zigZagDecode32","ByteBuffer.zigZagEncode64","unsigned","toSigned","shiftLeft","xor","shiftRight","toUnsigned","ByteBuffer.zigZagDecode64","and","ONE","negate","decodeUTF8Char","ByteBuffer.decodeUTF8Char","a","c","d","f","charCode","toString","encodeUTF8Char","ByteBuffer.encodeUTF8Char","calculateUTF8Char","ByteBuffer.calculateUTF8Char","calculateUTF8String","ByteBuffer.calculateUTF8String","str","bytes","charCodeAt","B64","encode64","ByteBuffer.encode64","o1","o2","o3","h4","oi","out","bits","h1","h2","h3","charAt","join","r","ByteBuffer.decode64","Math","ceil","indexOf","encodeHex","ByteBuffer.encodeHex","val","toUpperCase","push","ByteBuffer.decodeHex","substring","encodeBinary","ByteBuffer.encodeBinary","String","fromCharCode","ByteBuffer.decodeBinary","ByteBuffer.prototype.writeUTF8String","encLen","j","readUTF8String","ByteBuffer.prototype.readUTF8String","chars","result","readUTF8StringBytes","ByteBuffer.prototype.readUTF8StringBytes","writeLString","ByteBuffer.prototype.writeLString","readLString","ByteBuffer.prototype.readLString","lenDec","writeVString","ByteBuffer.prototype.writeVString","readVString","ByteBuffer.prototype.readVString","writeCString","ByteBuffer.prototype.writeCString","readCString","ByteBuffer.prototype.readCString","writeJSON","ByteBuffer.prototype.writeJSON","data","stringify","JSON","readJSON","ByteBuffer.prototype.readJSON","parse","toColumns","ByteBuffer.prototype.toColumns","lines","printDebug","ByteBuffer.prototype.printDebug","console","log","bind","toHex","ByteBuffer.prototype.toHex","debug","toBinary","ByteBuffer.prototype.toBinary","toBase64","ByteBuffer.prototype.toBase64","toUTF8","ByteBuffer.prototype.toUTF8","ByteBuffer.prototype.toString","toArrayBuffer","ByteBuffer.prototype.toArrayBuffer","forceCopy","copied","toBuffer","ByteBuffer.prototype.toBuffer","temp","module","define"] +} diff --git a/javascript/node_modules/bytebuffer/ByteBuffer.noexpose.js b/javascript/node_modules/bytebuffer/ByteBuffer.noexpose.js new file mode 100644 index 0000000..202cbca --- /dev/null +++ b/javascript/node_modules/bytebuffer/ByteBuffer.noexpose.js @@ -0,0 +1,2207 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + */ + ByteBuffer.VERSION = "2.3.1"; + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/bytebuffer/LICENSE b/javascript/node_modules/bytebuffer/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/bytebuffer/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/bytebuffer/NOTICE b/javascript/node_modules/bytebuffer/NOTICE new file mode 100644 index 0000000..3eac38f --- /dev/null +++ b/javascript/node_modules/bytebuffer/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) ByteBuffer.js by Daniel 'dcode' Wirtz. +See: https://github.com/dcodeIO/ByteBuffer.js for details diff --git a/javascript/node_modules/bytebuffer/README.md b/javascript/node_modules/bytebuffer/README.md new file mode 100644 index 0000000..3b0b611 --- /dev/null +++ b/javascript/node_modules/bytebuffer/README.md @@ -0,0 +1,121 @@ +![ByteBuffer.js - A full-featured ByteBuffer implementation in JavaScript](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png) +====================================== +Provides a full-featured ByteBuffer implementation using typed arrays. It's one of the core components driving +[ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js) and the [PSON](https://github.com/dcodeIO/PSON) reference +implementation. + +*Note:* The API behind #toHex and #toString has changed with ByteBuffer 2, which is a generally revised release, in +favor of making this more intuitive. + +What can it do? +--------------- +* Mimics Java ByteBuffers as close as reasonable while using typed array terms +* Signed and unsigned integers (8, 16, 32, 64 bit through [Long.js](https://github.com/dcodeIO/Long.js)) with endianness support +* 32 and 64 bit floats +* Varints as known from protobuf including zig-zag encoding +* Includes an UTF8 and Base64 en-/decoder +* C-strings, V(arint-prefixed)-strings and UTF8 L(ength-prefixed)-strings +* Rich string toolset (to hex, base64, binary, utf8, debug, columns) +* Relative and absolute zero-copy operations +* Manual and automatic resizing (efficiently doubles capacity) +* Chaining of all operations that do not return a specific value +* Slicing, appending, prepending, reversing, flip, mark, reset, etc. + +And much more... + +Features +-------- +* [CommonJS](http://www.commonjs.org/) compatible +* [RequireJS](http://requirejs.org/)/AMD compatible +* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/bytebuffer) +* Browser compatible +* [Closure Compiler](https://developers.google.com/closure/compiler/) ADVANCED_OPTIMIZATIONS compatible (fully annotated, + `ByteBuffer.min.js` has been compiled this way, `ByteBuffer.min.map` is the source map) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* Well tested through [nodeunit](https://github.com/caolan/nodeunit) +* Zero production dependencies (Long.js is optional) +* Small footprint + +Usage +----- +### Node.js / CommonJS ### +* Install: `npm install bytebuffer` + +```javascript +var ByteBuffer = require("bytebuffer"); +var bb = new ByteBuffer(); +bb.writeLString("Hello world!").flip(); +console.log(bb.readLString()+" from ByteBuffer.js"); +``` + +### Browser ### + +Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long +support, you can skip the Long.js include. + +```html + + +``` + +```javascript +var ByteBuffer = dcodeIO.ByteBuffer; +var bb = new ByteBuffer(); +bb.writeLString("Hello world!").flip(); +alert(bb.readLString()+" from ByteBuffer.js"); +``` + +### Require.js / AMD ### + +Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long +support, you can skip the Long.js config. [Require.js](http://requirejs.org/) example: + +```javascript +require.config({ + "paths": { + "Long": "/path/to/Long.js" + "ByteBuffer": "/path/to/ByteBuffer.js" + } +}); +require(["ByteBuffer"], function(ByteBuffer) { + var bb = new ByteBuffer(); + bb.writeLString("Hello world!"); + bb.flip(); + alert(bb.readLString()+" from ByteBuffer.js"); +}); +``` + +On long (int64) support +----------------------- +As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value +of 2^53. Beyond that, behaviour might be unexpected. However, real long support requires the full 64 bits +with the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support +in ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two +32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth. +On node, long support is available by default through the [long](https://npmjs.org/package/long) dependency. + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/ByteBuffer.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/ByteBuffer.js/tarball/master) + +Documentation +------------- +* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/ByteBuffer.js/master/docs/ByteBuffer.html) + +Tests (& Examples) [![Build Status](https://travis-ci.org/dcodeIO/ByteBuffer.js.png?branch=master)](https://travis-ci.org/dcodeIO/ByteBuffer.js) +------------------ +* [View source](https://github.com/dcodeIO/ByteBuffer.js/blob/master/tests/suite.js) +* [View report](https://travis-ci.org/dcodeIO/ByteBuffer.js) + +Support for IE<10, FF<15, Chrome<9 etc. +--------------------------------------- +* Requires working ArrayBuffer & DataView implementations (i.e. use a [polyfill](https://github.com/inexorabletash/polyfill#typed-arrays-polyfill)) + +Contributors +------------ +[Dretch](https://github.com/Dretch) (IE8 compatibility) + +License +------- +Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/javascript/node_modules/bytebuffer/bower.json b/javascript/node_modules/bytebuffer/bower.json new file mode 100644 index 0000000..7439693 --- /dev/null +++ b/javascript/node_modules/bytebuffer/bower.json @@ -0,0 +1,12 @@ +{ + "name": "bytebuffer", + "version": "2.3.1", + "author": "Daniel Wirtz ", + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"], + "dependencies": { + "long": "latest" + }, + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/bytebuffer/build.js b/javascript/node_modules/bytebuffer/build.js new file mode 100644 index 0000000..39013d4 --- /dev/null +++ b/javascript/node_modules/bytebuffer/build.js @@ -0,0 +1,35 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ByteBuffer.js Build Script (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ + +var Preprocessor = require("preprocessor"), + fs = require("fs"), + pkg = require(__dirname+"/package.json"); + +var pp = new Preprocessor(fs.readFileSync(__dirname+"/src/ByteBuffer.js"), __dirname+"/src"); +fs.writeFileSync(__dirname+"/ByteBuffer.js", pp.process({ + "VERSION": pkg.version +})); + +pp = new Preprocessor(fs.readFileSync(__dirname+"/src/bower.json"), __dirname+"/src"); +fs.writeFileSync(__dirname+"/bower.json", pp.process({ + "VERSION": pkg.version +})); diff --git a/javascript/node_modules/bytebuffer/docs/ByteBuffer.Long.html b/javascript/node_modules/bytebuffer/docs/ByteBuffer.Long.html new file mode 100644 index 0000000..85c2e5e --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/ByteBuffer.Long.html @@ -0,0 +1,4269 @@ + + + + + Class: Long + + + + + + + + + + +
+ +

Class: Long

+ + + + + +
+ +
+

+ ByteBuffer. + + Long +

+ +
+ +
+
+ + + + +
+

new Long(low, high)

+ + +
+
+ + +
+

Constructs a 64-bit two's-complement integer, given its low and high 32-bit +values as signed integers. See the from* functions below for more +convenient ways of constructing Longs.

+ +

The internal representation of a long is the two given signed, 32-bit values. +We use 32-bit pieces because these are the size of integers on which +Javascript performs bit-operations. For operations like addition and +multiplication, we split each number into 16-bit pieces, which can easily be +multiplied within Javascript's floating-point representation without overflow +or change in sign.

+ +

In the algorithms below, we frequently reduce the negative case to the +positive case by negating the input(s) and then post-processing the result. +Note that we must ALWAYS check specially whether those values are MINVALUE +(-2^63) because -MINVALUE == MIN_VALUE (since 2^63 cannot be represented as +a positive number, it overflows back into a negative). Not handling this +case would often result in infinite recursion.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
low + + +number + + + +

The low (signed) 32 bits of the long.

high + + +number + + + +

The high (signed) 32 bits of the long.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static> MAX_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> NEG_ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ZERO :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> fromBits(lowBits, highBits) → {Long}

+ + +
+
+ + +
+

Returns a Long representing the 64-bit integer that comes by concatenating +the given high and low bits. Each is assumed to use 32 bits.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lowBits + + +number + + + +

The low 32-bits.

highBits + + +number + + + +

The high 32-bits.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The corresponding Long value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromInt(value) → {Long}

+ + +
+
+ + +
+

Returns a Long representing the given (32-bit) integer value.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number + + + +

The 32-bit integer in question.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The corresponding Long value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromNumber(value) → {Long}

+ + +
+
+ + +
+

Returns a Long representing the given value, provided that it is a finite +number. Otherwise, zero is returned.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number + + + +

The number in question.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The corresponding Long value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromString(str, opt_radix) → {Long}

+ + +
+
+ + +
+

Returns a Long representation of the given string, written using the given +radix.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

The textual representation of the Long.

opt_radix + + +number + + + + + + <optional>
+ + + +

The radix in which the text is written.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The corresponding Long value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

add(other) → {Long}

+ + +
+
+ + +
+

Returns the sum of this and the given Long.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to add to this one.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The sum of this and the given Long.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

and(other) → {Long}

+ + +
+
+ + +
+

Returns the bitwise-AND of this Long and the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

The Long with which to AND.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The bitwise-AND of this and the other.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

compare(other) → {number}

+ + +
+
+ + +
+

Compares this Long with the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

0 if they are the same, 1 if the this is greater, and -1 + if the given one is greater.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

div(other) → {Long}

+ + +
+
+ + +
+

Returns this Long divided by the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long by which to divide.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

This Long divided by the given one.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

equals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long equals the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

getHighBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The high 32-bits as a signed value.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The low 32-bits as a signed value.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBitsUnsigned() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The low 32-bits as an unsigned value.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getNumBitsAbs() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Returns the number of bits needed to represent the absolute + value of this Long.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

greaterThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long is greater than the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

greaterThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long is greater than or equal to the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isNegative() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this value is negative.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isOdd() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this value is odd.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isZero() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this value is zero.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long is less than the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long is less than or equal to the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

modulo(other) → {Long}

+ + +
+
+ + +
+

Returns this Long modulo the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long by which to mod.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

This Long modulo the given one.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

multiply(other) → {Long}

+ + +
+
+ + +
+

Returns the product of this and the given long.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to multiply with this.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The product of this and the other.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

negate() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The negation of this value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

not() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The bitwise-NOT of this value.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

notEquals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to compare against.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Whether this Long does not equal the other.

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

or(other) → {Long}

+ + +
+
+ + +
+

Returns the bitwise-OR of this Long and the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

The Long with which to OR.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The bitwise-OR of this and the other.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftLeft(numBits) → {Long}

+ + +
+
+ + +
+

Returns this Long with bits shifted to the left by the given amount.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + +

The number of bits by which to shift.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

This shifted to the left by the given amount.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRight(numBits) → {Long}

+ + +
+
+ + +
+

Returns this Long with bits shifted to the right by the given amount.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + +

The number of bits by which to shift.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

This shifted to the right by the given amount.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRightUnsigned(numBits) → {Long}

+ + +
+
+ + +
+

Returns this Long with bits shifted to the right by the given amount, with +the new top bits matching the current sign bit.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + +

The number of bits by which to shift.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

This shifted to the right by the given amount, with + zeros placed into the new leading bits.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

subtract(other) → {Long}

+ + +
+
+ + +
+

Returns the difference of this and the given Long.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

Long to subtract from this.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The difference of this and the given Long.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

toInt() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The value, assuming it is a 32-bit integer.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toNumber() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The closest floating-point representation to this value.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toString(opt_radix) → {string}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
opt_radix + + +number + + + + + + <optional>
+ + + +

The radix in which the text should be written.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The textual representation of this value.

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

xor(other) → {Long}

+ + +
+
+ + +
+

Returns the bitwise-XOR of this Long and the given one.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + +

The Long with which to XOR.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The bitwise-XOR of this and the other.

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/docs/ByteBuffer.html b/javascript/node_modules/bytebuffer/docs/ByteBuffer.html new file mode 100644 index 0000000..2bc98f2 --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/ByteBuffer.html @@ -0,0 +1,15285 @@ + + + + + Class: ByteBuffer + + + + + + + + + + +
+ +

Class: ByteBuffer

+ + + + + +
+ +
+

+ ByteBuffer +

+ +

A full-featured ByteBuffer implementation in JavaScript using typed arrays.

+ +
+ +
+
+ + + + +
+

new ByteBuffer(capacity, littleEndian)

+ + +
+
+ + +
+

Constructs a new ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
capacity + + +number + + + + + + <optional>
+ + + +

Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian multi byte values, defaults to false for big + endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static, constant> BIG_ENDIAN :boolean

+ + +
+
+ +
+

Big endian constant for usage in constructors instead of a boolean value. Evaluates to false.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> DEFAULT_CAPACITY :number

+ + +
+
+ +
+

Default buffer capacity of 16. The ByteBuffer will be automatically resized by a factor of 2 if required.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> LITTLE_ENDIAN :boolean

+ + +
+
+ +
+

Little endian constant for usage in constructors instead of a boolean value. Evaluates to true.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> Long :Long|undefined

+ + +
+
+ +
+

Long class for int64 support. May be undefined if the Long class has not been loaded and int64 support is + not available.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> MAX_VARINT32_BYTES :number

+ + +
+
+ +
+

Maximum number of bytes used by 32bit base 128 variable-length integer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> MAX_VARINT64_BYTES :number

+ + +
+
+ +
+

Maximum number of bytes used by a 64bit base 128 variable-length integer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> VERSION :string

+ + +
+
+ +
+

Version string.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

array :ArrayBuffer

+ + +
+
+ +
+

Backing ArrayBuffer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

length :number

+ + +
+
+ +
+

Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + offset and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

littleEndian :boolean

+ + +
+
+ +
+

Whether to use little endian multi byte values, defaults to false for big endian.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

markedOffset :number

+ + +
+
+ +
+

Marked offset set through ByteBuffer#mark. Defaults to -1 (no marked offset).

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

offset :number

+ + +
+
+ +
+

Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

view :DataView

+ + +
+
+ +
+

DataView to mess with the ArrayBuffer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> allocate(capacity, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Allocates a new ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
capacity + + +number + + + + + + <optional>
+ + + +

Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian multi byte values, defaults to false for big + endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> calculateUTF8Char(charCode) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode the specified char code.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
charCode + + +number + + + +

Character to encode as char code

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be calculated (too large) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Number of bytes required to encode the specified char code

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateUTF8String(str) → {number}

+ + +
+
+ + +
+

Calculates the number of bytes required to store an UTF8 encoded string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +string + + + +

String to calculate

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateVarint32(value) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number + + + +

Value to encode

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required. Capped to ByteBuffer.MAX_VARINT32_BYTES

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateVarint64(value) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number +| + +!Long + + + +

Value to encode

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required. Capped to ByteBuffer.MAX_VARINT64_BYTES

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> decode64(str, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Decodes a base64 encoded string to a ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

Base64 encoded string

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian byte order, defaults to false for big endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid base64 encoded string +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> decodeHex(str, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Decodes a hex encoded string to a ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

Hex encoded string

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian byte order, defaults to false for big endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid hex encoded string +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> decodeUTF8Char(src, offset) → {{char: number, length: number}}

+ + +
+
+ + +
+

Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
src + + +ByteBuffer + + + +
offset + + +number + + + +

Offset to read from

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be decoded or there is a capacity overflow +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded char code and the actual number of bytes read

+
+ + + +
+
+ Type +
+
+ +{char: number, length: number} + + +
+
+ + + + +
+ + + +
+

<static> encode64(bb) → {string}

+ + +
+
+ + +
+

Encodes a ByteBuffer's contents to a base64 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bb + + +ByteBuffer + + + +

ByteBuffer

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is invalid +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Base64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

<static> encodeUTF8Char(charCode, dst, offset) → {number}

+ + +
+
+ + +
+

Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
charCode + + +number + + + +

Character to encode as char code

dst + + +ByteBuffer + + + +

ByteBuffer to encode to

offset + + +number + + + +

Offset to write to

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be encoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> wrap(buffer, enc, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + ByteBuffer's offset to 0 and its length to the wrapped object's byte length.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
buffer + + +ArrayBuffer +| + +!Buffer +| + +!{array: !ArrayBuffer} +| + +!{buffer: !ArrayBuffer} +| + +string + + + + + + + +

Anything that can + be wrapped

enc + + +string +| + +boolean + + + + + + <optional>
+ + + +

String encoding if a string is provided (hex, utf8, defaults to base64)

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian multi byte values, defaults to false for big + endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified object cannot be wrapped +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> zigZagDecode32(n) → {number}

+ + +
+
+ + +
+

Decodes a zigzag encoded signed 32bit integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +

Unsigned zigzag encoded 32bit integer

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Signed 32bit integer

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> zigZagDecode64(n) → {Long}

+ + +
+
+ + +
+

Decodes a zigzag encoded signed 64bit integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +Long +| + +number + + + +

Unsigned zigzag encoded long or JavaScript number

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If long support is not available +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Signed long

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> zigZagEncode32(n) → {number}

+ + +
+
+ + +
+

Encodes a signed 32bit integer so that it can be effectively used with varint encoding.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +

Signed 32bit integer

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Unsigned zigzag encoded 32bit integer

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> zigZagEncode64(n) → {Long}

+ + +
+
+ + +
+

Encodes a signed 64bit integer so that it can be effectively used with varint encoding.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number +| + +!Long + + + +

Signed long

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Unsigned zigzag encoded long

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

append(src, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
src + + +* + + + + + + + +

ByteBuffer or any object that can be wrapped to append

offset + + +number + + + + + + <optional>
+ + + +

Offset to append at. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

BE(bigEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Switches big endian byte order.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
bigEndian + + +boolean + + + + + + <optional>
+ + + +

Defaults to true, otherwise uses little endian

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

capacity() → {number}

+ + +
+
+ + +
+

Gets the capacity of the backing buffer. This is independent from ByteBuffer#length and returns the + size of the entire backing array.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Capacity of the backing array or 0 if destroyed

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

clone() → {ByteBuffer}

+ + +
+
+ + +
+

Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + offsets.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Clone

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

compact() → {ByteBuffer}

+ + +
+
+ + +
+

Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set offset=0 and + length=capacity.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer cannot be compacted +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

copy() → {ByteBuffer}

+ + +
+
+ + +
+

Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Copy

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

destroy() → {ByteBuffer}

+ + +
+
+ + +
+

Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + is usually not required but may be useful in limited memory environments. Most successive operations will + rise an error until ByteBuffer#resize or ByteBuffer#ensureCapacity is called to reinitialize + the backing array.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

ensureCapacity(capacity) → {ByteBuffer}

+ + +
+
+ + +
+

Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + If double the previous capacity is less than the required capacity, the required capacity will be used.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capacity + + +number + + + +

Required capacity

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

flip() → {ByteBuffer}

+ + +
+
+ + +
+

Makes the buffer ready for a new sequence of write or relative read operations. Sets length=offset and + offset=0. Always make sure to flip a buffer when all relative writing operations are complete.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

LE(littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Switches little endian byte order.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
littleEndian + + +boolean + + + + + + <optional>
+ + + +

Defaults to true, otherwise uses big endian

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

mark(offset) → {ByteBuffer}

+ + +
+
+ + +
+

Marks an offset to be used with ByteBuffer#reset.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to mark. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + +
Throws:
+ + +
+ If the mark cannot be set +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

prepend(src, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
src + + +* + + + + + + + +

ByteBuffer or any object that can be wrapped to prepend

offset + + +number + + + + + + <optional>
+ + + +

Offset to prepend at. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

printDebug(out)

+ + +
+
+ + +
+

Prints debug information about this ByteBuffer's contents.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
out + + +function(string) + + + + + + <optional>
+ + + +

Output function to call, defaults to console.log

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+

readByte(offset) → {number}

+ + +
+
+ + +
+

Reads a byte. This is an alias of ByteBuffer#readInt8.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readCString(offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string followed by a NULL character (Uint8).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readDouble(offset) → {number}

+ + +
+
+ + +
+

Reads a double. This is an alias of ByteBuffer#readFloat64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat(offset) → {number}

+ + +
+
+ + +
+

Reads a float. This is an alias of ByteBuffer#readFloat32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat64(offset) → {number}

+ + +
+
+ + +
+

Reads a 64bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt(offset) → {number}

+ + +
+
+ + +
+

Reads an integer. This is an alias of ByteBuffer#readInt32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt8(offset) → {number}

+ + +
+
+ + +
+

Reads an 8bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt16(offset) → {number}

+ + +
+
+ + +
+

Reads a 16bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt64(offset) → {Long}

+ + +
+
+ + +
+

Reads a 64bit integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readJSON(offset, parse) → {*|!{data: *, length: number}}

+ + +
+
+ + +
+

Reads a JSON payload and unserializes it.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

parse + + +function(string) + + + + + + <optional>
+ + + +

Parse implementation to use. Defaults to JSON.parse.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the data cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Data payload if offset is omitted, else the data payload and the + actual number of bytes read

+
+ + + +
+
+ Type +
+
+ +* +| + +!{data: *, length: number} + + +
+
+ + + + +
+ + + +
+

readLong(offset) → {Long}

+ + +
+
+ + +
+

Reads a long. This is an alias of ByteBuffer#readInt64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readLString(offset) → {string|{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string with a prepended number of characters, which is also encoded as an UTF8 character.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readShort(offset) → {number}

+ + +
+
+ + +
+

Reads a short value. This is an alias of ByteBuffer#readInt16.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint8(offset) → {number}

+ + +
+
+ + +
+

Reads an 8bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint16(offset) → {number}

+ + +
+
+ + +
+

Reads a 16bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint64(offset) → {Long}

+ + +
+
+ + +
+

Reads a 64bit unsigned integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readUTF8String(chars, offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads an UTF8 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
chars + + +number + + + + + + + +

Number of characters to read

offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readUTF8StringBytes(length, offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads an UTF8 string with the specified byte length.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
length + + +number + + + + + + + +

Byte length

offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the length did not match or the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint(offset) → {number|{value: number, length: number}}

+ + +
+
+ + +
+

Reads a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint32(offset) → {number|!{value: number, length: number}}

+ + +
+
+ + +
+

Reads a 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +!{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint64(offset) → {Long|!{value: Long, length: number}}

+ + +
+
+ + +
+

Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and + the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +Long +| + +!{value: Long, length: number} + + +
+
+ + + + +
+ + + +
+

readVString(offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded or if it is not preceeded by a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint(offset) → {number|{value: number, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readZigZagVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint32(offset) → {number|{value: number, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint64(offset) → {Long|{value: Long, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +Long +| + +{value: Long, length: number} + + +
+
+ + + + +
+ + + +
+

remaining() → {number}

+ + +
+
+ + +
+

Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + returns length-offset.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Remaining readable bytes. May be negative if offset>length.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

reset() → {ByteBuffer}

+ + +
+
+ + +
+

Resets the ByteBuffer. If an offset has been marked through ByteBuffer#mark before, the offset will + be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + no marked offset, sets offset=0 and length=0.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

resize(capacity) → {ByteBuffer}

+ + +
+
+ + +
+

Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capacity + + +number + + + +

New capacity

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

reverse() → {ByteBuffer}

+ + +
+
+ + +
+

Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00".

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

slice(begin, end) → {ByteBuffer}

+ + +
+
+ + +
+

Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + ArrayBuffer (use ByteBuffer#compact or ByteBuffer.wrap instead).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
begin + + +number + + + + + + <optional>
+ + + +

Begin offset, defaults to ByteBuffer#offset.

end + + +number + + + + + + <optional>
+ + + +

End offset, defaults to ByteBuffer#length.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer cannot be sliced +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

toArrayBuffer(forceCopy) → {ArrayBuffer}

+ + +
+
+ + +
+

Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will return a reference to + the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
forceCopy + + +boolean + + + + + + <optional>
+ + + +

true forces the creation of a copy, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Compacted ArrayBuffer or null if already destroyed

+
+ + + +
+
+ Type +
+
+ +ArrayBuffer + + +
+
+ + + + +
+ + + +
+

toBase64() → {string}

+ + +
+
+ + +
+

Returns the base64 encoded representation of the ByteBuffer's contents.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Base 64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toBuffer() → {Buffer}

+ + +
+
+ + +
+

Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will also copy all data (not + a reference).

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Compacted node Buffer or null if already destroyed

+
+ + + +
+
+ Type +
+
+ +Buffer + + +
+
+ + + + +
+ + + +
+

toColumns(wrap) → {string}

+ + +
+
+ + +
+

Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
wrap + + +number + + + + + + <optional>
+ + + +

Wrap length. Defaults to 16.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toHex(debug) → {string}

+ + +
+
+ + +
+

Returns the ByteBuffer's contents between offset and length as a hex string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
debug + + +boolean + + + + + + <optional>
+ + + +

true to return the entire backing array with marked offsets, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Hex string or debug string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(enc) → {string}

+ + +
+
+ + +
+

Converts the ByteBuffer to a string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
enc + + +string + + + + + + <optional>
+ + + +

Output encoding. Returns an informative string representation by default but also allows + direct conversion to "utf8", "hex" and "base64" encoding. "debug" returns a hex representation with marked + offsets.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toUTF8() → {string}

+ + +
+
+ + +
+

Returns the ByteBuffer's contents as an UTF8 encoded string.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

writeByte(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a byte. This is an alias of {ByteBuffer#writeInt8}.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeCString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + characters unless this is actually intended. This is not checked. If you have the option it is recommended + to use ByteBuffer#writeLString or ByteBuffer#writeVString with the corresponding reading + methods instead.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeDouble(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a double. This is an alias of ByteBuffer#writeFloat64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a float. This is an alias of ByteBuffer#writeFloat32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an integer. This is an alias of ByteBuffer#writeInt32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt8(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an 8bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if + omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt16(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 16bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeJSON(data, offset, stringify) → {ByteBuffer|number}

+ + +
+
+ + +
+

Serializes and writes a JSON payload.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
data + + +* + + + + + + + +

Data payload to serialize

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

stringify + + +function(*) + + + + + + <optional>
+ + + +

Stringify implementation to use. Defaults to JSON.stringify.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number if bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeLong(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a long. This is an alias of ByteBuffer#writeInt64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeLString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string with prepended number of characters, which is also encoded as an UTF8 character..

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeShort(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a short value. This is an alias of ByteBuffer#writeInt16.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint8(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an 8bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint16(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 16bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit unsigned integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUTF8String(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes an UTF8 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint32(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint64(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a 64bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeZigZagVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint32(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint64(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/docs/index.html b/javascript/node_modules/bytebuffer/docs/index.html new file mode 100644 index 0000000..0751f84 --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
+ +

Index

+ + + + + + + +

+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/docs/module-ByteBuffer.html b/javascript/node_modules/bytebuffer/docs/module-ByteBuffer.html new file mode 100644 index 0000000..868c7a0 --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/module-ByteBuffer.html @@ -0,0 +1,15872 @@ + + + + + Module: ByteBuffer + + + + + + + + + + +
+ +

Module: ByteBuffer

+ + + + + +
+ +
+

+ ByteBuffer +

+ +

A full-featured ByteBuffer implementation in JavaScript using typed arrays.

+ +
+ +
+
+ + + + +

Constructs a new ByteBuffer.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static, constant> BIG_ENDIAN :boolean

+ + +
+
+ +
+

Big endian constant for usage in constructors instead of a boolean value. Evaluates to false.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> DEFAULT_CAPACITY :number

+ + +
+
+ +
+

Default buffer capacity of 16. The ByteBuffer will be automatically resized by a factor of 2 if required.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> LITTLE_ENDIAN :boolean

+ + +
+
+ +
+

Little endian constant for usage in constructors instead of a boolean value. Evaluates to true.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> Long :Long

+ + +
+
+ +
+

Long class for int64 support. May be null if the Long class has not been loaded and int64 support is + not available.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> MAX_VARINT32_BYTES :number

+ + +
+
+ +
+

Maximum number of bytes used by 32bit base 128 variable-length integer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> MAX_VARINT64_BYTES :number

+ + +
+
+ +
+

Maximum number of bytes used by a 64bit base 128 variable-length integer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> VERSION :string

+ + +
+
+ +
+

Version string.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

array :ArrayBuffer

+ + +
+
+ +
+

Backing ArrayBuffer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

length :number

+ + +
+
+ +
+

Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + offset and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

littleEndian :boolean

+ + +
+
+ +
+

Whether to use little endian multi byte values, defaults to false for big endian.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

markedOffset :number

+ + +
+
+ +
+

Marked offset set through ByteBuffer#mark. Defaults to -1 (no marked offset).

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

offset :number

+ + +
+
+ +
+

Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

view :DataView

+ + +
+
+ +
+

DataView to mess with the ArrayBuffer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> allocate(capacity, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Allocates a new ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
capacity + + +number + + + + + + <optional>
+ + + +

Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian multi byte values, defaults to false for big + endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> calculateUTF8Char(charCode) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode the specified char code.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
charCode + + +number + + + +

Character to encode as char code

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be calculated (too large) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Number of bytes required to encode the specified char code

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateUTF8String(str) → {number}

+ + +
+
+ + +
+

Calculates the number of bytes required to store an UTF8 encoded string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +string + + + +

String to calculate

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateVarint32(value) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number + + + +

Value to encode

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required. Capped to ByteBuffer.MAX_VARINT32_BYTES

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> calculateVarint64(value) → {number}

+ + +
+
+ + +
+

Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +number +| + +!Long + + + +

Value to encode

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Number of bytes required. Capped to ByteBuffer.MAX_VARINT64_BYTES

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> decode64(str, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Decodes a base64 encoded string to a ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

Base64 encoded string

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian byte order, defaults to false for big endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid base64 encoded string +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> decodeBinary(str, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Decodes a binary string to a ByteBuffer. A binary string in this case is a string composed of 8bit values + as characters with a char code between 0 and 255 inclusive.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

Binary string

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian byte order, defaults to false for big endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid binary string +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> decodeHex(str, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Decodes a hex encoded string to a ByteBuffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

Hex encoded string

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian byte order, defaults to false for big endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid hex encoded string +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> decodeUTF8Char(src, offset) → {{char: number, length: number}}

+ + +
+
+ + +
+

Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
src + + +ByteBuffer + + + +
offset + + +number + + + +

Offset to read from

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be decoded or there is a capacity overflow +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded char code and the actual number of bytes read

+
+ + + +
+
+ Type +
+
+ +{char: number, length: number} + + +
+
+ + + + +
+ + + +
+

<static> encode64(bb) → {string}

+ + +
+
+ + +
+

Encodes a ByteBuffer's contents to a base64 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bb + + +ByteBuffer + + + +

ByteBuffer to encode. Will be cloned and flipped if length < offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid ByteBuffer +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Base64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

<static> encodeBinary(bb) → {string}

+ + +
+
+ + +
+

Encodes a ByteBuffer to a binary string. A binary string in this case is a string composed of 8bit values + as characters with a char code between 0 and 255 inclusive.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bb + + +ByteBuffer + + + +

ByteBuffer to encode. Will be cloned and flipped if length < offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid ByteBuffer +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Binary string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

<static> encodeHex(bb) → {string}

+ + +
+
+ + +
+

Encodes a ByteBuffer to a hex encoded string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bb + + +ByteBuffer + + + +

ByteBuffer to encode. Will be cloned and flipped if length < offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the argument is not a valid ByteBuffer +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Hex encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

<static> encodeUTF8Char(charCode, dst, offset) → {number}

+ + +
+
+ + +
+

Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
charCode + + +number + + + +

Character to encode as char code

dst + + +ByteBuffer + + + +

ByteBuffer to encode to

offset + + +number + + + +

Offset to write to

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the character cannot be encoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> isByteBuffer(bb) → {boolean}

+ + +
+
+ + +
+

Tests if the specified type is a ByteBuffer or ByteBuffer-like.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bb + + +* + + + +

ByteBuffer to test

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if it is a ByteBuffer or ByteBuffer-like, otherwise false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> wrap(buffer, enc, littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + ByteBuffer's offset to 0 and its length to the wrapped object's byte length.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
buffer + + +ArrayBuffer +| + +!Buffer +| + +!{array: !ArrayBuffer} +| + +!{buffer: !ArrayBuffer} +| + +string + + + + + + + +

Anything that can + be wrapped

enc + + +string +| + +boolean + + + + + + <optional>
+ + + +

String encoding if a string is provided (hex, utf8, binary, defaults to base64)

littleEndian + + +boolean + + + + + + <optional>
+ + + +

true to use little endian multi byte values, defaults to false for big + endian.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified object cannot be wrapped +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

<static> zigZagDecode32(n) → {number}

+ + +
+
+ + +
+

Decodes a zigzag encoded signed 32bit integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +

Unsigned zigzag encoded 32bit integer

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Signed 32bit integer

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> zigZagDecode64(n) → {Long}

+ + +
+
+ + +
+

Decodes a zigzag encoded signed 64bit integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +Long +| + +number + + + +

Unsigned zigzag encoded long or JavaScript number

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If long support is not available +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Signed long

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> zigZagEncode32(n) → {number}

+ + +
+
+ + +
+

Encodes a signed 32bit integer so that it can be effectively used with varint encoding.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +

Signed 32bit integer

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Unsigned zigzag encoded 32bit integer

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

<static> zigZagEncode64(n) → {Long}

+ + +
+
+ + +
+

Encodes a signed 64bit integer so that it can be effectively used with varint encoding.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number +| + +!Long + + + +

Signed long

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Unsigned zigzag encoded long

+
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

append(src, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
src + + +* + + + + + + + +

ByteBuffer or any object that can be wrapped to append

offset + + +number + + + + + + <optional>
+ + + +

Offset to append at. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

BE(bigEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Switches big endian byte order.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
bigEndian + + +boolean + + + + + + <optional>
+ + + +

Defaults to true, otherwise uses little endian

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

capacity() → {number}

+ + +
+
+ + +
+

Gets the capacity of the backing buffer. This is independent from ByteBuffer#length and returns the + size of the entire backing array.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Capacity of the backing array or 0 if destroyed

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

clone() → {ByteBuffer}

+ + +
+
+ + +
+

Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + offsets.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Clone

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

compact() → {ByteBuffer}

+ + +
+
+ + +
+

Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set offset=0 and + length=capacity.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer cannot be compacted +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

copy() → {ByteBuffer}

+ + +
+
+ + +
+

Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Copy

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

destroy() → {ByteBuffer}

+ + +
+
+ + +
+

Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + is usually not required but may be useful in limited memory environments. Most successive operations will + rise an error until ByteBuffer#resize or ByteBuffer#ensureCapacity is called to reinitialize + the backing array.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

ensureCapacity(capacity) → {ByteBuffer}

+ + +
+
+ + +
+

Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + If double the previous capacity is less than the required capacity, the required capacity will be used.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capacity + + +number + + + +

Required capacity

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

flip() → {ByteBuffer}

+ + +
+
+ + +
+

Makes the buffer ready for a new sequence of write or relative read operations. Sets length=offset and + offset=0. Always make sure to flip a buffer when all relative writing operations are complete.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

LE(littleEndian) → {ByteBuffer}

+ + +
+
+ + +
+

Switches little endian byte order.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
littleEndian + + +boolean + + + + + + <optional>
+ + + +

Defaults to true, otherwise uses big endian

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

mark(offset) → {ByteBuffer}

+ + +
+
+ + +
+

Marks an offset to be used with ByteBuffer#reset.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to mark. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+
    +
  • ByteBuffer#reset
  • +
+
+ + + +
+ + + + + +
Throws:
+ + +
+ If the mark cannot be set +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

prepend(src, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
src + + +* + + + + + + + +

ByteBuffer or any object that can be wrapped to prepend

offset + + +number + + + + + + <optional>
+ + + +

Offset to prepend at. Defaults to ByteBuffer#offset.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the specified buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

printDebug(out)

+ + +
+
+ + +
+

Prints debug information about this ByteBuffer's contents.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
out + + +function(string) + + + + + + <optional>
+ + + +

Output function to call, defaults to console.log

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+

readByte(offset) → {number}

+ + +
+
+ + +
+

Reads a byte. This is an alias of ByteBuffer#readInt8.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readCString(offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string followed by a NULL character (Uint8).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readDouble(offset) → {number}

+ + +
+
+ + +
+

Reads a double. This is an alias of ByteBuffer#readFloat64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat(offset) → {number}

+ + +
+
+ + +
+

Reads a float. This is an alias of ByteBuffer#readFloat32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readFloat64(offset) → {number}

+ + +
+
+ + +
+

Reads a 64bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt(offset) → {number}

+ + +
+
+ + +
+

Reads an integer. This is an alias of ByteBuffer#readInt32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt8(offset) → {number}

+ + +
+
+ + +
+

Reads an 8bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt16(offset) → {number}

+ + +
+
+ + +
+

Reads a 16bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readInt64(offset) → {Long}

+ + +
+
+ + +
+

Reads a 64bit integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readJSON(offset, parse) → {*|!{data: *, length: number}}

+ + +
+
+ + +
+

Reads a JSON payload and unserializes it.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

parse + + +function(string) + + + + + + <optional>
+ + + +

Parse implementation to use. Defaults to JSON.parse.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the data cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Data payload if offset is omitted, else the data payload and the + actual number of bytes read

+
+ + + +
+
+ Type +
+
+ +* +| + +!{data: *, length: number} + + +
+
+ + + + +
+ + + +
+

readLong(offset) → {Long}

+ + +
+
+ + +
+

Reads a long. This is an alias of ByteBuffer#readInt64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readLString(offset) → {string|{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string with a prepended number of characters, which is also encoded as an UTF8 character.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readShort(offset) → {number}

+ + +
+
+ + +
+

Reads a short value. This is an alias of ByteBuffer#readInt16.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint8(offset) → {number}

+ + +
+
+ + +
+

Reads an 8bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint16(offset) → {number}

+ + +
+
+ + +
+

Reads a 16bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint32(offset) → {number}

+ + +
+
+ + +
+

Reads a 32bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

readUint64(offset) → {Long}

+ + +
+
+ + +
+

Reads a 64bit unsigned integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If offset is out of bounds +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

readUTF8String(chars, offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads an UTF8 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
chars + + +number + + + + + + + +

Number of characters to read

offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readUTF8StringBytes(length, offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads an UTF8 string with the specified byte length.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
length + + +number + + + + + + + +

Byte length

offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the length did not match or the string cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint(offset) → {number|{value: number, length: number}}

+ + +
+
+ + +
+

Reads a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint32(offset) → {number|!{value: number, length: number}}

+ + +
+
+ + +
+

Reads a 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +!{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readVarint64(offset) → {Long|!{value: Long, length: number}}

+ + +
+
+ + +
+

Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and + the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +Long +| + +!{value: Long, length: number} + + +
+
+ + + + +
+ + + +
+

readVString(offset) → {string|!{string: string, length: number}}

+ + +
+
+ + +
+

Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the string cannot be decoded or if it is not preceeded by a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The string read if offset is omitted, else the string + read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +string +| + +!{string: string, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint(offset) → {number|{value: number, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readZigZagVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint32(offset) → {number|!{value: number, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read + and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +number +| + +!{value: number, length: number} + + +
+
+ + + + +
+ + + +
+

readZigZagVarint64(offset) → {Long|!{value: Long, length: number}}

+ + +
+
+ + +
+

Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
offset + + +number + + + + + + <optional>
+ + + +

Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid varint +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The value read if offset is omitted, else the value read and the actual number of bytes read.

+
+ + + +
+
+ Type +
+
+ +Long +| + +!{value: Long, length: number} + + +
+
+ + + + +
+ + + +
+

remaining() → {number}

+ + +
+
+ + +
+

Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + returns length-offset.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Remaining readable bytes. May be negative if offset>length.

+
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

reset() → {ByteBuffer}

+ + +
+
+ + +
+

Resets the ByteBuffer. If an offset has been marked through ByteBuffer#mark before, the offset will + be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + no marked offset, sets offset=0 and length=0.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+
    +
  • ByteBuffer#mark
  • +
+
+ + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

resize(capacity) → {ByteBuffer}

+ + +
+
+ + +
+

Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capacity + + +number + + + +

New capacity

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

reverse() → {ByteBuffer}

+ + +
+
+ + +
+

Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + offset.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer is already destroyed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

slice(begin, end) → {ByteBuffer}

+ + +
+
+ + +
+

Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + ArrayBuffer (use ByteBuffer#compact or ByteBuffer.wrap instead).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
begin + + +number + + + + + + <optional>
+ + + +

Begin offset, defaults to ByteBuffer#offset.

end + + +number + + + + + + <optional>
+ + + +

End offset, defaults to ByteBuffer#length.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the buffer cannot be sliced +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

toArrayBuffer(forceCopy) → {ArrayBuffer}

+ + +
+
+ + +
+

Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will return a reference to + the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
forceCopy + + +boolean + + + + + + <optional>
+ + + +

true forces the creation of a copy, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Compacted ArrayBuffer or null if already destroyed

+
+ + + +
+
+ Type +
+
+ +ArrayBuffer + + +
+
+ + + + +
+ + + +
+

toBase64() → {string}

+ + +
+
+ + +
+

Returns the base64 encoded representation of the ByteBuffer's contents.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Base 64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toBinary() → {string}

+ + +
+
+ + +
+

Returns the ByteBuffer's contents between offset and length as a binary string. A binary string in this case + is a string composed of 8bit values as characters with a char code between 0 and 255 inclusive.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Binary string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toBuffer() → {Buffer}

+ + +
+
+ + +
+

Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will also copy all data (not + a reference).

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Compacted node Buffer or null if already destroyed

+
+ + + +
+
+ Type +
+
+ +Buffer + + +
+
+ + + + +
+ + + +
+

toColumns(wrap) → {string}

+ + +
+
+ + +
+

Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
wrap + + +number + + + + + + <optional>
+ + + +

Wrap length. Defaults to 16.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toHex(debug) → {string}

+ + +
+
+ + +
+

Returns the ByteBuffer's contents between offset and length as a hex string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
debug + + +boolean + + + + + + <optional>
+ + + +

true to return the entire backing array with marked offsets, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Hex string or debug string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(enc) → {string}

+ + +
+
+ + +
+

Converts the ByteBuffer to a string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
enc + + +string + + + + + + <optional>
+ + + +

Output encoding. Returns an informative string representation by default but also allows + direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + marked offsets.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toUTF8() → {string}

+ + +
+
+ + +
+

Returns the ByteBuffer's contents as an UTF8 encoded string.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

writeByte(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a byte. This is an alias of {ByteBuffer#writeInt8}.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeCString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + characters unless this is actually intended. This is not checked. If you have the option it is recommended + to use ByteBuffer#writeLString or ByteBuffer#writeVString with the corresponding reading + methods instead.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeDouble(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a double. This is an alias of ByteBuffer#writeFloat64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a float. This is an alias of ByteBuffer#writeFloat32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeFloat64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit float.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an integer. This is an alias of ByteBuffer#writeInt32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt8(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an 8bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if + omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt16(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 16bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit signed integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeInt64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeJSON(data, offset, stringify) → {ByteBuffer|number}

+ + +
+
+ + +
+

Serializes and writes a JSON payload.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
data + + +* + + + + + + + +

Data payload to serialize

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

stringify + + +function(*) + + + + + + <optional>
+ + + +

Stringify implementation to use. Defaults to JSON.stringify.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number if bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeLong(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a long. This is an alias of ByteBuffer#writeInt64.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeLString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string with prepended number of characters, which is also encoded as an UTF8 character..

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeShort(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a short value. This is an alias of ByteBuffer#writeInt16.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint8(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes an 8bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint16(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 16bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint32(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 32bit unsigned integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUint64(value, offset) → {ByteBuffer}

+ + +
+
+ + +
+

Writes a 64bit unsigned integer. Requires Long.js.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +!Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

writeUTF8String(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes an UTF8 string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint32(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a 32bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVarint64(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a 64bit base 128 variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number +| + +Long + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeVString(str, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + +

String to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeZigZagVarint32.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint32(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Will use and advance ByteBuffer#offset if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ + + +
+

writeZigZagVarint64(value, offset) → {ByteBuffer|number}

+ + +
+
+ + +
+

Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + +

Value to write

offset + + +number + + + + + + <optional>
+ + + +

Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

this if offset is omitted, else the actual number of bytes written.

+
+ + + +
+
+ Type +
+
+ +ByteBuffer +| + +number + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/docs/scripts/html5.js b/javascript/node_modules/bytebuffer/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/bytebuffer/docs/scripts/prettify/prettify.js b/javascript/node_modules/bytebuffer/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/bytebuffer/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p} deps + * @param {function(...[*])} f + */ +function define(name, deps, f) {}; + +/** + * @param {number} size + * @constructor + * @extends Array + */ +function Buffer(size) {}; + +/** + * @param {*} buf + * @return {boolean} + */ +Buffer.isBuffer = function(buf) {}; + +/** + * @type {Object.} + */ +var console = {}; + +/** + * @param {string} s + */ +console.log = function(s) {}; + +/** + * @type {*} + */ +var module = {}; diff --git a/javascript/node_modules/bytebuffer/jsdoc.json b/javascript/node_modules/bytebuffer/jsdoc.json new file mode 100644 index 0000000..95ab5fc --- /dev/null +++ b/javascript/node_modules/bytebuffer/jsdoc.json @@ -0,0 +1,13 @@ +{ + "tags": { + "allowUnknownTags": true + }, + "source": { + "include": ["ByteBuffer.js"] + }, + "opts": { + "template": "templates/esoccer", + "destination": "docs" + }, + "plugins": ["plugins/markdown"] +} \ No newline at end of file diff --git a/javascript/node_modules/bytebuffer/node_modules/long/.npmignore b/javascript/node_modules/bytebuffer/node_modules/long/.npmignore new file mode 100644 index 0000000..3abe3d4 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/.npmignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/javascript/node_modules/bytebuffer/node_modules/long/.travis.yml b/javascript/node_modules/bytebuffer/node_modules/long/.travis.yml new file mode 100644 index 0000000..3f38c24 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - 0.4 + - 0.6 + - 0.8 + - 0.10 diff --git a/javascript/node_modules/bytebuffer/node_modules/long/LICENSE b/javascript/node_modules/bytebuffer/node_modules/long/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/bytebuffer/node_modules/long/Long.js b/javascript/node_modules/bytebuffer/node_modules/long/Long.js new file mode 100644 index 0000000..339e8ad --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/Long.js @@ -0,0 +1,940 @@ +/* + Copyright 2013 Daniel Wirtz + Copyright 2009 The Closure Library Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license Long.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/Long.js for details + * + * Long.js is based on goog.math.Long from the Closure Library. + * Copyright 2009 The Closure Library Authors. All Rights Reserved. + * Released under the Apache License, Version 2.0 + * see: https://code.google.com/p/closure-library/ for details + */ + +/** + * Defines a Long class for representing a 64-bit two's-complement + * integer value, which faithfully simulates the behavior of a Java "long". This + * implementation is derived from LongLib in GWT. + */ +(function(global) { + + /** + * Constructs a 64-bit two's-complement integer, given its low and high 32-bit + * values as *signed* integers. See the from* functions below for more + * convenient ways of constructing Longs. + * + * The internal representation of a long is the two given signed, 32-bit values. + * We use 32-bit pieces because these are the size of integers on which + * Javascript performs bit-operations. For operations like addition and + * multiplication, we split each number into 16-bit pieces, which can easily be + * multiplied within Javascript's floating-point representation without overflow + * or change in sign. + * + * In the algorithms below, we frequently reduce the negative case to the + * positive case by negating the input(s) and then post-processing the result. + * Note that we must ALWAYS check specially whether those values are MIN_VALUE + * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as + * a positive number, it overflows back into a negative). Not handling this + * case would often result in infinite recursion. + * + * @exports Long + * @class A Long class for representing a 64-bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long. + * @param {number} high The high (signed) 32 bits of the long. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed). + * @constructor + */ + var Long = function(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + * @expose + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + * @expose + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + * @expose + */ + this.unsigned = !!unsigned; + }; + + // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* methods on which they depend. + + // NOTE: The following cache variables are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * A cache of the Long representations of small integer values. + * @type {!Object} + */ + var INT_CACHE = {}; + + /** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + */ + var UINT_CACHE = {}; + + /** + * Returns a Long representing the given (32-bit) integer value. + * @param {number} value The 32-bit integer in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromInt = function(value, unsigned) { + var obj, cachedObj; + if (!unsigned) { + value = value | 0; + if (-128 <= value && value < 128) { + cachedObj = INT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, value < 0 ? -1 : 0, false); + if (-128 <= value && value < 128) { + INT_CACHE[value] = obj; + } + return obj; + } else { + value = value >>> 0; + if (0 <= value && value < 256) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); + if (0 <= value && value < 256) { + UINT_CACHE[value] = obj; + } + return obj; + } + }; + + /** + * Returns a Long representing the given value, provided that it is a finite + * number. Otherwise, zero is returned. + * @param {number} value The number in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromNumber = function(value, unsigned) { + unsigned = !!unsigned; + if (isNaN(value) || !isFinite(value)) { + return Long.ZERO; + } else if (!unsigned && value <= -TWO_PWR_63_DBL) { + return Long.MIN_SIGNED_VALUE; + } else if (unsigned && value <= 0) { + return Long.MIN_UNSIGNED_VALUE; + } else if (!unsigned && value + 1 >= TWO_PWR_63_DBL) { + return Long.MAX_SIGNED_VALUE; + } else if (unsigned && value >= TWO_PWR_64_DBL) { + return Long.MAX_UNSIGNED_VALUE; + } else if (value < 0) { + return Long.fromNumber(-value, false).negate(); + } else { + return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); + } + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @param {number} lowBits The low 32 bits. + * @param {number} highBits The high 32 bits. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromBits = function(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + * Each is assumed to use 28 bits. + * @param {number} part0 The low 28 bits + * @param {number} part1 The middle 28 bits + * @param {number} part2 The high 28 (8) bits + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} + * @expose + */ + Long.from28Bits = function(part0, part1, part2, unsigned) { + // 00000000000000000000000000001111 11111111111111111111111122222222 2222222222222 + // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH + return Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, unsigned); + }; + + /** + * Returns a Long representation of the given string, written using the given + * radix. + * @param {string} str The textual representation of the Long. + * @param {(boolean|number)=} unsigned Whether unsigned or not. Defaults to false (signed). + * @param {number=} radix The radix in which the text is written. + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromString = function(str, unsigned, radix) { + if (str.length == 0) { + throw(new Error('number format error: empty string')); + } + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") { + return Long.ZERO; + } + if (typeof unsigned === 'number') { // For goog.math.Long compatibility + radix = unsigned; + unsigned = false; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + + if (str.charAt(0) == '-') { + return Long.fromString(str.substring(1), unsigned, radix).negate(); + } else if (str.indexOf('-') >= 0) { + throw(new Error('number format error: interior "-" character: ' + str)); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 8)); + + var result = Long.ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i); + var value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = Long.fromNumber(Math.pow(radix, size)); + result = result.multiply(power).add(Long.fromNumber(value)); + } else { + result = result.multiply(radixToPower); + result = result.add(Long.fromNumber(value)); + } + } + return result; + }; + + // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be + // no runtime penalty for these. + + // NOTE: The following constant values are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * @type {number} + */ + var TWO_PWR_16_DBL = 1 << 16; + + /** + * @type {number} + */ + var TWO_PWR_24_DBL = 1 << 24; + + /** + * @type {number} + */ + var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_31_DBL = TWO_PWR_32_DBL / 2; + + /** + * @type {number} + */ + var TWO_PWR_48_DBL = TWO_PWR_32_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + + /** + * @type {number} + */ + var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + + /** + * @type {!Long} + */ + var TWO_PWR_24 = Long.fromInt(1 << 24); + + /** + * @type {!Long} + * @expose + */ + Long.ZERO = Long.fromInt(0); + + /** + * @type {!Long} + * @expose + */ + Long.ONE = Long.fromInt(1); + + /** + * @type {!Long} + * @expose + */ + Long.NEG_ONE = Long.fromInt(-1); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_SIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); + + /** + * Alias of {@link Long.MAX_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MAX_VALUE = Long.MAX_SIGNED_VALUE; + + /** + * @type {!Long} + * @expose + */ + Long.MIN_SIGNED_VALUE = Long.fromBits(0, 0x80000000 | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MIN_UNSIGNED_VALUE = Long.fromBits(0, 0, true); + + /** + * Alias of {@link Long.MIN_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MIN_VALUE = Long.MIN_SIGNED_VALUE; + + /** + * @return {number} The value, assuming it is a 32-bit integer. + * @expose + */ + Long.prototype.toInt = function() { + return this.unsigned ? this.low >>> 0 : this.low; + }; + + /** + * @return {number} The closest floating-point representation to this value. + * @expose + */ + Long.prototype.toNumber = function() { + if (this.unsigned) { + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + } + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); + }; + + /** + * @param {number=} radix The radix in which the text should be written. + * @return {string} The textual representation of this value. + * @override + * @expose + */ + Long.prototype.toString = function(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + if (this.isZero()) { + return '0'; + } + var rem; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = Long.fromNumber(radix); + var div = this.div(radixLong); + rem = div.multiply(radixLong).subtract(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else { + return '-' + this.negate().toString(radix); + } + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 6)); + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower); + var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); + var digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) { + return digits + result; + } else { + while (digits.length < 6) { + digits = '0' + digits; + } + result = '' + digits + result; + } + } + }; + + /** + * @return {number} The high 32 bits as a signed value. + * @expose + */ + Long.prototype.getHighBits = function() { + return this.high; + }; + + /** + * @return {number} The high 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getHighBitsUnsigned = function() { + return this.high >>> 0; + }; + + /** + * @return {number} The low 32 bits as a signed value. + * @expose + */ + Long.prototype.getLowBits = function() { + return this.low; + }; + + /** + * @return {number} The low 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getLowBitsUnsigned = function() { + return this.low >>> 0; + }; + + /** + * @return {number} Returns the number of bits needed to represent the absolute + * value of this Long. + * @expose + */ + Long.prototype.getNumBitsAbs = function() { + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + return 64; + } else { + return this.negate().getNumBitsAbs(); + } + } else { + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) { + if ((val & (1 << bit)) != 0) { + break; + } + } + return this.high != 0 ? bit + 33 : bit + 1; + } + }; + + /** + * @return {boolean} Whether this value is zero. + * @expose + */ + Long.prototype.isZero = function() { + return this.high == 0 && this.low == 0; + }; + + /** + * @return {boolean} Whether this value is negative. + * @expose + */ + Long.prototype.isNegative = function() { + return !this.unsigned && this.high < 0; + }; + + /** + * @return {boolean} Whether this value is odd. + * @expose + */ + Long.prototype.isOdd = function() { + return (this.low & 1) == 1; + }; + + /** + * @return {boolean} Whether this value is even. + */ + Long.prototype.isEven = function() { + return (this.low & 1) == 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long equals the other. + * @expose + */ + Long.prototype.equals = function(other) { + if (this.unsigned != other.unsigned && (this.high >>> 31) != (other.high >>> 31)) return false; + return (this.high == other.high) && (this.low == other.low); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long does not equal the other. + * @expose + */ + Long.prototype.notEquals = function(other) { + return !this.equals(other); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than the other. + * @expose + */ + Long.prototype.lessThan = function(other) { + return this.compare(other) < 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than or equal to the other. + * @expose + */ + Long.prototype.lessThanOrEqual = function(other) { + return this.compare(other) <= 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than the other. + * @expose + */ + Long.prototype.greaterThan = function(other) { + return this.compare(other) > 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than or equal to the other. + * @expose + */ + Long.prototype.greaterThanOrEqual = function(other) { + return this.compare(other) >= 0; + }; + + /** + * Compares this Long with the given one. + * @param {Long} other Long to compare against. + * @return {number} 0 if they are the same, 1 if the this is greater, and -1 + * if the given one is greater. + * @expose + */ + Long.prototype.compare = function(other) { + if (this.equals(other)) { + return 0; + } + var thisNeg = this.isNegative(); + var otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) return -1; + if (!thisNeg && otherNeg) return 1; + if (!this.unsigned) { + // At this point the signs are the same + return this.subtract(other).isNegative() ? -1 : 1; + } else { + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high == this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; + } + }; + + /** + * @return {!Long} The negation of this value. + * @expose + */ + Long.prototype.negate = function() { + if (!this.unsigned && this.equals(Long.MIN_SIGNED_VALUE)) { + return Long.MIN_SIGNED_VALUE; + } + return this.not().add(Long.ONE); + }; + + /** + * Returns the sum of this and the given Long. + * @param {Long} other Long to add to this one. + * @return {!Long} The sum of this and the given Long. + * @expose + */ + Long.prototype.add = function(other) { + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns the difference of this and the given Long. + * @param {Long} other Long to subtract from this. + * @return {!Long} The difference of this and the given Long. + * @expose + */ + Long.prototype.subtract = function(other) { + return this.add(other.negate()); + }; + + /** + * Returns the product of this and the given long. + * @param {Long} other Long to multiply with this. + * @return {!Long} The product of this and the other. + * @expose + */ + Long.prototype.multiply = function(other) { + if (this.isZero()) { + return Long.ZERO; + } else if (other.isZero()) { + return Long.ZERO; + } + + if (this.equals(Long.MIN_VALUE)) { + return other.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } else if (other.equals(Long.MIN_VALUE)) { + return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } + + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().multiply(other.negate()); + } else { + return this.negate().multiply(other).negate(); + } + } else if (other.isNegative()) { + return this.multiply(other.negate()).negate(); + } + // If both longs are small, use float multiplication + if (this.lessThan(TWO_PWR_24) && + other.lessThan(TWO_PWR_24)) { + return Long.fromNumber(this.toNumber() * other.toNumber(), this.unsigned); + } + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns this Long divided by the given one. + * @param {Long} other Long by which to divide. + * @return {!Long} This Long divided by the given one. + * @expose + */ + Long.prototype.div = function(other) { + if (other.isZero()) { + throw(new Error('division by zero')); + } else if (this.isZero()) { + return Long.ZERO; + } + if (this.equals(Long.MIN_SIGNED_VALUE)) { + if (other.equals(Long.ONE) || other.equals(Long.NEG_ONE)) { + return min; // recall that -MIN_VALUE == MIN_VALUE + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ONE; + } else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shiftRight(1); + var approx = halfThis.div(other).shiftLeft(1); + if (approx.equals(Long.ZERO)) { + return other.isNegative() ? Long.ONE : Long.NEG_ONE; + } else { + var rem = this.subtract(other.multiply(approx)); + var result = approx.add(rem.div(other)); + return result; + } + } + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ZERO; + } + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().div(other.negate()); + } else { + return this.negate().div(other).negate(); + } + } else if (other.isNegative()) { + return this.div(other.negate()).negate(); + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + var res = Long.ZERO; + var rem = this; + while (rem.greaterThanOrEqual(other)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2); + var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48); + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + var approxRes = Long.fromNumber(approx, this.unsigned); + var approxRem = approxRes.multiply(other); + while (approxRem.isNegative() || approxRem.greaterThan(rem)) { + approx -= delta; + approxRes = Long.fromNumber(approx, this.unsigned); + approxRem = approxRes.multiply(other); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) { + approxRes = Long.ONE; + } + + res = res.add(approxRes); + rem = rem.subtract(approxRem); + } + return res; + }; + + /** + * Returns this Long modulo the given one. + * @param {Long} other Long by which to mod. + * @return {!Long} This Long modulo the given one. + * @expose + */ + Long.prototype.modulo = function(other) { + return this.subtract(this.div(other).multiply(other)); + }; + + /** + * @return {!Long} The bitwise-NOT of this value. + * @expose + */ + Long.prototype.not = function() { + return Long.fromBits(~this.low, ~this.high, this.unsigned); + }; + + /** + * Returns the bitwise-AND of this Long and the given one. + * @param {Long} other The Long with which to AND. + * @return {!Long} The bitwise-AND of this and the other. + * @expose + */ + Long.prototype.and = function(other) { + return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned); + }; + + /** + * Returns the bitwise-OR of this Long and the given one. + * @param {Long} other The Long with which to OR. + * @return {!Long} The bitwise-OR of this and the other. + * @expose + */ + Long.prototype.or = function(other) { + return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned); + }; + + /** + * Returns the bitwise-XOR of this Long and the given one. + * @param {Long} other The Long with which to XOR. + * @return {!Long} The bitwise-XOR of this and the other. + * @expose + */ + Long.prototype.xor = function(other) { + return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); + }; + + /** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the left by the given amount. + * @expose + */ + Long.prototype.shiftLeft = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var low = this.low; + if (numBits < 32) { + var high = this.high; + return Long.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits)), this.unsigned); + } else { + return Long.fromBits(0, low << (numBits - 32), this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount. + * @expose + */ + Long.prototype.shiftRight = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits, this.unsigned); + } else { + return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1, this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount, with + * the new top bits matching the current sign bit. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount, with + * zeros placed into the new leading bits. + * @expose + */ + Long.prototype.shiftRightUnsigned = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits == 32) { + return Long.fromBits(high, 0, this.unsigned); + } else { + return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned); + } + } + }; + + /** + * @return {!Long} Signed long + * @expose + */ + Long.prototype.toSigned = function() { + var l = this.clone(); + l.unsigned = false; + return l; + }; + + /** + * @return {!Long} Unsigned long + * @expose + */ + Long.prototype.toUnsigned = function() { + var l = this.clone(); + l.unsigned = true; + return l; + }; + + /** + * @return {Long} Cloned instance with the same low/high bits and unsigned flag. + * @expose + */ + Long.prototype.clone = function() { + return new Long(this.low, this.high, this.unsigned); + }; + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = Long; + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("Math/Long", [], function() { return Long; }); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["Long"] = Long; + } + +})(this); diff --git a/javascript/node_modules/bytebuffer/node_modules/long/Long.min.js b/javascript/node_modules/bytebuffer/node_modules/long/Long.min.js new file mode 100644 index 0000000..a1be1ab --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/Long.min.js @@ -0,0 +1,26 @@ +/* + Long.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/Long.js for details + + Long.js is based on goog.math.Long from the Closure Library. + Copyright 2009 The Closure Library Authors. All Rights Reserved. + Released under the Apache License, Version 2.0 + see: https://code.google.com/p/closure-library/ for details +*/ +var p=!1; +(function(r){function b(a,b,d){this.low=a|0;this.high=b|0;this.unsigned=!!d}var s={},t={};b.fromInt=function(a,c){var d;if(c){a>>>=0;if(0<=a&&256>a&&(d=t[a]))return d;d=new b(a,0>(a|0)?-1:0,!0);0<=a&&256>a&&(t[a]=d)}else{a|=0;if(-128<=a&&128>a&&(d=s[a]))return d;d=new b(a,0>a?-1:0,p);-128<=a&&128>a&&(s[a]=d)}return d};b.fromNumber=function(a,c){c=!!c;return isNaN(a)||!isFinite(a)?b.ZERO:!c&&a<=-u?b.MIN_SIGNED_VALUE:c&&0>=a?b.MIN_UNSIGNED_VALUE:!c&&a+1>=u?b.MAX_SIGNED_VALUE:c&&a>=v?b.MAX_UNSIGNED_VALUE:0> +a?b.fromNumber(-a,p).negate():new b(a%l|0,a/l|0,c)};b.fromBits=function(a,c,d){return new b(a,c,d)};b.from28Bits=function(a,c,d,e){return b.fromBits(a|c<<28,c>>>4|d<<24,e)};b.fromString=function(a,c,d){if(0==a.length)throw Error("number format error: empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return b.ZERO;"number"===typeof c&&(d=c,c=p);d=d||10;if(2>d||36f?(f=b.fromNumber(Math.pow(d,f)),e=e.multiply(f).add(b.fromNumber(k))):(e=e.multiply(c),e=e.add(b.fromNumber(k)))}return e};var l=4294967296,v=l*l,u=v/2,w=b.fromInt(16777216);b.ZERO=b.fromInt(0);b.ONE=b.fromInt(1);b.NEG_ONE=b.fromInt(-1);b.MAX_SIGNED_VALUE=b.fromBits(-1,2147483647,p); +b.MAX_UNSIGNED_VALUE=b.fromBits(-1,-1,!0);b.MAX_VALUE=b.MAX_SIGNED_VALUE;b.MIN_SIGNED_VALUE=b.fromBits(0,-2147483648,p);b.MIN_UNSIGNED_VALUE=b.fromBits(0,0,!0);b.MIN_VALUE=b.MIN_SIGNED_VALUE;b.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low};b.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)};b.prototype.toString=function(a){a=a||10;if(2>a||36f.length;)f="0"+f;e=""+f+e}};b.prototype.getHighBits=function(){return this.high};b.prototype.getHighBitsUnsigned=function(){return this.high>>>0}; +b.prototype.getLowBits=function(){return this.low};b.prototype.getLowBitsUnsigned=function(){return this.low>>>0};b.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(b.MIN_SIGNED_VALUE)?64:this.negate().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,c=31;0this.high};b.prototype.isOdd=function(){return 1== +(this.low&1)};b.prototype.equals=function(a){return this.unsigned!=a.unsigned&&this.high>>>31!=a.high>>>31?p:this.high==a.high&&this.low==a.low};b.prototype.notEquals=function(a){return!this.equals(a)};b.prototype.lessThan=function(a){return 0>this.compare(a)};b.prototype.lessThanOrEqual=function(a){return 0>=this.compare(a)};b.prototype.greaterThan=function(a){return 0>>0>this.high>>>0||a.high==this.high&&a.low>>>0>this.low>>>0?-1:1:this.subtract(a).isNegative()?-1:1};b.prototype.negate=function(){return!this.unsigned&&this.equals(b.MIN_SIGNED_VALUE)?b.MIN_SIGNED_VALUE:this.not().add(b.ONE)};b.prototype.add=function(a){var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=a.high>>>16,f=a.high&65535,k=a.low>>>16,q;q=0+((this.low&65535)+(a.low&65535));a=0+(q>>>16);a+=e+k;e=0+ +(a>>>16);e+=d+f;d=0+(e>>>16);d=d+(c+g)&65535;return b.fromBits((a&65535)<<16|q&65535,d<<16|e&65535,this.unsigned)};b.prototype.subtract=function(a){return this.add(a.negate())};b.prototype.multiply=function(a){if(this.isZero()||a.isZero())return b.ZERO;if(this.equals(b.MIN_VALUE))return a.isOdd()?b.MIN_VALUE:b.ZERO;if(a.equals(b.MIN_VALUE))return this.isOdd()?b.MIN_VALUE:b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().multiply(a.negate()):this.negate().multiply(a).negate();if(a.isNegative())return this.multiply(a.negate()).negate(); +if(this.lessThan(w)&&a.lessThan(w))return b.fromNumber(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=this.low&65535,f=a.high>>>16,k=a.high&65535,q=a.low>>>16;a=a.low&65535;var n,h,m,l;l=0+g*a;m=0+(l>>>16);m+=e*a;h=0+(m>>>16);m=(m&65535)+g*q;h+=m>>>16;m&=65535;h+=d*a;n=0+(h>>>16);h=(h&65535)+e*q;n+=h>>>16;h&=65535;h+=g*k;n+=h>>>16;h&=65535;n=n+(c*a+d*q+e*k+g*f)&65535;return b.fromBits(m<<16|l&65535,n<<16|h,this.unsigned)};b.prototype.div=function(a){if(a.isZero())throw Error("division by zero"); +if(this.isZero())return b.ZERO;if(this.equals(b.MIN_SIGNED_VALUE)){if(a.equals(b.ONE)||a.equals(b.NEG_ONE))return min;if(a.equals(b.MIN_VALUE))return b.ONE;var c=this.shiftRight(1).div(a).shiftLeft(1);if(c.equals(b.ZERO))return a.isNegative()?b.ONE:b.NEG_ONE;var d=this.subtract(a.multiply(c));return c.add(d.div(a))}if(a.equals(b.MIN_VALUE))return b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().div(a.negate()):this.negate().div(a).negate();if(a.isNegative())return this.div(a.negate()).negate(); +for(var e=b.ZERO,d=this;d.greaterThanOrEqual(a);){for(var c=Math.max(1,Math.floor(d.toNumber()/a.toNumber())),g=Math.ceil(Math.log(c)/Math.LN2),g=48>=g?1:Math.pow(2,g-48),f=b.fromNumber(c,this.unsigned),k=f.multiply(a);k.isNegative()||k.greaterThan(d);)c-=g,f=b.fromNumber(c,this.unsigned),k=f.multiply(a);f.isZero()&&(f=b.ONE);e=e.add(f);d=d.subtract(k)}return e};b.prototype.modulo=function(a){return this.subtract(this.div(a).multiply(a))};b.prototype.not=function(){return b.fromBits(~this.low,~this.high, +this.unsigned)};b.prototype.and=function(a){return b.fromBits(this.low&a.low,this.high&a.high,this.unsigned)};b.prototype.or=function(a){return b.fromBits(this.low|a.low,this.high|a.high,this.unsigned)};b.prototype.xor=function(a){return b.fromBits(this.low^a.low,this.high^a.high,this.unsigned)};b.prototype.shiftLeft=function(a){a&=63;if(0==a)return this;var c=this.low;return 32>a?b.fromBits(c<>>32-a,this.unsigned):b.fromBits(0,c<a?b.fromBits(this.low>>>a|c<<32-a,c>>a,this.unsigned):b.fromBits(c>>a-32,0<=c?0:-1,this.unsigned)};b.prototype.shiftRightUnsigned=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>>a,this.unsigned):32==a?b.fromBits(c,0,this.unsigned):b.fromBits(c>>>a-32,0,this.unsigned)};b.prototype.toSigned=function(){var a=this.clone();a.unsigned=p;return a};b.prototype.toUnsigned=function(){var a=this.clone();a.unsigned= +!0;return a};b.prototype.clone=function(){return new b(this.low,this.high,this.unsigned)};"undefined"!=typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("Math/Long",[],function(){return b}):(r.dcodeIO||(r.dcodeIO={}),r.dcodeIO.Long=b)})(this); diff --git a/javascript/node_modules/bytebuffer/node_modules/long/NOTICE b/javascript/node_modules/bytebuffer/node_modules/long/NOTICE new file mode 100644 index 0000000..7563caf --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) Long.js by Daniel 'dcode' Wirtz. +See: https://github.com/dcodeIO/Long.js for details diff --git a/javascript/node_modules/bytebuffer/node_modules/long/README.md b/javascript/node_modules/bytebuffer/node_modules/long/README.md new file mode 100644 index 0000000..2e48bd8 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/README.md @@ -0,0 +1,75 @@ +![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png) +======= +A Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/) +for stand-alone use and extended with unsigned support. + +Why? +---- +As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value +of 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit +numbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations +on the full 64bits. This is where Long.js comes into play. + +Features +-------- +* [CommonJS](http://www.commonjs.org/) compatible +* [RequireJS](http://requirejs.org/)/AMD compatible +* Shim compatible (include the script, then use var Long = dcodeIO.Long;) +* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* API-compatible to the Closure Library implementation +* Zero production dependencies +* Small footprint + +Usage +----- + +#### node.js / CommonJS #### + +Install: `npm install long` + +```javascript +var Long = require("long"); +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +console.log(longVal.toString()); +... +``` + +#### RequireJS / AMD #### + +````javascript +require.config({ + "paths": { + "Math/Long": "/path/to/Long.js" + } +}); +require(["Math/Long"], function(Long) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + console.log(longVal.toString()); +}); +```` + +### Browser / shim #### + +```html + +``` + +```javascript +var Long = dcodeIO.Long; +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +alert(longVal.toString()); +``` + +Documentation +------------- +* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html) + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master) + +License +------- +Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/javascript/node_modules/bytebuffer/node_modules/long/bower.json b/javascript/node_modules/bytebuffer/node_modules/long/bower.json new file mode 100644 index 0000000..5627a2d --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/bower.json @@ -0,0 +1,9 @@ +{ + "name": "long", + "version": "1.1.2", + "author": "Daniel Wirtz ", + "description": "Long.js: A Long class for representing a 64-bit two's-complement integer value derived from the Closure Library extended with unsigned support.", + "main": "Long.js", + "keywords": ["math"], + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/bytebuffer/node_modules/long/docs/Long.html b/javascript/node_modules/bytebuffer/node_modules/long/docs/Long.html new file mode 100644 index 0000000..effa27b --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/docs/Long.html @@ -0,0 +1,5380 @@ + + + + + Class: Long + + + + + + + + + + +
+ +

Class: Long

+ + + + + +
+ +
+

+ Long +

+ +
A Long class for representing a 64-bit two's-complement integer value.
+ +
+ +
+
+ + + + +
+

new Long(low, high, unsigned)

+ + +
+
+ + +
+ Constructs a 64-bit two's-complement integer, given its low and high 32-bit +values as *signed* integers. See the from* functions below for more +convenient ways of constructing Longs. + +The internal representation of a long is the two given signed, 32-bit values. +We use 32-bit pieces because these are the size of integers on which +Javascript performs bit-operations. For operations like addition and +multiplication, we split each number into 16-bit pieces, which can easily be +multiplied within Javascript's floating-point representation without overflow +or change in sign. + +In the algorithms below, we frequently reduce the negative case to the +positive case by negating the input(s) and then post-processing the result. +Note that we must ALWAYS check specially whether those values are MIN_VALUE +(-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +a positive number, it overflows back into a negative). Not handling this +case would often result in infinite recursion. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
low + + +number + + + + + + + + The low (signed) 32 bits of the long.
high + + +number + + + + + + + + The high (signed) 32 bits of the long.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to `false` (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static> MAX_SIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MAX_UNSIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MAX_VALUE :Long

+ + +
+
+ +
+ Alias of Long.MAX_SIGNED_VALUE for goog.math.Long compatibility. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_SIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_UNSIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_VALUE :Long

+ + +
+
+ +
+ Alias of Long.MIN_SIGNED_VALUE for goog.math.Long compatibility. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> NEG_ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ZERO :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

high :number

+ + +
+
+ +
+ The high 32 bits as a signed value. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

low :number

+ + +
+
+ +
+ The low 32 bits as a signed value. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

unsigned :boolean

+ + +
+
+ +
+ Whether unsigned or not. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> from28Bits(part0, part1, part2, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + Each is assumed to use 28 bits. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
part0 + + +number + + + + + + + + The low 28 bits
part1 + + +number + + + + + + + + The middle 28 bits
part2 + + +number + + + + + + + + The high 28 (8) bits
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromBits(lowBits, highBits, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + assumed to use 32 bits. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
lowBits + + +number + + + + + + + + The low 32 bits.
highBits + + +number + + + + + + + + The high 32 bits.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromInt(value, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the given (32-bit) integer value. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + + The 32-bit integer in question.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromNumber(value, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the given value, provided that it is a finite +number. Otherwise, zero is returned. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + + The number in question.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromString(str, unsigned, radix) → {Long}

+ + +
+
+ + +
+ Returns a Long representation of the given string, written using the given +radix. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + + The textual representation of the Long.
unsigned + + +boolean +| + +number + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
radix + + +number + + + + + + <optional>
+ + + +
The radix in which the text is written.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

add(other) → {Long}

+ + +
+
+ + +
+ Returns the sum of this and the given Long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to add to this one.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The sum of this and the given Long. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

and(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-AND of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to AND.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-AND of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

clone() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Cloned instance with the same low/high bits and unsigned flag. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

compare(other) → {number}

+ + +
+
+ + +
+ Compares this Long with the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ 0 if they are the same, 1 if the this is greater, and -1 + if the given one is greater. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

div(other) → {Long}

+ + +
+
+ + +
+ Returns this Long divided by the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long by which to divide.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This Long divided by the given one. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

equals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long equals the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

getHighBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The high 32 bits as a signed value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getHighBitsUnsigned() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The high 32 bits as an unsigned value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The low 32 bits as a signed value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBitsUnsigned() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The low 32 bits as an unsigned value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getNumBitsAbs() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Returns the number of bits needed to represent the absolute + value of this Long. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

greaterThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is greater than the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

greaterThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is greater than or equal to the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isEven() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is even. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isNegative() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is negative. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isOdd() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is odd. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isZero() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is zero. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is less than the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is less than or equal to the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

modulo(other) → {Long}

+ + +
+
+ + +
+ Returns this Long modulo the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long by which to mod.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This Long modulo the given one. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

multiply(other) → {Long}

+ + +
+
+ + +
+ Returns the product of this and the given long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to multiply with this.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The product of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

negate() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The negation of this value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

not() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-NOT of this value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

notEquals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long does not equal the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

or(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-OR of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to OR.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-OR of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftLeft(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the left by the given amount. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the left by the given amount. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRight(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the right by the given amount. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the right by the given amount. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRightUnsigned(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the right by the given amount, with +the new top bits matching the current sign bit. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the right by the given amount, with + zeros placed into the new leading bits. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

subtract(other) → {Long}

+ + +
+
+ + +
+ Returns the difference of this and the given Long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to subtract from this.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The difference of this and the given Long. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

toInt() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The value, assuming it is a 32-bit integer. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toNumber() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The closest floating-point representation to this value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toSigned() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Signed long +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

toString(radix) → {string}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
radix + + +number + + + + + + <optional>
+ + + +
The radix in which the text should be written.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The textual representation of this value. +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toUnsigned() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Unsigned long +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

xor(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-XOR of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to XOR.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-XOR of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/node_modules/long/docs/index.html b/javascript/node_modules/bytebuffer/node_modules/long/docs/index.html new file mode 100644 index 0000000..49ca749 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
+ +

Index

+ + + + + + + +

+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js b/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js b/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1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V1p77~Vwe`Cct&|{)@wfo{SodKSyyP-Ut^WxnF29yquDF5H-`PY)$N6Ly3S^!*rbI4bJpzCl9lB0Q=Wybl z%NL&Z`TYmP(|9mOC)*MNUS{<(3a=2DXL7Gq_6rgAdSl%f_1PHov7Y$uqw1v~mWScR zYw;3x=IBg5E=)RW*r&L_{qmd$9QS#(38ElOQ!-hk8Krmcy-DV>FH&O7dTP6V11(I6 zk5Cih=QlTpusl0N>PWTnNsJL4^x+f+7A!aA~F7doZ9lSZ~(SjB%TDOYvvGU4;EfMY;Z=WCbb6EO)l+G?_wpOZG`+24O z2=RNb$uD#qu!?<$$bAxGOa|VdgQuqpp|waoLub#%W*oxDCuG}Uc`L(m&D$qLtlZ+@ zJQBKLP3-zZZky}qrj^(c9i61ofB#D68#`#Wy`54QDCs(Nj7s@ADp3m+N^P86J8Bpz z-1Q-JJhS;$NTKRhhxb|3J})A%PQt!w?3Zvg8>3uUQiPiKpO=IEn7pn0=#UG7kNGJo zm)yJ-p?Ah`NzY=B-`Oc%_Tw=dP(xaXxfgMhV6kke4Cs`bd>e*>ctKMx0m8m9IV67 ziRI^C+$VW7zp&@@jD)b)1>A>qB9`oVd8y&E9uU5i&MvjsE8bnj*)sce5)~m{e?3|l zIOdQ8%h^6hQnfK^u641#vE8PLU((7JDZ4`1W$Fr9Nrt+Pm2y$Z zcvpS?b@l%1>atJA!ak{t^i}xlq_kX$V(*^Xdk^X~1KR zI9Sxt0SMi>3r|MeAt9{STg2~_aFv%>d3{*Wa`FBewn79#2OxBSB#h;95BoB<=0.6" + }, + "scripts": { + "make": "npm run-script compile && npm test && npm run-script jsdoc", + "compile": "ccjs Long.js --compilation_level=ADVANCED_OPTIMIZATIONS > Long.min.js", + "test": "node node_modules/testjs/bin/testjs tests/suite.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png)\n=======\nA Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/)\nfor stand-alone use and extended with unsigned support.\n\nWhy?\n----\nAs of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value\nof 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit\nnumbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations\non the full 64bits. This is where Long.js comes into play.\n\nFeatures\n--------\n* [CommonJS](http://www.commonjs.org/) compatible\n* [RequireJS](http://requirejs.org/)/AMD compatible\n* Shim compatible (include the script, then use var Long = dcodeIO.Long;)\n* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long)\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\n* API-compatible to the Closure Library implementation\n* Zero production dependencies\n* Small footprint\n\nUsage\n-----\n\n#### node.js / CommonJS ####\n\nInstall: `npm install long`\n\n```javascript\nvar Long = require(\"long\");\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nconsole.log(longVal.toString());\n...\n```\n\n#### RequireJS / AMD ####\n\n````javascript\nrequire.config({\n \"paths\": {\n \"Math/Long\": \"/path/to/Long.js\"\n }\n});\nrequire([\"Math/Long\"], function(Long) {\n var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\n console.log(longVal.toString());\n});\n````\n\n### Browser / shim ####\n\n```html\n\n```\n\n```javascript\nvar Long = dcodeIO.Long;\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nalert(longVal.toString());\n```\n\nDocumentation\n-------------\n* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html)\n\nDownloads\n---------\n* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip)\n* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master)\n\nLicense\n-------\nApache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/dcodeIO/Long.js/issues" + }, + "_id": "long@1.1.2", + "_from": "long@latest" +} diff --git a/javascript/node_modules/bytebuffer/node_modules/long/tests/suite.js b/javascript/node_modules/bytebuffer/node_modules/long/tests/suite.js new file mode 100644 index 0000000..e71a512 --- /dev/null +++ b/javascript/node_modules/bytebuffer/node_modules/long/tests/suite.js @@ -0,0 +1,156 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * Long.js Pretty Simple Test Suite. + */ +var Long = require(__dirname+"/../Long.min.js"); + +var suite = { + + "basic": function(test) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + test.equal(longVal.toNumber(), 9223372036854775807); + test.equal(longVal.toString(), "9223372036854775807"); + test.done(); + }, + + // Let's assume signed goog.math.Long works as expected because the people at Google are pretty smart. + + // So let's focus on my probably not-so-smart extensions: + + "from28Bits": function(test) { + var val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF); + test.equal(val.toString(), "-1"); + test.done(); + }, + + "unsigned": { + + "min/max": function(test) { + test.equal(Long.MIN_SIGNED_VALUE.toString(), "-9223372036854775808"); + test.equal(Long.MAX_SIGNED_VALUE.toString(), "9223372036854775807"); + test.equal(Long.MIN_UNSIGNED_VALUE.toString(), "0"); + test.equal(Long.MAX_UNSIGNED_VALUE.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_negint": function(test) { + var longVal = Long.fromInt(-1, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_highlow": function(test) { + var longVal = new Long(0xFFFFFFFF, 0xFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_number": function(test) { + var longVal = Long.fromNumber(0xFFFFFFFFFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "toSigned/Unsigned": function(test) { + var longVal = Long.fromNumber(-1, false); + test.equal(longVal.toNumber(), -1); + longVal = longVal.toUnsigned(); + test.equal(longVal.toNumber(), 0xFFFFFFFFFFFFFFFF); + longVal = longVal.toSigned(); + test.equal(longVal.toNumber(), -1); + test.done(); + }, + + "max_unsigned_sub_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_SIGNED_VALUE).subtract(Long.ONE); + test.equal(longVal.toNumber(), Long.MAX_SIGNED_VALUE); + test.equal(longVal.toString(), Long.MAX_SIGNED_VALUE.toString()); + test.done(); + }, + + "max_sub_max": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_UNSIGNED_VALUE); + test.equal(longVal, 0); + test.equal(longVal.low, 0); + test.equal(longVal.high, 0); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 0); + test.equal(longVal.toString(), "0"); + test.done(); + }, + + "zero_sub_signed": function(test) { + var longVal = Long.fromInt(0, true).add(Long.fromInt(-1, false)); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "max_unsigned_div_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.MAX_SIGNED_VALUE); + test.equal(longVal.toNumber(), 2); + test.equal(longVal.toString(), "2"); + test.done(); + }, + + "max_unsigned_div_neg_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.fromInt(-2)); + test.equal(longVal.toNumber(), -Long.MAX_SIGNED_VALUE); + test.done(); + } + }, + + // FIXME: There is no support for NaN or +/-Infinity + // "NaN": function(test) { + // test.ok(isNan(Long.fromNumber(NaN).toNumber()); + // test.strictEqual(Long.fromNumber(+Infinity).toNumber(), +Infinity); + // test.strictEqual(Long.fromNumber(-Infinity).toNumber(), -Infinity); + // test.done(); + // } + // One option could be to store NaN, Infinity etc. in high and set low to 0, while making sure to convert it in a + // proper way as soon as any math is called upon it. This might be as simple as that each of these values always + // "infects" other values, thus remaining untouched respectively changing the base long to its value. + // + // To clarify that, it all becomes zero atm, which usually is good enough but not perfect: + "NaN": function(test) { + test.strictEqual(Long.fromNumber(NaN), Long.ZERO); + test.strictEqual(Long.fromNumber(+Infinity), Long.ZERO); + test.strictEqual(Long.fromNumber(-Infinity), Long.ZERO); + test.strictEqual(Long.fromString(NaN+""), Long.ZERO); + test.strictEqual(Long.fromString(+Infinity+""), Long.ZERO); + test.strictEqual(Long.fromString(-Infinity+""), Long.ZERO); + test.done(); + } +}; + +module.exports = suite; diff --git a/javascript/node_modules/bytebuffer/package.json b/javascript/node_modules/bytebuffer/package.json new file mode 100644 index 0000000..334cb19 --- /dev/null +++ b/javascript/node_modules/bytebuffer/package.json @@ -0,0 +1,53 @@ +{ + "name": "bytebuffer", + "version": "2.3.1", + "author": { + "name": "Daniel Wirtz", + "email": "dcode@dcode.io" + }, + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "repository": { + "type": "git", + "url": "https://github.com/dcodeIO/ByteBuffer.js.git" + }, + "bugs": { + "url": "https://github.com/dcodeIO/ByteBuffer.js/issues" + }, + "keywords": [ + "net", + "array", + "buffer", + "arraybuffer", + "typed array", + "bytebuffer", + "json", + "websocket", + "webrtc" + ], + "dependencies": { + "long": "latest" + }, + "devDependencies": { + "testjs": "latest", + "preprocessor": "latest", + "closurecompiler": "latest" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=0.8" + }, + "scripts": { + "prepublish": "npm test", + "test": "node node_modules/testjs/bin/testjs tests/suite.js", + "make": "npm run-script build && npm run-script compile && npm run-script noexpose && npm test && npm run-script jsdoc", + "build": "node build.js", + "compile": "ccjs ByteBuffer.js --create_source_map=ByteBuffer.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --externs=externs/Long.js > ByteBuffer.min.js", + "noexpose": "cat ByteBuffer.js | grep -v @expose > ByteBuffer.noexpose.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![ByteBuffer.js - A full-featured ByteBuffer implementation in JavaScript](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png)\r\n======================================\r\nProvides a full-featured ByteBuffer implementation using typed arrays. It's one of the core components driving\r\n[ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js) and the [PSON](https://github.com/dcodeIO/PSON) reference\r\nimplementation.\r\n\r\n*Note:* The API behind #toHex and #toString has changed with ByteBuffer 2, which is a generally revised release, in\r\nfavor of making this more intuitive.\r\n\r\nWhat can it do?\r\n---------------\r\n* Mimics Java ByteBuffers as close as reasonable while using typed array terms\r\n* Signed and unsigned integers (8, 16, 32, 64 bit through [Long.js](https://github.com/dcodeIO/Long.js)) with endianness support\r\n* 32 and 64 bit floats\r\n* Varints as known from protobuf including zig-zag encoding\r\n* Includes an UTF8 and Base64 en-/decoder\r\n* C-strings, V(arint-prefixed)-strings and UTF8 L(ength-prefixed)-strings \r\n* Rich string toolset (to hex, base64, binary, utf8, debug, columns)\r\n* Relative and absolute zero-copy operations\r\n* Manual and automatic resizing (efficiently doubles capacity)\r\n* Chaining of all operations that do not return a specific value\r\n* Slicing, appending, prepending, reversing, flip, mark, reset, etc.\r\n\r\nAnd much more...\r\n\r\nFeatures\r\n--------\r\n* [CommonJS](http://www.commonjs.org/) compatible\r\n* [RequireJS](http://requirejs.org/)/AMD compatible\r\n* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/bytebuffer)\r\n* Browser compatible\r\n* [Closure Compiler](https://developers.google.com/closure/compiler/) ADVANCED_OPTIMIZATIONS compatible (fully annotated,\r\n `ByteBuffer.min.js` has been compiled this way, `ByteBuffer.min.map` is the source map)\r\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\r\n* Well tested through [nodeunit](https://github.com/caolan/nodeunit)\r\n* Zero production dependencies (Long.js is optional)\r\n* Small footprint\r\n\r\nUsage\r\n-----\r\n### Node.js / CommonJS ###\r\n* Install: `npm install bytebuffer`\r\n\r\n```javascript\r\nvar ByteBuffer = require(\"bytebuffer\");\r\nvar bb = new ByteBuffer();\r\nbb.writeLString(\"Hello world!\").flip();\r\nconsole.log(bb.readLString()+\" from ByteBuffer.js\");\r\n```\r\n\r\n### Browser ###\r\n\r\nOptionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long\r\nsupport, you can skip the Long.js include.\r\n\r\n```html\r\n\r\n\r\n```\r\n\r\n```javascript\r\nvar ByteBuffer = dcodeIO.ByteBuffer;\r\nvar bb = new ByteBuffer();\r\nbb.writeLString(\"Hello world!\").flip();\r\nalert(bb.readLString()+\" from ByteBuffer.js\");\r\n```\r\n\r\n### Require.js / AMD ###\r\n\r\nOptionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long\r\nsupport, you can skip the Long.js config. [Require.js](http://requirejs.org/) example:\r\n\r\n```javascript\r\nrequire.config({\r\n \"paths\": {\r\n \"Long\": \"/path/to/Long.js\"\r\n \"ByteBuffer\": \"/path/to/ByteBuffer.js\"\r\n }\r\n});\r\nrequire([\"ByteBuffer\"], function(ByteBuffer) {\r\n var bb = new ByteBuffer();\r\n bb.writeLString(\"Hello world!\");\r\n bb.flip();\r\n alert(bb.readLString()+\" from ByteBuffer.js\");\r\n});\r\n```\r\n\r\nOn long (int64) support\r\n-----------------------\r\nAs of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value\r\nof 2^53. Beyond that, behaviour might be unexpected. However, real long support requires the full 64 bits\r\nwith the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support\r\nin ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two\r\n32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth.\r\nOn node, long support is available by default through the [long](https://npmjs.org/package/long) dependency.\r\n\r\nDownloads\r\n---------\r\n* [ZIP-Archive](https://github.com/dcodeIO/ByteBuffer.js/archive/master.zip)\r\n* [Tarball](https://github.com/dcodeIO/ByteBuffer.js/tarball/master)\r\n\r\nDocumentation\r\n-------------\r\n* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/ByteBuffer.js/master/docs/ByteBuffer.html)\r\n\r\nTests (& Examples) [![Build Status](https://travis-ci.org/dcodeIO/ByteBuffer.js.png?branch=master)](https://travis-ci.org/dcodeIO/ByteBuffer.js)\r\n------------------\r\n* [View source](https://github.com/dcodeIO/ByteBuffer.js/blob/master/tests/suite.js)\r\n* [View report](https://travis-ci.org/dcodeIO/ByteBuffer.js)\r\n\r\nSupport for IE<10, FF<15, Chrome<9 etc.\r\n---------------------------------------\r\n* Requires working ArrayBuffer & DataView implementations (i.e. use a [polyfill](https://github.com/inexorabletash/polyfill#typed-arrays-polyfill))\r\n\r\nContributors\r\n------------\r\n[Dretch](https://github.com/Dretch) (IE8 compatibility)\r\n\r\nLicense\r\n-------\r\nApache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html\r\n", + "readmeFilename": "README.md", + "_id": "bytebuffer@2.3.1", + "_from": "bytebuffer@" +} diff --git a/javascript/node_modules/bytebuffer/src/ByteBuffer.js b/javascript/node_modules/bytebuffer/src/ByteBuffer.js new file mode 100644 index 0000000..cba25b6 --- /dev/null +++ b/javascript/node_modules/bytebuffer/src/ByteBuffer.js @@ -0,0 +1,2320 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + * @expose + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + * @expose + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + * @expose + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + * @expose + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + * @expose + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + * @expose + */ + ByteBuffer.VERSION = // #put '"'+VERSION+'";' + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + * @expose + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + * @expose + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + * @expose + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @expose + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + * @expose + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + * @expose + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + * @expose + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + * @expose + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + * @expose + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + * @expose + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + * @expose + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + * @expose + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + * @expose + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @expose + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + * @expose + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + * @expose + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + * @expose + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + * @expose + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + * @expose + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + * @expose + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + * @expose + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + * @expose + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + * @expose + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + * @expose + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + * @expose + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + * @expose + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + * @expose + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + * @expose + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + * @expose + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + * @expose + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + * @expose + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + * @expose + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + * @expose + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/bytebuffer/src/bower.json b/javascript/node_modules/bytebuffer/src/bower.json new file mode 100644 index 0000000..ed384f1 --- /dev/null +++ b/javascript/node_modules/bytebuffer/src/bower.json @@ -0,0 +1,12 @@ +{ + "name": "bytebuffer", + "version": // #put '"'+VERSION+'",' + "author": "Daniel Wirtz ", + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"], + "dependencies": { + "long": "latest" + }, + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/bytebuffer/tests/suite.js b/javascript/node_modules/bytebuffer/tests/suite.js new file mode 100644 index 0000000..36c4ec9 --- /dev/null +++ b/javascript/node_modules/bytebuffer/tests/suite.js @@ -0,0 +1,929 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ByteBuffer.js Test Suite. + * @author Daniel Wirtz + */ + +/** + * File to use. + * @type {string} + */ +var FILE = "ByteBuffer.min.js"; + +/** + * ByteBuffer. + * @type {ByteBuffer} + */ +var ByteBuffer = require(__dirname+"/../"+FILE); + +/** + * Long. + * @type {Long} + */ +var Long = ByteBuffer.Long; + +/** + * Constructs a new Sandbox for module loaders and shim testing. + * @param {Object.} properties Additional properties to set + * @constructor + */ +var Sandbox = function(properties) { + this.Int8Array = function() {}; + this.Uint8Array = function() {}; + this.Int16Array = function() {}; + this.Uint16Array = function() {}; + this.Int32Array = function() {}; + this.Uint32Array = function() {}; + this.Float32Array = function() {}; + this.Float64Array = function() {}; + for (var i in properties) { + this[i] = properties[i]; + } + this.console = { + log: function(s) { + console.log(s); + } + }; +}; + +/** + * Test suite. + * @type {Object.} + */ +var suite = { + + "init": function(test) { + test.ok(typeof ByteBuffer == "function"); + test.ok(typeof ByteBuffer.encodeUTF8Char == "function"); + test.done(); + }, + + "construct/allocate": function(test) { + var bb = new ByteBuffer(); + test.equal(bb.array.byteLength, ByteBuffer.DEFAULT_CAPACITY); + bb = ByteBuffer.allocate(); + test.equal(bb.array.byteLength, ByteBuffer.DEFAULT_CAPACITY); + test.done(); + }, + + "wrap(ArrayBuffer)": function(test) { + var buf = new ArrayBuffer(1); + var bb = ByteBuffer.wrap(buf); + test.strictEqual(bb.array, buf); + test.equal(bb.offset, 0); + test.equal(bb.length, 1); + test.done(); + }, + + "wrap(Uint8Array)": function(test) { + var buf = new Uint8Array(1); + var bb = ByteBuffer.wrap(buf); + test.strictEqual(bb.array, buf.buffer); + test.done(); + }, + + "wrap(ByteBuffer)": function(test) { // clones + var bb2 = new ByteBuffer(4).writeInt32(0x12345678).flip(); + bb2.offset = 1; + var bb = ByteBuffer.wrap(bb2); + test.strictEqual(bb2.toString("debug"), bb.toString("debug")); + test.done(); + }, + + "wrap(String)": function(test) { + var bb = ByteBuffer.wrap("test"); + test.equal(bb.offset, 0); + test.equal(bb.length, 4); + test.equal(bb.readUTF8String(4), "test"); + + bb = ByteBuffer.wrap("6162", "hex"); + test.equal(bb.toHex(true), "<61 62>"); + + bb = ByteBuffer.wrap("YWI=", "base64"); + test.equal(bb.toHex(true), "<61 62>"); + + test.done(); + }, + + "wrap(Buffer)": function(test) { + var b = new Buffer("abc", "utf8"); + var bb = ByteBuffer.wrap(b); + test.equal(bb.toString("debug"), "<61 62 63>"); + test.done(); + }, + + "resize": function(test) { + var bb = new ByteBuffer(1); + bb.resize(2); + test.equal(bb.array.byteLength, 2); + test.equal(bb.toString("debug"), "|00 00 "); + test.done(); + }, + + "slice": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint8(0x12).writeUint8(0x34).writeUint8(0x56); + var bb2 = bb.slice(1,2); + test.strictEqual(bb.array, bb2.array); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + test.equal(bb2.offset, 1); + test.equal(bb2.length, 2); + test.done(); + }, + + "ensureCapacity": function(test) { + var bb = new ByteBuffer(5); + test.equal(bb.array.byteLength, 5); + bb.ensureCapacity(6); + test.equal(bb.array.byteLength, 10); + bb.ensureCapacity(21); + test.equal(bb.array.byteLength, 21); + test.done(); + }, + + "flip": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + test.equal(bb.offset, 4); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.offset, 0); + test.equal(bb.length, 4); + test.done(); + }, + + "reset": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.reset(); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.done(); + }, + + "mark": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint16(0x1234); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.mark(); + test.equal(bb.markedOffset, 2); + bb.writeUint16(0x5678); + test.equal(bb.offset, 4); + test.equal(bb.markedOffset, 2); + bb.reset(); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.reset(); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.mark(2); + test.equal(bb.markedOffset, 2); + test.done(); + }, + + "clone": function(test) { + var bb = new ByteBuffer(1); + var bb2 = bb.clone(); + test.strictEqual(bb.array, bb2.array); + test.equal(bb.offset, bb2.offset); + test.equal(bb.length, bb2.length); + test.notStrictEqual(bb, bb2); + test.done(); + }, + + "copy": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0x12); + var bb2 = bb.copy(); + test.notStrictEqual(bb, bb2); + test.notStrictEqual(bb.array, bb2.array); + test.equal(bb2.offset, bb.offset); + test.equal(bb2.length, bb.length); + test.done(); + }, + + "compact": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint8(0x12); + var prevArray = bb.array; + bb.compact(); + test.notStrictEqual(bb.array, prevArray); + test.equal(bb.array.byteLength, 1); + test.equal(bb.offset, 0); + test.equal(bb.length, 1); + test.done(); + }, + + "compactEmpty": function(test) { + var bb = new ByteBuffer(2); + bb.compact(); + test.strictEqual(bb.offset, 0); + test.strictEqual(bb.length, 0); + test.strictEqual(bb.view, null); // Special case + test.strictEqual(bb.array.byteLength, 0); + bb.writeInt32(0xFFFFFFFF); + bb.flip(); + test.strictEqual(bb.offset, 0); + test.strictEqual(bb.length, 4); + test.notStrictEqual(bb.view, null); + test.strictEqual(bb.array.byteLength, 4); // Cannot double 0, so it takes 32bits + test.done(); + }, + + "destroy": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0x12); + bb.destroy(); + test.strictEqual(bb.array, null); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.equal(bb.toString("debug"), "DESTROYED"); + test.done(); + }, + + "reverse": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.flip(); + bb.reverse(); + test.equal(bb.toString("debug"), "<78 56 34 12>"); + test.done(); + }, + + "append": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0x1234); + var bb2 = new ByteBuffer(2); + bb2.writeUint16(0x5678); + bb2.flip(); + bb.append(bb2); + test.equal(bb.toString("debug"), ">12 34 56 78<"); + bb.append(bb2, 1); + test.equal(bb.toString("debug"), ">12 56 78 78<"); + test.done(); + }, + + "prepend": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0x1234); + bb.flip(); + var bb2 = new ByteBuffer(2); + bb2.writeUint16(0x5678); + bb2.flip(); + bb.prepend(bb2); + test.equal(bb.toString("debug"), "<56 78 12 34>"); + bb.offset = 4; + bb.prepend(bb2, 3); + test.equal(bb.toString("debug"), " 56 56 78 34|") + test.done(); + }, + + "write/readInt8": function(test) { + var bb = new ByteBuffer(1); + bb.writeInt8(0xFF); + bb.flip(); + test.equal(-1, bb.readInt8()); + test.done(); + }, + + "write/readByte": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt8, bb.readByte); + test.strictEqual(bb.writeInt8, bb.writeByte); + test.done(); + }, + + "write/readUint8": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0xFF); + bb.flip(); + test.equal(0xFF, bb.readUint8()); + test.done(); + }, + + "write/readInt16": function(test) { + var bb = new ByteBuffer(2); + bb.writeInt16(0xFFFF); + bb.flip(); + test.equal(-1, bb.readInt16()); + test.done(); + }, + + "write/readShort": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt16, bb.readShort); + test.strictEqual(bb.writeInt16, bb.writeShort); + test.done(); + }, + + "write/readUint16": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0xFFFF); + bb.flip(); + test.equal(0xFFFF, bb.readUint16()); + test.done(); + }, + + "write/readInt32": function(test) { + var bb = new ByteBuffer(4); + bb.writeInt32(0xFFFFFFFF); + bb.flip(); + test.equal(-1, bb.readInt32()); + test.done(); + }, + + "write/readInt": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt32, bb.readInt); + test.strictEqual(bb.writeInt32, bb.writeInt); + test.done(); + }, + + "write/readUint32": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.flip(); + test.equal(0x12345678, bb.readUint32()); + test.done(); + }, + + "write/readFloat32": function(test) { + var bb = new ByteBuffer(4); + bb.writeFloat32(0.5); + bb.flip(); + test.equal(0.5, bb.readFloat32()); // 0.5 remains 0.5 if Float32 + test.done(); + }, + + "write/readFloat": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readFloat32, bb.readFloat); + test.strictEqual(bb.writeFloat32, bb.writeFloat); + test.done(); + }, + + "write/readFloat64": function(test) { + var bb = new ByteBuffer(8); + bb.writeFloat64(0.1); + bb.flip(); + test.equal(0.1, bb.readFloat64()); // would be 0.10000000149011612 if Float32 + test.done(); + }, + + "write/readDouble": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readFloat64, bb.readDouble); + test.strictEqual(bb.writeFloat64, bb.writeDouble); + test.done(); + }, + + "write/readInt64": function(test) { + var bb = new ByteBuffer(8); + + var max = ByteBuffer.Long.MAX_SIGNED_VALUE.toNumber(); + bb.writeInt64(max).flip(); + test.equal(bb.toString("debug"), "<7F FF FF FF FF FF FF FF>"); + test.equal(bb.readInt64(0), max); + + var min = ByteBuffer.Long.MIN_SIGNED_VALUE.toNumber(); + bb.writeInt64(min).flip(); + test.equal(bb.toString("debug"), "<80 00 00 00 00 00 00 00>"); + test.equal(bb.readInt64(0), min); + + bb.writeInt64(-1).flip(); + test.equal(bb.toString("debug"), ""); + test.equal(bb.readInt64(0), -1); + + bb.reset(); + bb.LE().writeInt64(new ByteBuffer.Long(0x89ABCDEF, 0x01234567)).flip(); + test.equal(bb.toString("debug"), ""); + + test.done(); + }, + + "write/readUint64": function(test) { + var bb = new ByteBuffer(8); + + var max = ByteBuffer.Long.MAX_UNSIGNED_VALUE.toNumber(); + bb.writeUint64(max).flip(); + test.equal(bb.toString("debug"), ""); + test.equal(bb.readUint64(0), max); + + var min = ByteBuffer.Long.MIN_UNSIGNED_VALUE.toNumber(); + bb.writeLong(min).flip(); + test.equal(bb.toString("debug"), "<00 00 00 00 00 00 00 00>"); + test.equal(bb.readUint64(0), min); + + bb.writeUint64(-1).flip(); + test.equal(bb.toString("debug"), "<00 00 00 00 00 00 00 00>"); + test.equal(bb.readUint64(0), 0); + + bb.reset(); + bb.LE().writeUint64(new ByteBuffer.Long(0x89ABCDEF, 0x01234567, true)).flip(); + test.equal(bb.toString("debug"), ""); + + test.done(); + }, + + "write/readLong": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt64, bb.readLong); + test.strictEqual(bb.writeInt64, bb.writeLong); + test.done(); + }, + + "writeVarint64/readVarint32": function(test) { + var bb = new ByteBuffer(); + bb.writeVarint64(Long.fromNumber(-1)); + bb.flip(); + var n = bb.readVarint32(); + test.equal(n, -1); + test.done(); + }, + + "LE/BE": function(test) { + var bb = new ByteBuffer(8).LE().writeInt(1).BE().writeInt(2).flip(); + test.equal(bb.toString("debug"), "<01 00 00 00 00 00 00 02>"); + test.done(); + }, + + "calculateVarint32/64": function(test) { + test.equal(ByteBuffer.MAX_VARINT32_BYTES, 5); + test.equal(ByteBuffer.MAX_VARINT64_BYTES, 10); + var values = [ + [0, 1], + [-1, 5, 10], + [1<<7, 2], + [1<<14, 3], + [1<<21, 4], + [1<<28, 5], + [0x7FFFFFFF | 0, 5], + [0xFFFFFFFF, 5], + [0xFFFFFFFF | 0, 5, 10] + ]; + for (var i=0; i 2 ? values[i][2] : values[i][1]); + } + var Long = ByteBuffer.Long; + values = [ + [Long.fromNumber(1).shiftLeft(35), 6], + [Long.fromNumber(1).shiftLeft(42), 7], + [Long.fromNumber(1).shiftLeft(49), 8], + [Long.fromNumber(1).shiftLeft(56), 9], + [Long.fromNumber(1).shiftLeft(63), 10], + [Long.fromNumber(1, true).shiftLeft(63), 10] + ]; + for (i=0; i 1 ? values[i][1] : values[i][0]).toString(), dec['value'].toString()); + test.equal(encLen, dec['length']); + } + test.done(); + }, + + "write/readZigZagVarint32": function(test) { + var values = [ + 0, + 1, + 300, + -300, + 2147483647, + -2147483648 + ]; + var bb = new ByteBuffer(10); + for (var i=0; i00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readLString(0)); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.equal("ab", bb.readLString()); + test.equal(bb.toString("debug"), " 02 61 62|00 "); + test.done(); + }, + + "write/readVString": function(test) { + var bb = new ByteBuffer(2); + bb.writeVString("ab"); // resizes to 4 + test.equal(bb.array.byteLength, 4); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readVString(0)); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.equal("ab", bb.readLString()); + test.equal(bb.toString("debug"), " 02 61 62|00 "); + test.done(); + }, + + "write/readCString": function(test) { + var bb = new ByteBuffer(2); + bb.writeCString("ab"); // resizes to 4 + test.equal(bb.array.byteLength, 4); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.toString("debug"), "<61 62 00>00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readCString(0)); + test.equal(bb.toString("debug"), "<61 62 00>00 "); + test.equal("ab", bb.readCString()); + test.equal(bb.toString("debug"), " 61 62 00|00 "); + test.done(); + }, + + "write/readJSON": function(test) { + var bb = new ByteBuffer(); + var data = {"x":1}; + bb.writeJSON(data); + bb.flip(); + test.deepEqual(data, bb.readJSON()); + test.done(); + }, + + "toHex": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + test.equal(bb.flip().toHex(), "1234"); + test.done(); + }, + + "toString": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x6162).flip(); + test.equal(bb.toString(), "ByteBuffer(offset=0,markedOffset=-1,length=2,capacity=3)"); + test.equal(bb.toString("hex"), "6162"); + test.equal(bb.toString("base64"), "YWI="); + test.equal(bb.toString("utf8"), "ab"); + test.equal(bb.toString("debug"), "<61 62>00 "); + test.done(); + }, + + "toArrayBuffer": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + var buf = bb.toArrayBuffer(); + test.equal(buf.byteLength, 2); + test.equal(buf[0], 0x12); + test.equal(buf[1], 0x34); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.array.byteLength, 3); + test.done(); + }, + + "toBuffer": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + var buf; + try { + buf = bb.toBuffer(); + } catch (e) { + console.trace(e); + } + test.equal(buf.length, 2); + test.equal(buf[0], 0x12); + test.equal(buf[1], 0x34); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.array.byteLength, 3); + test.done(); + }, + + "printDebug": function(test) { + var bb = new ByteBuffer(3); + function callMe() { callMe.called = true; }; + bb.printDebug(callMe); + test.ok(callMe.called); + test.done(); + }, + + "encode/decode/calculateUTF8Char": function(test) { + var bb = new ByteBuffer(6) + , chars = [0x00, 0x7F, 0x80, 0x7FF, 0x800, 0xFFFF, 0x10000, 0x1FFFFF, 0x200000, 0x3FFFFFF, 0x4000000, 0x7FFFFFFF] + , dec; + for (var i=0; i10 02 18 00 20 80 B0 D9 B4 E8 27 28 93 99 8E CD 04<00 "); + test.done(); + }, + + "encode/decode64": function(test) { + var values = [ + ["ProtoBuf.js", "UHJvdG9CdWYuanM="], + ["ProtoBuf.j", "UHJvdG9CdWYuag=="], + ["ProtoBuf.", "UHJvdG9CdWYu"], + ["ProtoBuf", "UHJvdG9CdWY="] + ]; + for (var i=0; i>> 0, 0); + test.strictEqual(NaN | 0, 0); + test.strictEqual(Infinity >>> 0, 0); + test.strictEqual(Infinity | 0, 0); + test.strictEqual(-Infinity >>> 0, 0); + test.strictEqual(-Infinity | 0, 0); + + test.done(); + }, + + "ByteBuffer-like": function(test) { + var bb = new ByteBuffer(4); + var bbLike = { + array: bb.array, + view: bb.view, + offset: bb.offset, + markedOffset: bb.markedOffset, + length: bb.length, + littleEndian: bb.littleEndian + }; + test.ok(ByteBuffer.isByteBuffer(bbLike)); + var bb2 = ByteBuffer.wrap(bbLike); + test.ok(bb2 instanceof ByteBuffer); + test.strictEqual(bbLike.array, bb2.array); + test.strictEqual(bbLike.view, bb2.view); + test.strictEqual(bbLike.offset, bb2.offset); + test.strictEqual(bbLike.markedOffset, bb2.markedOffset); + test.strictEqual(bbLike.length, bb2.length); + test.strictEqual(bbLike.littleEndian, bb2.littleEndian); + test.done(); + }, + + "commonjs": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var Long = ByteBuffer.Long; + var sandbox = new Sandbox({ + require: function(moduleName) { + if (moduleName == 'long') { + return Long; + } + }, + module: { + exports: {} + } + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in CommonJS-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.module.exports == 'function'); + test.ok(sandbox.module.exports.Long && sandbox.module.exports.Long == ByteBuffer.Long); + test.done(); + }, + + "amd": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + require: function() {}, + define: (function() { + function define(moduleName, dependencies, constructor) { + define.called = [moduleName, dependencies]; + } + define.amd = true; + define.called = null; + return define; + })() + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in AMD-VM"); + // console.log(util.inspect(sandbox)); + test.ok(sandbox.define.called && sandbox.define.called[0] == "ByteBuffer" && sandbox.define.called[1][0] == "Math/Long"); + test.done(); + }, + + "shim": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + dcodeIO: { + Long: ByteBuffer.Long + } + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in shim-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.dcodeIO != 'undefined' && typeof sandbox.dcodeIO.ByteBuffer != 'undefined'); + test.ok(sandbox.dcodeIO.ByteBuffer.Long && sandbox.dcodeIO.ByteBuffer.Long == ByteBuffer.Long); + test.done(); + }, + + "helloworld": function(test) { + var bb = new ByteBuffer(); + bb.writeUTF8String("Hello world! from ByteBuffer.js. This is just a last visual test of ByteBuffer#printDebug."); + bb.flip(); + console.log(""); + bb.printDebug(console.log); + test.done(); + } +}; + +module.exports = suite; diff --git a/javascript/node_modules/long/.npmignore b/javascript/node_modules/long/.npmignore new file mode 100644 index 0000000..3abe3d4 --- /dev/null +++ b/javascript/node_modules/long/.npmignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/javascript/node_modules/long/.travis.yml b/javascript/node_modules/long/.travis.yml new file mode 100644 index 0000000..3f38c24 --- /dev/null +++ b/javascript/node_modules/long/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - 0.4 + - 0.6 + - 0.8 + - 0.10 diff --git a/javascript/node_modules/long/LICENSE b/javascript/node_modules/long/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/long/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/long/Long.js b/javascript/node_modules/long/Long.js new file mode 100644 index 0000000..339e8ad --- /dev/null +++ b/javascript/node_modules/long/Long.js @@ -0,0 +1,940 @@ +/* + Copyright 2013 Daniel Wirtz + Copyright 2009 The Closure Library Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license Long.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/Long.js for details + * + * Long.js is based on goog.math.Long from the Closure Library. + * Copyright 2009 The Closure Library Authors. All Rights Reserved. + * Released under the Apache License, Version 2.0 + * see: https://code.google.com/p/closure-library/ for details + */ + +/** + * Defines a Long class for representing a 64-bit two's-complement + * integer value, which faithfully simulates the behavior of a Java "long". This + * implementation is derived from LongLib in GWT. + */ +(function(global) { + + /** + * Constructs a 64-bit two's-complement integer, given its low and high 32-bit + * values as *signed* integers. See the from* functions below for more + * convenient ways of constructing Longs. + * + * The internal representation of a long is the two given signed, 32-bit values. + * We use 32-bit pieces because these are the size of integers on which + * Javascript performs bit-operations. For operations like addition and + * multiplication, we split each number into 16-bit pieces, which can easily be + * multiplied within Javascript's floating-point representation without overflow + * or change in sign. + * + * In the algorithms below, we frequently reduce the negative case to the + * positive case by negating the input(s) and then post-processing the result. + * Note that we must ALWAYS check specially whether those values are MIN_VALUE + * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as + * a positive number, it overflows back into a negative). Not handling this + * case would often result in infinite recursion. + * + * @exports Long + * @class A Long class for representing a 64-bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long. + * @param {number} high The high (signed) 32 bits of the long. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed). + * @constructor + */ + var Long = function(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + * @expose + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + * @expose + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + * @expose + */ + this.unsigned = !!unsigned; + }; + + // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* methods on which they depend. + + // NOTE: The following cache variables are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * A cache of the Long representations of small integer values. + * @type {!Object} + */ + var INT_CACHE = {}; + + /** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + */ + var UINT_CACHE = {}; + + /** + * Returns a Long representing the given (32-bit) integer value. + * @param {number} value The 32-bit integer in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromInt = function(value, unsigned) { + var obj, cachedObj; + if (!unsigned) { + value = value | 0; + if (-128 <= value && value < 128) { + cachedObj = INT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, value < 0 ? -1 : 0, false); + if (-128 <= value && value < 128) { + INT_CACHE[value] = obj; + } + return obj; + } else { + value = value >>> 0; + if (0 <= value && value < 256) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); + if (0 <= value && value < 256) { + UINT_CACHE[value] = obj; + } + return obj; + } + }; + + /** + * Returns a Long representing the given value, provided that it is a finite + * number. Otherwise, zero is returned. + * @param {number} value The number in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromNumber = function(value, unsigned) { + unsigned = !!unsigned; + if (isNaN(value) || !isFinite(value)) { + return Long.ZERO; + } else if (!unsigned && value <= -TWO_PWR_63_DBL) { + return Long.MIN_SIGNED_VALUE; + } else if (unsigned && value <= 0) { + return Long.MIN_UNSIGNED_VALUE; + } else if (!unsigned && value + 1 >= TWO_PWR_63_DBL) { + return Long.MAX_SIGNED_VALUE; + } else if (unsigned && value >= TWO_PWR_64_DBL) { + return Long.MAX_UNSIGNED_VALUE; + } else if (value < 0) { + return Long.fromNumber(-value, false).negate(); + } else { + return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); + } + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @param {number} lowBits The low 32 bits. + * @param {number} highBits The high 32 bits. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromBits = function(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + * Each is assumed to use 28 bits. + * @param {number} part0 The low 28 bits + * @param {number} part1 The middle 28 bits + * @param {number} part2 The high 28 (8) bits + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} + * @expose + */ + Long.from28Bits = function(part0, part1, part2, unsigned) { + // 00000000000000000000000000001111 11111111111111111111111122222222 2222222222222 + // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH + return Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, unsigned); + }; + + /** + * Returns a Long representation of the given string, written using the given + * radix. + * @param {string} str The textual representation of the Long. + * @param {(boolean|number)=} unsigned Whether unsigned or not. Defaults to false (signed). + * @param {number=} radix The radix in which the text is written. + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromString = function(str, unsigned, radix) { + if (str.length == 0) { + throw(new Error('number format error: empty string')); + } + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") { + return Long.ZERO; + } + if (typeof unsigned === 'number') { // For goog.math.Long compatibility + radix = unsigned; + unsigned = false; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + + if (str.charAt(0) == '-') { + return Long.fromString(str.substring(1), unsigned, radix).negate(); + } else if (str.indexOf('-') >= 0) { + throw(new Error('number format error: interior "-" character: ' + str)); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 8)); + + var result = Long.ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i); + var value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = Long.fromNumber(Math.pow(radix, size)); + result = result.multiply(power).add(Long.fromNumber(value)); + } else { + result = result.multiply(radixToPower); + result = result.add(Long.fromNumber(value)); + } + } + return result; + }; + + // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be + // no runtime penalty for these. + + // NOTE: The following constant values are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * @type {number} + */ + var TWO_PWR_16_DBL = 1 << 16; + + /** + * @type {number} + */ + var TWO_PWR_24_DBL = 1 << 24; + + /** + * @type {number} + */ + var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_31_DBL = TWO_PWR_32_DBL / 2; + + /** + * @type {number} + */ + var TWO_PWR_48_DBL = TWO_PWR_32_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + + /** + * @type {number} + */ + var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + + /** + * @type {!Long} + */ + var TWO_PWR_24 = Long.fromInt(1 << 24); + + /** + * @type {!Long} + * @expose + */ + Long.ZERO = Long.fromInt(0); + + /** + * @type {!Long} + * @expose + */ + Long.ONE = Long.fromInt(1); + + /** + * @type {!Long} + * @expose + */ + Long.NEG_ONE = Long.fromInt(-1); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_SIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); + + /** + * Alias of {@link Long.MAX_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MAX_VALUE = Long.MAX_SIGNED_VALUE; + + /** + * @type {!Long} + * @expose + */ + Long.MIN_SIGNED_VALUE = Long.fromBits(0, 0x80000000 | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MIN_UNSIGNED_VALUE = Long.fromBits(0, 0, true); + + /** + * Alias of {@link Long.MIN_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MIN_VALUE = Long.MIN_SIGNED_VALUE; + + /** + * @return {number} The value, assuming it is a 32-bit integer. + * @expose + */ + Long.prototype.toInt = function() { + return this.unsigned ? this.low >>> 0 : this.low; + }; + + /** + * @return {number} The closest floating-point representation to this value. + * @expose + */ + Long.prototype.toNumber = function() { + if (this.unsigned) { + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + } + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); + }; + + /** + * @param {number=} radix The radix in which the text should be written. + * @return {string} The textual representation of this value. + * @override + * @expose + */ + Long.prototype.toString = function(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + if (this.isZero()) { + return '0'; + } + var rem; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = Long.fromNumber(radix); + var div = this.div(radixLong); + rem = div.multiply(radixLong).subtract(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else { + return '-' + this.negate().toString(radix); + } + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 6)); + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower); + var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); + var digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) { + return digits + result; + } else { + while (digits.length < 6) { + digits = '0' + digits; + } + result = '' + digits + result; + } + } + }; + + /** + * @return {number} The high 32 bits as a signed value. + * @expose + */ + Long.prototype.getHighBits = function() { + return this.high; + }; + + /** + * @return {number} The high 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getHighBitsUnsigned = function() { + return this.high >>> 0; + }; + + /** + * @return {number} The low 32 bits as a signed value. + * @expose + */ + Long.prototype.getLowBits = function() { + return this.low; + }; + + /** + * @return {number} The low 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getLowBitsUnsigned = function() { + return this.low >>> 0; + }; + + /** + * @return {number} Returns the number of bits needed to represent the absolute + * value of this Long. + * @expose + */ + Long.prototype.getNumBitsAbs = function() { + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + return 64; + } else { + return this.negate().getNumBitsAbs(); + } + } else { + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) { + if ((val & (1 << bit)) != 0) { + break; + } + } + return this.high != 0 ? bit + 33 : bit + 1; + } + }; + + /** + * @return {boolean} Whether this value is zero. + * @expose + */ + Long.prototype.isZero = function() { + return this.high == 0 && this.low == 0; + }; + + /** + * @return {boolean} Whether this value is negative. + * @expose + */ + Long.prototype.isNegative = function() { + return !this.unsigned && this.high < 0; + }; + + /** + * @return {boolean} Whether this value is odd. + * @expose + */ + Long.prototype.isOdd = function() { + return (this.low & 1) == 1; + }; + + /** + * @return {boolean} Whether this value is even. + */ + Long.prototype.isEven = function() { + return (this.low & 1) == 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long equals the other. + * @expose + */ + Long.prototype.equals = function(other) { + if (this.unsigned != other.unsigned && (this.high >>> 31) != (other.high >>> 31)) return false; + return (this.high == other.high) && (this.low == other.low); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long does not equal the other. + * @expose + */ + Long.prototype.notEquals = function(other) { + return !this.equals(other); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than the other. + * @expose + */ + Long.prototype.lessThan = function(other) { + return this.compare(other) < 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than or equal to the other. + * @expose + */ + Long.prototype.lessThanOrEqual = function(other) { + return this.compare(other) <= 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than the other. + * @expose + */ + Long.prototype.greaterThan = function(other) { + return this.compare(other) > 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than or equal to the other. + * @expose + */ + Long.prototype.greaterThanOrEqual = function(other) { + return this.compare(other) >= 0; + }; + + /** + * Compares this Long with the given one. + * @param {Long} other Long to compare against. + * @return {number} 0 if they are the same, 1 if the this is greater, and -1 + * if the given one is greater. + * @expose + */ + Long.prototype.compare = function(other) { + if (this.equals(other)) { + return 0; + } + var thisNeg = this.isNegative(); + var otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) return -1; + if (!thisNeg && otherNeg) return 1; + if (!this.unsigned) { + // At this point the signs are the same + return this.subtract(other).isNegative() ? -1 : 1; + } else { + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high == this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; + } + }; + + /** + * @return {!Long} The negation of this value. + * @expose + */ + Long.prototype.negate = function() { + if (!this.unsigned && this.equals(Long.MIN_SIGNED_VALUE)) { + return Long.MIN_SIGNED_VALUE; + } + return this.not().add(Long.ONE); + }; + + /** + * Returns the sum of this and the given Long. + * @param {Long} other Long to add to this one. + * @return {!Long} The sum of this and the given Long. + * @expose + */ + Long.prototype.add = function(other) { + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns the difference of this and the given Long. + * @param {Long} other Long to subtract from this. + * @return {!Long} The difference of this and the given Long. + * @expose + */ + Long.prototype.subtract = function(other) { + return this.add(other.negate()); + }; + + /** + * Returns the product of this and the given long. + * @param {Long} other Long to multiply with this. + * @return {!Long} The product of this and the other. + * @expose + */ + Long.prototype.multiply = function(other) { + if (this.isZero()) { + return Long.ZERO; + } else if (other.isZero()) { + return Long.ZERO; + } + + if (this.equals(Long.MIN_VALUE)) { + return other.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } else if (other.equals(Long.MIN_VALUE)) { + return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } + + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().multiply(other.negate()); + } else { + return this.negate().multiply(other).negate(); + } + } else if (other.isNegative()) { + return this.multiply(other.negate()).negate(); + } + // If both longs are small, use float multiplication + if (this.lessThan(TWO_PWR_24) && + other.lessThan(TWO_PWR_24)) { + return Long.fromNumber(this.toNumber() * other.toNumber(), this.unsigned); + } + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns this Long divided by the given one. + * @param {Long} other Long by which to divide. + * @return {!Long} This Long divided by the given one. + * @expose + */ + Long.prototype.div = function(other) { + if (other.isZero()) { + throw(new Error('division by zero')); + } else if (this.isZero()) { + return Long.ZERO; + } + if (this.equals(Long.MIN_SIGNED_VALUE)) { + if (other.equals(Long.ONE) || other.equals(Long.NEG_ONE)) { + return min; // recall that -MIN_VALUE == MIN_VALUE + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ONE; + } else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shiftRight(1); + var approx = halfThis.div(other).shiftLeft(1); + if (approx.equals(Long.ZERO)) { + return other.isNegative() ? Long.ONE : Long.NEG_ONE; + } else { + var rem = this.subtract(other.multiply(approx)); + var result = approx.add(rem.div(other)); + return result; + } + } + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ZERO; + } + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().div(other.negate()); + } else { + return this.negate().div(other).negate(); + } + } else if (other.isNegative()) { + return this.div(other.negate()).negate(); + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + var res = Long.ZERO; + var rem = this; + while (rem.greaterThanOrEqual(other)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2); + var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48); + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + var approxRes = Long.fromNumber(approx, this.unsigned); + var approxRem = approxRes.multiply(other); + while (approxRem.isNegative() || approxRem.greaterThan(rem)) { + approx -= delta; + approxRes = Long.fromNumber(approx, this.unsigned); + approxRem = approxRes.multiply(other); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) { + approxRes = Long.ONE; + } + + res = res.add(approxRes); + rem = rem.subtract(approxRem); + } + return res; + }; + + /** + * Returns this Long modulo the given one. + * @param {Long} other Long by which to mod. + * @return {!Long} This Long modulo the given one. + * @expose + */ + Long.prototype.modulo = function(other) { + return this.subtract(this.div(other).multiply(other)); + }; + + /** + * @return {!Long} The bitwise-NOT of this value. + * @expose + */ + Long.prototype.not = function() { + return Long.fromBits(~this.low, ~this.high, this.unsigned); + }; + + /** + * Returns the bitwise-AND of this Long and the given one. + * @param {Long} other The Long with which to AND. + * @return {!Long} The bitwise-AND of this and the other. + * @expose + */ + Long.prototype.and = function(other) { + return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned); + }; + + /** + * Returns the bitwise-OR of this Long and the given one. + * @param {Long} other The Long with which to OR. + * @return {!Long} The bitwise-OR of this and the other. + * @expose + */ + Long.prototype.or = function(other) { + return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned); + }; + + /** + * Returns the bitwise-XOR of this Long and the given one. + * @param {Long} other The Long with which to XOR. + * @return {!Long} The bitwise-XOR of this and the other. + * @expose + */ + Long.prototype.xor = function(other) { + return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); + }; + + /** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the left by the given amount. + * @expose + */ + Long.prototype.shiftLeft = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var low = this.low; + if (numBits < 32) { + var high = this.high; + return Long.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits)), this.unsigned); + } else { + return Long.fromBits(0, low << (numBits - 32), this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount. + * @expose + */ + Long.prototype.shiftRight = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits, this.unsigned); + } else { + return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1, this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount, with + * the new top bits matching the current sign bit. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount, with + * zeros placed into the new leading bits. + * @expose + */ + Long.prototype.shiftRightUnsigned = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits == 32) { + return Long.fromBits(high, 0, this.unsigned); + } else { + return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned); + } + } + }; + + /** + * @return {!Long} Signed long + * @expose + */ + Long.prototype.toSigned = function() { + var l = this.clone(); + l.unsigned = false; + return l; + }; + + /** + * @return {!Long} Unsigned long + * @expose + */ + Long.prototype.toUnsigned = function() { + var l = this.clone(); + l.unsigned = true; + return l; + }; + + /** + * @return {Long} Cloned instance with the same low/high bits and unsigned flag. + * @expose + */ + Long.prototype.clone = function() { + return new Long(this.low, this.high, this.unsigned); + }; + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = Long; + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("Math/Long", [], function() { return Long; }); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["Long"] = Long; + } + +})(this); diff --git a/javascript/node_modules/long/Long.min.js b/javascript/node_modules/long/Long.min.js new file mode 100644 index 0000000..a1be1ab --- /dev/null +++ b/javascript/node_modules/long/Long.min.js @@ -0,0 +1,26 @@ +/* + Long.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/Long.js for details + + Long.js is based on goog.math.Long from the Closure Library. + Copyright 2009 The Closure Library Authors. All Rights Reserved. + Released under the Apache License, Version 2.0 + see: https://code.google.com/p/closure-library/ for details +*/ +var p=!1; +(function(r){function b(a,b,d){this.low=a|0;this.high=b|0;this.unsigned=!!d}var s={},t={};b.fromInt=function(a,c){var d;if(c){a>>>=0;if(0<=a&&256>a&&(d=t[a]))return d;d=new b(a,0>(a|0)?-1:0,!0);0<=a&&256>a&&(t[a]=d)}else{a|=0;if(-128<=a&&128>a&&(d=s[a]))return d;d=new b(a,0>a?-1:0,p);-128<=a&&128>a&&(s[a]=d)}return d};b.fromNumber=function(a,c){c=!!c;return isNaN(a)||!isFinite(a)?b.ZERO:!c&&a<=-u?b.MIN_SIGNED_VALUE:c&&0>=a?b.MIN_UNSIGNED_VALUE:!c&&a+1>=u?b.MAX_SIGNED_VALUE:c&&a>=v?b.MAX_UNSIGNED_VALUE:0> +a?b.fromNumber(-a,p).negate():new b(a%l|0,a/l|0,c)};b.fromBits=function(a,c,d){return new b(a,c,d)};b.from28Bits=function(a,c,d,e){return b.fromBits(a|c<<28,c>>>4|d<<24,e)};b.fromString=function(a,c,d){if(0==a.length)throw Error("number format error: empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return b.ZERO;"number"===typeof c&&(d=c,c=p);d=d||10;if(2>d||36f?(f=b.fromNumber(Math.pow(d,f)),e=e.multiply(f).add(b.fromNumber(k))):(e=e.multiply(c),e=e.add(b.fromNumber(k)))}return e};var l=4294967296,v=l*l,u=v/2,w=b.fromInt(16777216);b.ZERO=b.fromInt(0);b.ONE=b.fromInt(1);b.NEG_ONE=b.fromInt(-1);b.MAX_SIGNED_VALUE=b.fromBits(-1,2147483647,p); +b.MAX_UNSIGNED_VALUE=b.fromBits(-1,-1,!0);b.MAX_VALUE=b.MAX_SIGNED_VALUE;b.MIN_SIGNED_VALUE=b.fromBits(0,-2147483648,p);b.MIN_UNSIGNED_VALUE=b.fromBits(0,0,!0);b.MIN_VALUE=b.MIN_SIGNED_VALUE;b.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low};b.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)};b.prototype.toString=function(a){a=a||10;if(2>a||36f.length;)f="0"+f;e=""+f+e}};b.prototype.getHighBits=function(){return this.high};b.prototype.getHighBitsUnsigned=function(){return this.high>>>0}; +b.prototype.getLowBits=function(){return this.low};b.prototype.getLowBitsUnsigned=function(){return this.low>>>0};b.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(b.MIN_SIGNED_VALUE)?64:this.negate().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,c=31;0this.high};b.prototype.isOdd=function(){return 1== +(this.low&1)};b.prototype.equals=function(a){return this.unsigned!=a.unsigned&&this.high>>>31!=a.high>>>31?p:this.high==a.high&&this.low==a.low};b.prototype.notEquals=function(a){return!this.equals(a)};b.prototype.lessThan=function(a){return 0>this.compare(a)};b.prototype.lessThanOrEqual=function(a){return 0>=this.compare(a)};b.prototype.greaterThan=function(a){return 0>>0>this.high>>>0||a.high==this.high&&a.low>>>0>this.low>>>0?-1:1:this.subtract(a).isNegative()?-1:1};b.prototype.negate=function(){return!this.unsigned&&this.equals(b.MIN_SIGNED_VALUE)?b.MIN_SIGNED_VALUE:this.not().add(b.ONE)};b.prototype.add=function(a){var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=a.high>>>16,f=a.high&65535,k=a.low>>>16,q;q=0+((this.low&65535)+(a.low&65535));a=0+(q>>>16);a+=e+k;e=0+ +(a>>>16);e+=d+f;d=0+(e>>>16);d=d+(c+g)&65535;return b.fromBits((a&65535)<<16|q&65535,d<<16|e&65535,this.unsigned)};b.prototype.subtract=function(a){return this.add(a.negate())};b.prototype.multiply=function(a){if(this.isZero()||a.isZero())return b.ZERO;if(this.equals(b.MIN_VALUE))return a.isOdd()?b.MIN_VALUE:b.ZERO;if(a.equals(b.MIN_VALUE))return this.isOdd()?b.MIN_VALUE:b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().multiply(a.negate()):this.negate().multiply(a).negate();if(a.isNegative())return this.multiply(a.negate()).negate(); +if(this.lessThan(w)&&a.lessThan(w))return b.fromNumber(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=this.low&65535,f=a.high>>>16,k=a.high&65535,q=a.low>>>16;a=a.low&65535;var n,h,m,l;l=0+g*a;m=0+(l>>>16);m+=e*a;h=0+(m>>>16);m=(m&65535)+g*q;h+=m>>>16;m&=65535;h+=d*a;n=0+(h>>>16);h=(h&65535)+e*q;n+=h>>>16;h&=65535;h+=g*k;n+=h>>>16;h&=65535;n=n+(c*a+d*q+e*k+g*f)&65535;return b.fromBits(m<<16|l&65535,n<<16|h,this.unsigned)};b.prototype.div=function(a){if(a.isZero())throw Error("division by zero"); +if(this.isZero())return b.ZERO;if(this.equals(b.MIN_SIGNED_VALUE)){if(a.equals(b.ONE)||a.equals(b.NEG_ONE))return min;if(a.equals(b.MIN_VALUE))return b.ONE;var c=this.shiftRight(1).div(a).shiftLeft(1);if(c.equals(b.ZERO))return a.isNegative()?b.ONE:b.NEG_ONE;var d=this.subtract(a.multiply(c));return c.add(d.div(a))}if(a.equals(b.MIN_VALUE))return b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().div(a.negate()):this.negate().div(a).negate();if(a.isNegative())return this.div(a.negate()).negate(); +for(var e=b.ZERO,d=this;d.greaterThanOrEqual(a);){for(var c=Math.max(1,Math.floor(d.toNumber()/a.toNumber())),g=Math.ceil(Math.log(c)/Math.LN2),g=48>=g?1:Math.pow(2,g-48),f=b.fromNumber(c,this.unsigned),k=f.multiply(a);k.isNegative()||k.greaterThan(d);)c-=g,f=b.fromNumber(c,this.unsigned),k=f.multiply(a);f.isZero()&&(f=b.ONE);e=e.add(f);d=d.subtract(k)}return e};b.prototype.modulo=function(a){return this.subtract(this.div(a).multiply(a))};b.prototype.not=function(){return b.fromBits(~this.low,~this.high, +this.unsigned)};b.prototype.and=function(a){return b.fromBits(this.low&a.low,this.high&a.high,this.unsigned)};b.prototype.or=function(a){return b.fromBits(this.low|a.low,this.high|a.high,this.unsigned)};b.prototype.xor=function(a){return b.fromBits(this.low^a.low,this.high^a.high,this.unsigned)};b.prototype.shiftLeft=function(a){a&=63;if(0==a)return this;var c=this.low;return 32>a?b.fromBits(c<>>32-a,this.unsigned):b.fromBits(0,c<a?b.fromBits(this.low>>>a|c<<32-a,c>>a,this.unsigned):b.fromBits(c>>a-32,0<=c?0:-1,this.unsigned)};b.prototype.shiftRightUnsigned=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>>a,this.unsigned):32==a?b.fromBits(c,0,this.unsigned):b.fromBits(c>>>a-32,0,this.unsigned)};b.prototype.toSigned=function(){var a=this.clone();a.unsigned=p;return a};b.prototype.toUnsigned=function(){var a=this.clone();a.unsigned= +!0;return a};b.prototype.clone=function(){return new b(this.low,this.high,this.unsigned)};"undefined"!=typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("Math/Long",[],function(){return b}):(r.dcodeIO||(r.dcodeIO={}),r.dcodeIO.Long=b)})(this); diff --git a/javascript/node_modules/long/NOTICE b/javascript/node_modules/long/NOTICE new file mode 100644 index 0000000..7563caf --- /dev/null +++ b/javascript/node_modules/long/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) Long.js by Daniel 'dcode' Wirtz. +See: https://github.com/dcodeIO/Long.js for details diff --git a/javascript/node_modules/long/README.md b/javascript/node_modules/long/README.md new file mode 100644 index 0000000..2e48bd8 --- /dev/null +++ b/javascript/node_modules/long/README.md @@ -0,0 +1,75 @@ +![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png) +======= +A Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/) +for stand-alone use and extended with unsigned support. + +Why? +---- +As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value +of 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit +numbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations +on the full 64bits. This is where Long.js comes into play. + +Features +-------- +* [CommonJS](http://www.commonjs.org/) compatible +* [RequireJS](http://requirejs.org/)/AMD compatible +* Shim compatible (include the script, then use var Long = dcodeIO.Long;) +* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* API-compatible to the Closure Library implementation +* Zero production dependencies +* Small footprint + +Usage +----- + +#### node.js / CommonJS #### + +Install: `npm install long` + +```javascript +var Long = require("long"); +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +console.log(longVal.toString()); +... +``` + +#### RequireJS / AMD #### + +````javascript +require.config({ + "paths": { + "Math/Long": "/path/to/Long.js" + } +}); +require(["Math/Long"], function(Long) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + console.log(longVal.toString()); +}); +```` + +### Browser / shim #### + +```html + +``` + +```javascript +var Long = dcodeIO.Long; +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +alert(longVal.toString()); +``` + +Documentation +------------- +* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html) + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master) + +License +------- +Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/javascript/node_modules/long/bower.json b/javascript/node_modules/long/bower.json new file mode 100644 index 0000000..5627a2d --- /dev/null +++ b/javascript/node_modules/long/bower.json @@ -0,0 +1,9 @@ +{ + "name": "long", + "version": "1.1.2", + "author": "Daniel Wirtz ", + "description": "Long.js: A Long class for representing a 64-bit two's-complement integer value derived from the Closure Library extended with unsigned support.", + "main": "Long.js", + "keywords": ["math"], + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/long/docs/Long.html b/javascript/node_modules/long/docs/Long.html new file mode 100644 index 0000000..effa27b --- /dev/null +++ b/javascript/node_modules/long/docs/Long.html @@ -0,0 +1,5380 @@ + + + + + Class: Long + + + + + + + + + + +
+ +

Class: Long

+ + + + + +
+ +
+

+ Long +

+ +
A Long class for representing a 64-bit two's-complement integer value.
+ +
+ +
+
+ + + + +
+

new Long(low, high, unsigned)

+ + +
+
+ + +
+ Constructs a 64-bit two's-complement integer, given its low and high 32-bit +values as *signed* integers. See the from* functions below for more +convenient ways of constructing Longs. + +The internal representation of a long is the two given signed, 32-bit values. +We use 32-bit pieces because these are the size of integers on which +Javascript performs bit-operations. For operations like addition and +multiplication, we split each number into 16-bit pieces, which can easily be +multiplied within Javascript's floating-point representation without overflow +or change in sign. + +In the algorithms below, we frequently reduce the negative case to the +positive case by negating the input(s) and then post-processing the result. +Note that we must ALWAYS check specially whether those values are MIN_VALUE +(-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +a positive number, it overflows back into a negative). Not handling this +case would often result in infinite recursion. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
low + + +number + + + + + + + + The low (signed) 32 bits of the long.
high + + +number + + + + + + + + The high (signed) 32 bits of the long.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to `false` (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static> MAX_SIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MAX_UNSIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MAX_VALUE :Long

+ + +
+
+ +
+ Alias of Long.MAX_SIGNED_VALUE for goog.math.Long compatibility. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_SIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_UNSIGNED_VALUE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> MIN_VALUE :Long

+ + +
+
+ +
+ Alias of Long.MIN_SIGNED_VALUE for goog.math.Long compatibility. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> NEG_ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ONE :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> ZERO :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

high :number

+ + +
+
+ +
+ The high 32 bits as a signed value. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

low :number

+ + +
+
+ +
+ The low 32 bits as a signed value. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

unsigned :boolean

+ + +
+
+ +
+ Whether unsigned or not. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> from28Bits(part0, part1, part2, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + Each is assumed to use 28 bits. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
part0 + + +number + + + + + + + + The low 28 bits
part1 + + +number + + + + + + + + The middle 28 bits
part2 + + +number + + + + + + + + The high 28 (8) bits
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromBits(lowBits, highBits, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + assumed to use 32 bits. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
lowBits + + +number + + + + + + + + The low 32 bits.
highBits + + +number + + + + + + + + The high 32 bits.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromInt(value, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the given (32-bit) integer value. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + + The 32-bit integer in question.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromNumber(value, unsigned) → {Long}

+ + +
+
+ + +
+ Returns a Long representing the given value, provided that it is a finite +number. Otherwise, zero is returned. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +number + + + + + + + + The number in question.
unsigned + + +boolean + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

<static> fromString(str, unsigned, radix) → {Long}

+ + +
+
+ + +
+ Returns a Long representation of the given string, written using the given +radix. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
str + + +string + + + + + + + + The textual representation of the Long.
unsigned + + +boolean +| + +number + + + + + + <optional>
+ + + +
Whether unsigned or not. Defaults to false (signed).
radix + + +number + + + + + + <optional>
+ + + +
The radix in which the text is written.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The corresponding Long value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

add(other) → {Long}

+ + +
+
+ + +
+ Returns the sum of this and the given Long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to add to this one.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The sum of this and the given Long. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

and(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-AND of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to AND.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-AND of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

clone() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Cloned instance with the same low/high bits and unsigned flag. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

compare(other) → {number}

+ + +
+
+ + +
+ Compares this Long with the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ 0 if they are the same, 1 if the this is greater, and -1 + if the given one is greater. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

div(other) → {Long}

+ + +
+
+ + +
+ Returns this Long divided by the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long by which to divide.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This Long divided by the given one. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

equals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long equals the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

getHighBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The high 32 bits as a signed value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getHighBitsUnsigned() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The high 32 bits as an unsigned value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBits() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The low 32 bits as a signed value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getLowBitsUnsigned() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The low 32 bits as an unsigned value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

getNumBitsAbs() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Returns the number of bits needed to represent the absolute + value of this Long. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

greaterThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is greater than the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

greaterThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is greater than or equal to the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isEven() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is even. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isNegative() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is negative. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isOdd() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is odd. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

isZero() → {boolean}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this value is zero. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThan(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is less than the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

lessThanOrEqual(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long is less than or equal to the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

modulo(other) → {Long}

+ + +
+
+ + +
+ Returns this Long modulo the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long by which to mod.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This Long modulo the given one. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

multiply(other) → {Long}

+ + +
+
+ + +
+ Returns the product of this and the given long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to multiply with this.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The product of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

negate() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The negation of this value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

not() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-NOT of this value. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

notEquals(other) → {boolean}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to compare against.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Whether this Long does not equal the other. +
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

or(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-OR of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to OR.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-OR of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftLeft(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the left by the given amount. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the left by the given amount. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRight(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the right by the given amount. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the right by the given amount. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

shiftRightUnsigned(numBits) → {Long}

+ + +
+
+ + +
+ Returns this Long with bits shifted to the right by the given amount, with +the new top bits matching the current sign bit. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numBits + + +number + + + + The number of bits by which to shift.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ This shifted to the right by the given amount, with + zeros placed into the new leading bits. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

subtract(other) → {Long}

+ + +
+
+ + +
+ Returns the difference of this and the given Long. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + Long to subtract from this.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The difference of this and the given Long. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

toInt() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The value, assuming it is a 32-bit integer. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toNumber() → {number}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The closest floating-point representation to this value. +
+ + + +
+
+ Type +
+
+ +number + + +
+
+ + + + +
+ + + +
+

toSigned() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Signed long +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

toString(radix) → {string}

+ + +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
radix + + +number + + + + + + <optional>
+ + + +
The radix in which the text should be written.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The textual representation of this value. +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toUnsigned() → {Long}

+ + +
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ Unsigned long +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ + + +
+

xor(other) → {Long}

+ + +
+
+ + +
+ Returns the bitwise-XOR of this Long and the given one. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
other + + +Long + + + + The Long with which to XOR.
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+ The bitwise-XOR of this and the other. +
+ + + +
+
+ Type +
+
+ +Long + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/long/docs/index.html b/javascript/node_modules/long/docs/index.html new file mode 100644 index 0000000..49ca749 --- /dev/null +++ b/javascript/node_modules/long/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
+ +

Index

+ + + + + + + +

+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/long/docs/scripts/html5.js b/javascript/node_modules/long/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/long/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/long/docs/scripts/prettify/prettify.js b/javascript/node_modules/long/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/long/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p?H2?rYR{#J&=n4P;F&8?!uthoT)~;-svgOJa$a^0sn^3kl zvO65Xh>-a79DLbhwA3>i3&{()^KsTGP zMY%E}sjOewKPqg?vYfJKWN>=rRb>aYfAh+LUn_gxWm_*RTj}#SI+Q&i`&q5+S!HjC z+4o~lz&>0f-(Tn9vwU2CQFg**KP@{Z=f?3mfx+gJHEJ?qi43|`;mG#Q8Ua9OB?RdA_+L?&>_v}~7Hj2l#P4@MG{Ck1zc)COsyKNpH0PyI1 zhE8uOD=53&hu8GH?87}CJvwWjUsSeMgwKuD;&~m^#J1XT>=94yYaWl`W!a}2L+VQ} z9^K7aKXiq4oxou8$=rmFBFNF*A#L3eKp^*sK=yhNx|~D4%nSF({;hHO+z;e)xAu)M5G!w z$u>6oXq&_5EfVV1Z@|Bs3Q`(c;7uByZNwLIT_xYPlJu6|g#tXFDigC_}ia$!k?`^lvsOI8mi>b2`l*|-bLjylPx~N z)^*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%_Tw=dP(xaXxfgMhV6kke4Cs`bd>e*>ctKMx0m8m9IV67 ziRI^C+$VW7zp&@@jD)b)1>A>qB9`oVd8y&E9uU5i&MvjsE8bnj*)sce5)~m{e?3|l zIOdQ8%h^6hQnfK^u641#vE8PLU((7JDZ4`1W$Fr9Nrt+Pm2y$Z zcvpS?b@l%1>atJA!ak{t^i}xlq_kX$V(*^Xdk^X~1KR zI9Sxt0SMi>3r|MeAt9{STg2~_aFv%>d3{*Wa`FBewn79#2OxBSB#h;95BoB<=0.6" + }, + "scripts": { + "make": "npm run-script compile && npm test && npm run-script jsdoc", + "compile": "ccjs Long.js --compilation_level=ADVANCED_OPTIMIZATIONS > Long.min.js", + "test": "node node_modules/testjs/bin/testjs tests/suite.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png)\n=======\nA Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/)\nfor stand-alone use and extended with unsigned support.\n\nWhy?\n----\nAs of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value\nof 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit\nnumbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations\non the full 64bits. This is where Long.js comes into play.\n\nFeatures\n--------\n* [CommonJS](http://www.commonjs.org/) compatible\n* [RequireJS](http://requirejs.org/)/AMD compatible\n* Shim compatible (include the script, then use var Long = dcodeIO.Long;)\n* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long)\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\n* API-compatible to the Closure Library implementation\n* Zero production dependencies\n* Small footprint\n\nUsage\n-----\n\n#### node.js / CommonJS ####\n\nInstall: `npm install long`\n\n```javascript\nvar Long = require(\"long\");\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nconsole.log(longVal.toString());\n...\n```\n\n#### RequireJS / AMD ####\n\n````javascript\nrequire.config({\n \"paths\": {\n \"Math/Long\": \"/path/to/Long.js\"\n }\n});\nrequire([\"Math/Long\"], function(Long) {\n var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\n console.log(longVal.toString());\n});\n````\n\n### Browser / shim ####\n\n```html\n\n```\n\n```javascript\nvar Long = dcodeIO.Long;\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nalert(longVal.toString());\n```\n\nDocumentation\n-------------\n* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html)\n\nDownloads\n---------\n* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip)\n* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master)\n\nLicense\n-------\nApache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/dcodeIO/Long.js/issues" + }, + "_id": "long@1.1.2", + "_from": "long@" +} diff --git a/javascript/node_modules/long/tests/suite.js b/javascript/node_modules/long/tests/suite.js new file mode 100644 index 0000000..e71a512 --- /dev/null +++ b/javascript/node_modules/long/tests/suite.js @@ -0,0 +1,156 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * Long.js Pretty Simple Test Suite. + */ +var Long = require(__dirname+"/../Long.min.js"); + +var suite = { + + "basic": function(test) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + test.equal(longVal.toNumber(), 9223372036854775807); + test.equal(longVal.toString(), "9223372036854775807"); + test.done(); + }, + + // Let's assume signed goog.math.Long works as expected because the people at Google are pretty smart. + + // So let's focus on my probably not-so-smart extensions: + + "from28Bits": function(test) { + var val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF); + test.equal(val.toString(), "-1"); + test.done(); + }, + + "unsigned": { + + "min/max": function(test) { + test.equal(Long.MIN_SIGNED_VALUE.toString(), "-9223372036854775808"); + test.equal(Long.MAX_SIGNED_VALUE.toString(), "9223372036854775807"); + test.equal(Long.MIN_UNSIGNED_VALUE.toString(), "0"); + test.equal(Long.MAX_UNSIGNED_VALUE.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_negint": function(test) { + var longVal = Long.fromInt(-1, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_highlow": function(test) { + var longVal = new Long(0xFFFFFFFF, 0xFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_number": function(test) { + var longVal = Long.fromNumber(0xFFFFFFFFFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "toSigned/Unsigned": function(test) { + var longVal = Long.fromNumber(-1, false); + test.equal(longVal.toNumber(), -1); + longVal = longVal.toUnsigned(); + test.equal(longVal.toNumber(), 0xFFFFFFFFFFFFFFFF); + longVal = longVal.toSigned(); + test.equal(longVal.toNumber(), -1); + test.done(); + }, + + "max_unsigned_sub_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_SIGNED_VALUE).subtract(Long.ONE); + test.equal(longVal.toNumber(), Long.MAX_SIGNED_VALUE); + test.equal(longVal.toString(), Long.MAX_SIGNED_VALUE.toString()); + test.done(); + }, + + "max_sub_max": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_UNSIGNED_VALUE); + test.equal(longVal, 0); + test.equal(longVal.low, 0); + test.equal(longVal.high, 0); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 0); + test.equal(longVal.toString(), "0"); + test.done(); + }, + + "zero_sub_signed": function(test) { + var longVal = Long.fromInt(0, true).add(Long.fromInt(-1, false)); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "max_unsigned_div_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.MAX_SIGNED_VALUE); + test.equal(longVal.toNumber(), 2); + test.equal(longVal.toString(), "2"); + test.done(); + }, + + "max_unsigned_div_neg_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.fromInt(-2)); + test.equal(longVal.toNumber(), -Long.MAX_SIGNED_VALUE); + test.done(); + } + }, + + // FIXME: There is no support for NaN or +/-Infinity + // "NaN": function(test) { + // test.ok(isNan(Long.fromNumber(NaN).toNumber()); + // test.strictEqual(Long.fromNumber(+Infinity).toNumber(), +Infinity); + // test.strictEqual(Long.fromNumber(-Infinity).toNumber(), -Infinity); + // test.done(); + // } + // One option could be to store NaN, Infinity etc. in high and set low to 0, while making sure to convert it in a + // proper way as soon as any math is called upon it. This might be as simple as that each of these values always + // "infects" other values, thus remaining untouched respectively changing the base long to its value. + // + // To clarify that, it all becomes zero atm, which usually is good enough but not perfect: + "NaN": function(test) { + test.strictEqual(Long.fromNumber(NaN), Long.ZERO); + test.strictEqual(Long.fromNumber(+Infinity), Long.ZERO); + test.strictEqual(Long.fromNumber(-Infinity), Long.ZERO); + test.strictEqual(Long.fromString(NaN+""), Long.ZERO); + test.strictEqual(Long.fromString(+Infinity+""), Long.ZERO); + test.strictEqual(Long.fromString(-Infinity+""), Long.ZERO); + test.done(); + } +}; + +module.exports = suite; diff --git a/javascript/node_modules/protobufjs/.idea/.name b/javascript/node_modules/protobufjs/.idea/.name new file mode 100644 index 0000000..3dafbae --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/.name @@ -0,0 +1 @@ +ProtoBuf \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/.idea/ProtoBuf.iml b/javascript/node_modules/protobufjs/.idea/ProtoBuf.iml new file mode 100644 index 0000000..3b09ca3 --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/ProtoBuf.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/javascript/node_modules/protobufjs/.idea/encodings.xml b/javascript/node_modules/protobufjs/.idea/encodings.xml new file mode 100644 index 0000000..7c62b52 --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/javascript/node_modules/protobufjs/.idea/misc.xml b/javascript/node_modules/protobufjs/.idea/misc.xml new file mode 100644 index 0000000..262e5d3 --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/javascript/node_modules/protobufjs/.idea/modules.xml b/javascript/node_modules/protobufjs/.idea/modules.xml new file mode 100644 index 0000000..12858eb --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/javascript/node_modules/protobufjs/.idea/scopes/scope_settings.xml b/javascript/node_modules/protobufjs/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..0d5175c --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/.idea/vcs.xml b/javascript/node_modules/protobufjs/.idea/vcs.xml new file mode 100644 index 0000000..ab55cf1 --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/javascript/node_modules/protobufjs/.idea/workspace.xml b/javascript/node_modules/protobufjs/.idea/workspace.xml new file mode 100644 index 0000000..113f713 --- /dev/null +++ b/javascript/node_modules/protobufjs/.idea/workspace.xml @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1390062190314 + 1390062190314 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/javascript/node_modules/protobufjs/.npmignore b/javascript/node_modules/protobufjs/.npmignore new file mode 100644 index 0000000..baf03f8 --- /dev/null +++ b/javascript/node_modules/protobufjs/.npmignore @@ -0,0 +1,2 @@ +node_modules/ +npm-debug.log diff --git a/javascript/node_modules/protobufjs/.travis.yml b/javascript/node_modules/protobufjs/.travis.yml new file mode 100644 index 0000000..a118245 --- /dev/null +++ b/javascript/node_modules/protobufjs/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 + - 0.10 diff --git a/javascript/node_modules/protobufjs/LICENSE b/javascript/node_modules/protobufjs/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/protobufjs/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/protobufjs/NOTICE b/javascript/node_modules/protobufjs/NOTICE new file mode 100644 index 0000000..3d38810 --- /dev/null +++ b/javascript/node_modules/protobufjs/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) ProtoBuf.js by Daniel 'dcode' Wirtz +See: https://github.com/dcodeIO/ProtoBuf.js for details diff --git a/javascript/node_modules/protobufjs/ProtoBuf.js b/javascript/node_modules/protobufjs/ProtoBuf.js new file mode 100644 index 0000000..3b6813c --- /dev/null +++ b/javascript/node_modules/protobufjs/ProtoBuf.js @@ -0,0 +1,3721 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ProtoBuf.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ProtoBuf.js for details + */ +(function(global) { + "use strict"; + + function loadProtoBuf(ByteBuffer) { + + /** + * The ProtoBuf namespace. + * @exports ProtoBuf + * @namespace + * @expose + */ + var ProtoBuf = {}; + + /** + * ProtoBuf.js version. + * @type {string} + * @const + * @expose + */ + ProtoBuf.VERSION = "2.0.5"; + + /** + * Wire types. + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES = {}; + + /** + * Varint wire type. + * @type {number} + * @expose + */ + ProtoBuf.WIRE_TYPES.VARINT = 0; + + /** + * Fixed 64 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS64 = 1; + + /** + * Length delimited wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.LDELIM = 2; + + /** + * Start group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.STARTGROUP = 3; + + /** + * End group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.ENDGROUP = 4; + + /** + * Fixed 32 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS32 = 5; + + /** + * Types. + * @dict + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.TYPES = { + // According to the protobuf spec. + "int32": { + name: "int32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint32": { + name: "uint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint32": { + name: "sint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "int64": { + name: "int64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint64": { + name: "uint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint64": { + name: "sint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "bool": { + name: "bool", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "double": { + name: "double", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "string": { + name: "string", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "bytes": { + name: "bytes", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "fixed32": { + name: "fixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "sfixed32": { + name: "sfixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "fixed64": { + name: "fixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "sfixed64": { + name: "sfixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "float": { + name: "float", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "enum": { + name: "enum", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "message": { + name: "message", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + } + }; + + /** + * @type {?Long} + */ + ProtoBuf.Long = ByteBuffer.Long; + + /** + * If set to `true`, field names will be converted from underscore notation to camel case. Defaults to `false`. + * Must be set prior to parsing. + * @type {boolean} + * @expose + */ + ProtoBuf.convertFieldsToCamelCase = false; + + /** + * @alias ProtoBuf.Util + * @expose + */ + ProtoBuf.Util = (function() { + "use strict"; + + // Object.create polyfill + // ref: https://developer.mozilla.org/de/docs/JavaScript/Reference/Global_Objects/Object/create + if (!Object.create) { + /** @expose */ + Object.create = function (o) { + if (arguments.length > 1) { + throw new Error('Object.create implementation only accepts the first parameter.'); + } + function F() {} + F.prototype = o; + return new F(); + }; + } + + /** + * ProtoBuf utilities. + * @exports ProtoBuf.Util + * @namespace + */ + var Util = {}; + + /** + * Flag if running in node or not. + * @type {boolean} + * @const + * @expose + */ + Util.IS_NODE = (typeof window === 'undefined' || !window.window) && typeof require === 'function' && typeof process !== 'undefined' && typeof process["nextTick"] === 'function'; + + /** + * Constructs a XMLHttpRequest object. + * @return {XMLHttpRequest} + * @throws {Error} If XMLHttpRequest is not supported + * @expose + */ + Util.XHR = function() { + // No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html + var XMLHttpFactories = [ + function () {return new XMLHttpRequest()}, + function () {return new ActiveXObject("Msxml2.XMLHTTP")}, + function () {return new ActiveXObject("Msxml3.XMLHTTP")}, + function () {return new ActiveXObject("Microsoft.XMLHTTP")} + ]; + /** @type {?XMLHttpRequest} */ + var xhr = null; + for (var i=0;i} + * @namespace + * @expose + */ + var Lang = { // Look, so cute! + OPEN: "{", + CLOSE: "}", + OPTOPEN: "[", + OPTCLOSE: "]", + OPTEND: ",", + EQUAL: "=", + END: ";", + STRINGOPEN: '"', + STRINGCLOSE: '"', + COPTOPEN: '(', + COPTCLOSE: ')', + + DELIM: /[\s\{\}=;\[\],"\(\)]/g, + + KEYWORD: /^(?:package|option|import|message|enum|extend|service|syntax|extensions)$/, + RULE: /^(?:required|optional|repeated)$/, + TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/, + NAME: /^[a-zA-Z][a-zA-Z_0-9]*$/, + OPTNAME: /^(?:[a-zA-Z][a-zA-Z_0-9]*|\([a-zA-Z][a-zA-Z_0-9]*\))$/, + TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/, + TYPEREF: /^(?:\.?[a-zA-Z][a-zA-Z_0-9]*)+$/, + FQTYPEREF: /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/, + NUMBER: /^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+)$/, + NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/, + NUMBER_HEX: /^0x[0-9a-fA-F]+$/, + NUMBER_OCT: /^0[0-7]+$/, + NUMBER_FLT: /^[0-9]*\.[0-9]+$/, + ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + WHITESPACE: /\s/, + STRING: /"([^"\\]*(\\.[^"\\]*)*)"/g, + BOOL: /^(?:true|false)$/i, + + ID_MIN: 1, + ID_MAX: 0x1FFFFFFF + }; + return Lang; + })(); + + /** + * Utilities to parse .proto files. + * @namespace + * @expose + */ + ProtoBuf.DotProto = {}; // Not present in "noparse" builds + + /** + * @alias ProtoBuf.DotProto.Tokenizer + * @expose + */ + ProtoBuf.DotProto.Tokenizer = (function(Lang) { + + /** + * Constructs a new Tokenizer. + * @exports ProtoBuf.DotProto.Tokenizer + * @class A ProtoBuf .proto Tokenizer. + * @param {string} proto Proto to tokenize + * @constructor + */ + var Tokenizer = function(proto) { + + /** + * Source to parse. + * @type {string} + * @expose + */ + this.source = ""+proto; + + /** + * Current index. + * @type {number} + * @expose + */ + this.index = 0; + + /** + * Current line. + * @type {number} + * @expose + */ + this.line = 1; + + /** + * Stacked values. + * @type {Array} + * @expose + */ + this.stack = []; + + /** + * Whether currently reading a string or not. + * @type {boolean} + * @expose + */ + this.readingString = false; + }; + + /** + * Reads a string beginning at the current index. + * @return {string} The string + * @throws {Error} If it's not a valid string + * @private + */ + Tokenizer.prototype._readString = function() { + Lang.STRING.lastIndex = this.index-1; // Include the open quote + var match; + if ((match = Lang.STRING.exec(this.source)) !== null) { + var s = match[1]; + this.index = Lang.STRING.lastIndex; + this.stack.push(Lang.STRINGCLOSE); + return s; + } + throw(new Error("Illegal string value at line "+this.line+", index "+this.index)); + }; + + /** + * Gets the next token and advances by one. + * @return {?string} Token or `null` on EOF + * @throws {Error} If it's not a valid proto file + * @expose + */ + Tokenizer.prototype.next = function() { + if (this.stack.length > 0) { + return this.stack.shift(); + } + if (this.index >= this.source.length) { + return null; // No more tokens + } + if (this.readingString) { + this.readingString = false; + return this._readString(); + } + var repeat, last; + do { + repeat = false; + // Strip white spaces + while (Lang.WHITESPACE.test(last = this.source.charAt(this.index))) { + this.index++; + if (last === "\n") this.line++; + if (this.index === this.source.length) return null; + } + // Strip comments + if (this.source.charAt(this.index) === '/') { + if (this.source.charAt(++this.index) === '/') { // Single line + while (this.source.charAt(this.index) !== "\n") { + this.index++; + if (this.index == this.source.length) return null; + } + this.index++; + this.line++; + repeat = true; + } else if (this.source.charAt(this.index) === '*') { /* Block */ + last = ''; + while (last+(last=this.source.charAt(this.index)) !== '*/') { + this.index++; + if (last === "\n") this.line++; + if (this.index === this.source.length) return null; + } + this.index++; + repeat = true; + } else { + throw(new Error("Invalid comment at line "+this.line+": /"+this.source.charAt(this.index)+" ('/' or '*' expected)")); + } + } + } while (repeat); + if (this.index === this.source.length) return null; + + // Read the next token + var end = this.index; + Lang.DELIM.lastIndex = 0; + var delim = Lang.DELIM.test(this.source.charAt(end)); + if (!delim) { + end++; + while(end < this.source.length && !Lang.DELIM.test(this.source.charAt(end))) { + end++; + } + } else { + end++; + } + var token = this.source.substring(this.index, this.index = end); + if (token === Lang.STRINGOPEN) { + this.readingString = true; + } + return token; + }; + + /** + * Peeks for the next token. + * @return {?string} Token or `null` on EOF + * @throws {Error} If it's not a valid proto file + * @expose + */ + Tokenizer.prototype.peek = function() { + if (this.stack.length == 0) { + var token = this.next(); + if (token === null) return null; + this.stack.push(token); + } + return this.stack[0]; + }; + + /** + * Returns a string representation of this object. + * @return {string} String representation as of "Tokenizer(index/length)" + * @expose + */ + Tokenizer.prototype.toString = function() { + return "Tokenizer("+this.index+"/"+this.source.length+" at line "+this.line+")"; + }; + + return Tokenizer; + + })(ProtoBuf.Lang); + + /** + * @alias ProtoBuf.DotProto.Parser + * @expose + */ + ProtoBuf.DotProto.Parser = (function(ProtoBuf, Lang, Tokenizer) { + "use strict"; + + /** + * Constructs a new Parser. + * @exports ProtoBuf.DotProto.Parser + * @class A ProtoBuf .proto parser. + * @param {string} proto Protocol source + * @constructor + */ + var Parser = function(proto) { + + /** + * Tokenizer. + * @type {ProtoBuf.DotProto.Tokenizer} + * @expose + */ + this.tn = new Tokenizer(proto); + }; + + /** + * Runs the parser. + * @return {{package: string|null, messages: Array., enums: Array., imports: Array., options: object}} + * @throws {Error} If the source cannot be parsed + * @expose + */ + Parser.prototype.parse = function() { + var topLevel = { + "name": "[ROOT]", // temporary + "package": null, + "messages": [], + "enums": [], + "imports": [], + "options": {}, + "services": [] + }; + var token, header = true; + do { + token = this.tn.next(); + if (token == null) { + break; // No more messages + } + if (token == 'package') { + if (!header) { + throw(new Error("Illegal package definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + if (topLevel["package"] !== null) { + throw(new Error("Illegal package definition at line "+this.tn.line+": Package already declared")); + } + topLevel["package"] = this._parsePackage(token); + } else if (token == 'import') { + if (!header) { + throw(new Error("Illegal import definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + topLevel.imports.push(this._parseImport(token)); + } else if (token === 'message') { + this._parseMessage(topLevel, token); + header = false; + } else if (token === 'enum') { + this._parseEnum(topLevel, token); + header = false; + } else if (token === 'option') { + if (!header) { + throw(new Error("Illegal option definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + this._parseOption(topLevel, token); + } else if (token === 'service') { + this._parseService(topLevel, token); + } else if (token === 'extend') { + this._parseExtend(topLevel, token); + } else if (token === 'syntax') { + this._parseIgnoredStatement(topLevel, token); + } else { + throw(new Error("Illegal top level declaration at line "+this.tn.line+": "+token)); + } + } while (true); + delete topLevel["name"]; + return topLevel; + }; + + /** + * Parses a number value. + * @param {string} val Number value to parse + * @return {number} Number + * @throws {Error} If the number value is invalid + * @private + */ + Parser.prototype._parseNumber = function(val) { + var sign = 1; + if (val.charAt(0) == '-') { + sign = -1; val = val.substring(1); + } + if (Lang.NUMBER_DEC.test(val)) { + return sign*parseInt(val, 10); + } else if (Lang.NUMBER_HEX.test(val)) { + return sign*parseInt(val.substring(2), 16); + } else if (Lang.NUMBER_OCT.test(val)) { + return sign*parseInt(val.substring(1), 8); + } else if (Lang.NUMBER_FLT.test(val)) { + return sign*parseFloat(val); + } + throw(new Error("Illegal number value at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + }; + + /** + * Parses an ID value. + * @param {string} val ID value to parse + * @param {boolean=} neg Whether the ID may be negative, defaults to `false` + * @returns {number} ID + * @throws {Error} If the ID value is invalid + * @private + */ + Parser.prototype._parseId = function(val, neg) { + var id = -1; + var sign = 1; + if (val.charAt(0) == '-') { + sign = -1; val = val.substring(1); + } + if (Lang.NUMBER_DEC.test(val)) { + id = parseInt(val); + } else if (Lang.NUMBER_HEX.test(val)) { + id = parseInt(val.substring(2), 16); + } else if (Lang.NUMBER_OCT.test(val)) { + id = parseInt(val.substring(1), 8); + } else { + throw(new Error("Illegal ID value at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + } + id = (sign*id)|0; // Force to 32bit + if (!neg && id < 0) { + throw(new Error("Illegal ID range at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + } + return id; + }; + + /** + * Parses the package definition. + * @param {string} token Initial token + * @return {string} Package name + * @throws {Error} If the package definition cannot be parsed + * @private + */ + Parser.prototype._parsePackage = function(token) { + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal package name at line "+this.tn.line+": "+token)); + } + var pkg = token; + token = this.tn.next(); + if (token != Lang.END) { + throw(new Error("Illegal end of package definition at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return pkg; + }; + + /** + * Parses an import definition. + * @param {string} token Initial token + * @return {string} Import file name + * @throws {Error} If the import definition cannot be parsed + * @private + */ + Parser.prototype._parseImport = function(token) { + token = this.tn.next(); + if (token === "public") { + token = this.tn.next(); + } + if (token !== Lang.STRINGOPEN) { + throw(new Error("Illegal begin of import value at line "+this.tn.line+": "+token+" ('"+Lang.STRINGOPEN+"' expected)")); + } + var imported = this.tn.next(); + token = this.tn.next(); + if (token !== Lang.STRINGCLOSE) { + throw(new Error("Illegal end of import value at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal end of import definition at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return imported; + }; + + /** + * Parses a namespace option. + * @param {Object} parent Parent definition + * @param {string} token Initial token + * @throws {Error} If the option cannot be parsed + * @private + */ + Parser.prototype._parseOption = function(parent, token) { + token = this.tn.next(); + var custom = false; + if (token == Lang.COPTOPEN) { + custom = true; + token = this.tn.next(); + } + if (!Lang.NAME.test(token)) { + // we can allow options of the form google.protobuf.* since they will just get ignored anyways + if (!/google\.protobuf\./.test(token)) { + throw(new Error("Illegal option name in message "+parent.name+" at line "+this.tn.line+": "+token)); + } + } + var name = token; + token = this.tn.next(); + if (custom) { // (my_method_option).foo, (my_method_option), some_method_option + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal custom option name delimiter in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")); + } + name = '('+name+')'; + token = this.tn.next(); + if (Lang.FQTYPEREF.test(token)) { + name += token; + token = this.tn.next(); + } + } + if (token !== Lang.EQUAL) { + throw(new Error("Illegal option operator in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + var value; + token = this.tn.next(); + if (token === Lang.STRINGOPEN) { + value = this.tn.next(); + token = this.tn.next(); + if (token !== Lang.STRINGCLOSE) { + throw(new Error("Illegal end of option value in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + } else { + if (Lang.NUMBER.test(token)) { + value = this._parseNumber(token, true); + } else if (Lang.TYPEREF.test(token)) { + value = token; + } else { + throw(new Error("Illegal option value in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token)); + } + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal end of option in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + parent["options"][name] = value; + }; + + /** + * Parses an ignored block of the form ['keyword', 'typeref', '{' ... '}']. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the directive cannot be parsed + * @private + */ + Parser.prototype._parseIgnoredBlock = function(parent, keyword) { + var token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal "+keyword+" type in "+parent.name+": "+token)); + } + var name = token; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN in "+parent.name+" after "+keyword+" "+name+" at line "+this.tn.line+": "+token)); + } + var depth = 1; + do { + token = this.tn.next(); + if (token === null) { + throw(new Error("Unexpected EOF in "+parent.name+", "+keyword+" (ignored) at line "+this.tn.line+": "+name)); + } + if (token === Lang.OPEN) { + depth++; + } else if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + depth--; + if (depth === 0) { + break; + } + } + } while(true); + }; + + /** + * Parses an ignored statement of the form ['keyword', ..., ';']. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the directive cannot be parsed + * @private + */ + Parser.prototype._parseIgnoredStatement = function(parent, keyword) { + var token; + do { + token = this.tn.next(); + if (token === null) { + throw(new Error("Unexpected EOF in "+parent.name+", "+keyword+" (ignored) at line "+this.tn.line)); + } + if (token === Lang.END) break; + } while (true); + }; + + /** + * Parses a service definition. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the service cannot be parsed + * @private + */ + Parser.prototype._parseService = function(parent, keyword) { + var token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal service name at line "+this.tn.line+": "+token)); + } + var name = token; + var svc = { + "name": name, + "rpc": {}, + "options": {} + }; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN after service "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + do { + token = this.tn.next(); + if (token === "option") { + this._parseOption(svc, token); + } else if (token === 'rpc') { + this._parseServiceRPC(svc, token); + } else if (token !== Lang.CLOSE) { + throw(new Error("Illegal type for service "+name+" at line "+this.tn.line+": "+token)); + } + } while (token !== Lang.CLOSE); + parent["services"].push(svc); + }; + + /** + * Parses a RPC service definition of the form ['rpc', name, (request), 'returns', (response)]. + * @param {Object} svc Parent definition + * @param {string} token Initial token + * @private + */ + Parser.prototype._parseServiceRPC = function(svc, token) { + var type = token; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal RPC method name in service "+svc["name"]+" at line "+this.tn.line+": "+token)); + } + var name = token; + var method = { + "request": null, + "response": null, + "options": {} + }; + token = this.tn.next(); + if (token !== Lang.COPTOPEN) { + throw(new Error("Illegal start of request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTOPEN+"' expected)")); + } + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token)); + } + method["request"] = token; + token = this.tn.next(); + if (token != Lang.COPTCLOSE) { + throw(new Error("Illegal end of request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")) + } + token = this.tn.next(); + if (token.toLowerCase() !== "returns") { + throw(new Error("Illegal request/response delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('returns' expected)")); + } + token = this.tn.next(); + if (token != Lang.COPTOPEN) { + throw(new Error("Illegal start of response type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTOPEN+"' expected)")); + } + token = this.tn.next(); + method["response"] = token; + token = this.tn.next(); + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal end of response type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")) + } + token = this.tn.next(); + if (token === Lang.OPEN) { + do { + token = this.tn.next(); + if (token === 'option') { + this._parseOption(method, token); // <- will fail for the custom-options example + } else if (token !== Lang.CLOSE) { + throw(new Error("Illegal start of option in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('option' expected)")); + } + } while (token !== Lang.CLOSE); + } else if (token !== Lang.END) { + throw(new Error("Illegal method delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' or '"+Lang.OPEN+"' expected)")); + } + if (typeof svc[type] === 'undefined') svc[type] = {}; + svc[type][name] = method; + }; + + /** + * Parses a message definition. + * @param {Object} parent Parent definition + * @param {string} token First token + * @return {Object} + * @throws {Error} If the message cannot be parsed + * @private + */ + Parser.prototype._parseMessage = function(parent, token) { + /** @dict */ + var msg = {}; // Note: At some point we might want to exclude the parser, so we need a dict. + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal message name"+(parent ? " in message "+parent["name"] : "")+" at line "+this.tn.line+": "+token)); + } + msg["name"] = token; + token = this.tn.next(); + if (token != Lang.OPEN) { + throw(new Error("Illegal OPEN after message "+msg.name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + msg["fields"] = []; // Note: Using arrays to support also browser that cannot preserve order of object keys. + msg["enums"] = []; + msg["messages"] = []; + msg["options"] = {}; + // msg["extensions"] = undefined + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + break; + } else if (Lang.RULE.test(token)) { + this._parseMessageField(msg, token); + } else if (token === "enum") { + this._parseEnum(msg, token); + } else if (token === "message") { + this._parseMessage(msg, token); + } else if (token === "option") { + this._parseOption(msg, token); + } else if (token === "extensions") { + msg["extensions"] = this._parseExtensions(msg, token); + } else if (token === "extend") { + this._parseExtend(msg, token); + } else { + throw(new Error("Illegal token in message "+msg.name+" at line "+this.tn.line+": "+token+" (type or '"+Lang.CLOSE+"' expected)")); + } + } while (true); + parent["messages"].push(msg); + return msg; + }; + + /** + * Parses a message field. + * @param {Object} msg Message definition + * @param {string} token Initial token + * @throws {Error} If the message field cannot be parsed + * @private + */ + Parser.prototype._parseMessageField = function(msg, token) { + /** @dict */ + var fld = {}; + fld["rule"] = token; + token = this.tn.next(); + if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token)) { + throw(new Error("Illegal field type in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + fld["type"] = token; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal field name in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + fld["name"] = token; + token = this.tn.next(); + if (token !== Lang.EQUAL) { + throw(new Error("Illegal field number operator in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + token = this.tn.next(); + try { + fld["id"] = this._parseId(token); + } catch (e) { + throw(new Error("Illegal field id in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + /** @dict */ + fld["options"] = {}; + token = this.tn.next(); + if (token === Lang.OPTOPEN) { + this._parseFieldOptions(msg, fld, token); + token = this.tn.next(); + } + if (token !== Lang.END) { + throw(new Error("Illegal field delimiter in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + msg["fields"].push(fld); + }; + + /** + * Parses a set of field option definitions. + * @param {Object} msg Message definition + * @param {Object} fld Field definition + * @param {string} token Initial token + * @throws {Error} If the message field options cannot be parsed + * @private + */ + Parser.prototype._parseFieldOptions = function(msg, fld, token) { + var first = true; + do { + token = this.tn.next(); + if (token === Lang.OPTCLOSE) { + break; + } else if (token === Lang.OPTEND) { + if (first) { + throw(new Error("Illegal start of message field options in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + token = this.tn.next(); + } + this._parseFieldOption(msg, fld, token); + first = false; + } while (true); + }; + + /** + * Parses a single field option. + * @param {Object} msg Message definition + * @param {Object} fld Field definition + * @param {string} token Initial token + * @throws {Error} If the mesage field option cannot be parsed + * @private + */ + Parser.prototype._parseFieldOption = function(msg, fld, token) { + var custom = false; + if (token === Lang.COPTOPEN) { + token = this.tn.next(); + custom = true; + } + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal field option in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + var name = token; + token = this.tn.next(); + if (custom) { + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal custom field option name delimiter in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" (')' expected)")); + } + name = '('+name+')'; + token = this.tn.next(); + if (Lang.FQTYPEREF.test(token)) { + name += token; + token = this.tn.next(); + } + } + if (token !== Lang.EQUAL) { + throw(new Error("Illegal field option operation in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('=' expected)")); + } + var value; + token = this.tn.next(); + if (token === Lang.STRINGOPEN) { + value = this.tn.next(); + token = this.tn.next(); + if (token != Lang.STRINGCLOSE) { + throw(new Error("Illegal end of field value in message "+msg.name+"#"+fld.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + } else if (Lang.NUMBER.test(token, true)) { + value = this._parseNumber(token, true); + } else if (Lang.BOOL.test(token)) { + value = token.toLowerCase() === 'true'; + } else if (Lang.TYPEREF.test(token)) { + value = token; // TODO: Resolve? + } else { + throw(new Error("Illegal field option value in message "+msg.name+"#"+fld.name+", option "+name+" at line "+this.tn.line+": "+token)); + } + fld["options"][name] = value; + }; + + /** + * Parses an enum. + * @param {Object} msg Message definition + * @param {string} token Initial token + * @throws {Error} If the enum cannot be parsed + * @private + */ + Parser.prototype._parseEnum = function(msg, token) { + /** @dict */ + var enm = {}; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal enum name in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + enm["name"] = token; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN after enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + enm["values"] = []; + enm["options"] = {}; + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + break; + } + if (token == 'option') { + this._parseOption(enm, token); + } else { + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal enum value name in enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + this._parseEnumValue(enm, token); + } + } while (true); + msg["enums"].push(enm); + }; + + /** + * Parses an enum value. + * @param {Object} enm Enum definition + * @param {string} token Initial token + * @throws {Error} If the enum value cannot be parsed + * @private + */ + Parser.prototype._parseEnumValue = function(enm, token) { + /** @dict */ + var val = {}; + val["name"] = token; + token = this.tn.next(); + if (token !== Lang.EQUAL) { + throw(new Error("Illegal enum value operator in enum "+enm.name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + token = this.tn.next(); + try { + val["id"] = this._parseId(token, true); + } catch (e) { + throw(new Error("Illegal enum value id in enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + enm["values"].push(val); + token = this.tn.next(); + if (token === Lang.OPTOPEN) { + var opt = { 'options' : {} }; // TODO: Actually expose them somehow. + this._parseFieldOptions(enm, opt, token); + token = this.tn.next(); + } + if (token !== Lang.END) { + throw(new Error("Illegal enum value delimiter in enum "+enm.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + }; + + /** + * Parses an extensions statement. + * @param {Object} msg Message object + * @param {string} token Initial token + * @throws {Error} If the extensions statement cannot be parsed + * @private + */ + Parser.prototype._parseExtensions = function(msg, token) { + /** @type {Array.} */ + var range = []; + token = this.tn.next(); + if (token === "min") { // FIXME: Does the official implementation support this? + range.push(Lang.ID_MIN); + } else if (token === "max") { + range.push(Lang.ID_MAX); + } else { + range.push(this._parseNumber(token)); + } + token = this.tn.next(); + if (token !== 'to') { + throw("Illegal extensions delimiter in message "+msg.name+" at line "+this.tn.line+" ('to' expected)"); + } + token = this.tn.next(); + if (token === "min") { + range.push(Lang.ID_MIN); + } else if (token === "max") { + range.push(Lang.ID_MAX); + } else { + range.push(this._parseNumber(token)); + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal extension delimiter in message "+msg.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return range; + }; + + /** + * Parses an extend block. + * @param {Object} parent Parent object + * @param {string} token Initial token + * @throws {Error} If the extend block cannot be parsed + * @private + */ + Parser.prototype._parseExtend = function(parent, token) { + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal extended message name at line "+this.tn.line+": "+token)); + } + /** @dict */ + var ext = {}; + ext["ref"] = token; + ext["fields"] = []; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN in extend "+ext.name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token == Lang.END) this.tn.next(); + break; + } else if (Lang.RULE.test(token)) { + this._parseMessageField(ext, token); + } else { + throw(new Error("Illegal token in extend "+ext.name+" at line "+this.tn.line+": "+token+" (rule or '"+Lang.CLOSE+"' expected)")); + } + } while (true); + parent["messages"].push(ext); + return ext; + }; + + /** + * Returns a string representation of this object. + * @returns {string} String representation as of "Parser" + */ + Parser.prototype.toString = function() { + return "Parser"; + }; + + return Parser; + + })(ProtoBuf, ProtoBuf.Lang, ProtoBuf.DotProto.Tokenizer); + + /** + * @alias ProtoBuf.Reflect + * @expose + */ + ProtoBuf.Reflect = (function(ProtoBuf) { + "use strict"; + + /** + * @exports ProtoBuf.Reflect + * @namespace + */ + var Reflect = {}; + + /** + * Constructs a Reflect base class. + * @exports ProtoBuf.Reflect.T + * @constructor + * @param {ProtoBuf.Reflect.T} parent Parent object + * @param {string} name Object name + */ + var T = function(parent, name) { + /** + * Parent object. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.parent = parent; + + /** + * Object name in namespace. + * @type {string} + * @expose + */ + this.name = name; + }; + + /** + * Returns the fully qualified name of this object. + * @returns {string} Fully qualified name as of ".PATH.TO.THIS" + * @expose + */ + T.prototype.fqn = function() { + var name = this.name, + ptr = this; + do { + ptr = ptr.parent; + if (ptr == null) break; + name = ptr.name+"."+name; + } while (true); + return name; + }; + + /** + * Returns a string representation of this Reflect object (its fully qualified name). + * @param {boolean=} includeClass Set to true to include the class name. Defaults to false. + * @return String representation + * @expose + */ + T.prototype.toString = function(includeClass) { + var name = this.fqn(); + if (includeClass) { + if (this instanceof Message) { + name = "Message "+name; + } else if (this instanceof Message.Field) { + name = "Message.Field "+name; + } else if (this instanceof Enum) { + name = "Enum "+name; + } else if (this instanceof Enum.Value) { + name = "Enum.Value "+name; + } else if (this instanceof Service) { + name = "Service "+name; + } else if (this instanceof Service.Method) { + if (this instanceof Service.RPCMethod) { + name = "Service.RPCMethod "+name; + } else { + name = "Service.Method "+name; // Should not happen as it is abstract + } + } else if (this instanceof Namespace) { + name = "Namespace "+name; + } + } + return name; + }; + + /** + * Builds this type. + * @throws {Error} If this type cannot be built directly + * @expose + */ + T.prototype.build = function() { + throw(new Error(this.toString(true)+" cannot be built directly")); + }; + + /** + * @alias ProtoBuf.Reflect.T + * @expose + */ + Reflect.T = T; + + /** + * Constructs a new Namespace. + * @exports ProtoBuf.Reflect.Namespace + * @param {ProtoBuf.Reflect.Namespace|null} parent Namespace parent + * @param {string} name Namespace name + * @param {Object.} options Namespace options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Namespace = function(parent, name, options) { + T.call(this, parent, name); + + /** + * Children inside the namespace. + * @type {Array.} + */ + this.children = []; + + /** + * Options. + * @type {Object.} + */ + this.options = options || {}; + }; + + // Extends T + Namespace.prototype = Object.create(T.prototype); + + /** + * Returns an array of the namespace's children. + * @param {ProtoBuf.Reflect.T=} type Filter type (returns instances of this type only). Defaults to null (all children). + * @return {Array.} + * @expose + */ + Namespace.prototype.getChildren = function(type) { + type = type || null; + if (type == null) { + return this.children.slice(); + } + var children = []; + for (var i=0; i} Runtime namespace + * @expose + */ + Namespace.prototype.build = function() { + /** @dict */ + var ns = {}; + var children = this.getChildren(), child; + for (var i=0; i} + */ + Namespace.prototype.buildOpt = function() { + var opt = {}; + var keys = Object.keys(this.options); + for (var i=0; i}null} Option value or NULL if there is no such option + */ + Namespace.prototype.getOption = function(name) { + if (typeof name == 'undefined') { + return this.options; + } + return typeof this.options[name] != 'undefined' ? this.options[name] : null; + }; + + /** + * @alias ProtoBuf.Reflect.Namespace + * @expose + */ + Reflect.Namespace = Namespace; + + /** + * Constructs a new Message. + * @exports ProtoBuf.Reflect.Message + * @param {ProtoBuf.Reflect.Namespace} parent Parent message or namespace + * @param {string} name Message name + * @param {Object.} options Message options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Message = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Extensions range. + * @type {!Array.} + * @expose + */ + this.extensions = [ProtoBuf.Lang.ID_MIN, ProtoBuf.Lang.ID_MAX]; + + /** + * Runtime message class. + * @type {?function(new:ProtoBuf.Builder.Message)} + * @expose + */ + this.clazz = null; + }; + + // Extends Namespace + Message.prototype = Object.create(Namespace.prototype); + + /** + * Builds the message and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Message + * @param {boolean=} rebuild Whether to rebuild or not, defaults to false + * @return {ProtoBuf.Reflect.Message} Message class + * @throws {Error} If the message cannot be built + * @expose + */ + Message.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + + // We need to create a prototyped Message class in an isolated scope + var clazz = (function(ProtoBuf, T) { + var fields = T.getChildren(Reflect.Message.Field); + + /** + * Constructs a new runtime Message. + * @name ProtoBuf.Builder.Message + * @class Barebone of all runtime messages. + * @param {Object.|...[string]} values Preset values + * @constructor + * @throws {Error} If the message cannot be created + */ + var Message = function(values) { + ProtoBuf.Builder.Message.call(this); + var i, field; + + // Create fields on the object itself to allow setting and getting through Message#fieldname + for (i=0; i} + * @expose + */ + var O_o; // for cc + + if (Object.defineProperty) { + Object.defineProperty(Message, '$options', { + 'value': T.buildOpt(), + 'enumerable': false, + 'configurable': false, + 'writable': false + }); + } + + return Message; + + })(ProtoBuf, this); + + // Static enums and prototyped sub-messages + var children = this.getChildren(); + for (var i=0; i 0)) { + var tag = buffer.readVarint32(); + var wireType = tag & 0x07, + id = tag >> 3; + var field = this.getChild(id); // Message.Field only + if (!field) { + // "messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing." + switch (wireType) { + case ProtoBuf.WIRE_TYPES.VARINT: + buffer.readVarint32(); + break; + case ProtoBuf.WIRE_TYPES.BITS32: + buffer.offset += 4; + break; + case ProtoBuf.WIRE_TYPES.BITS64: + buffer.offset += 8; + break; + case ProtoBuf.WIRE_TYPES.LDELIM: + var len = buffer.readVarint32(); + buffer.offset += len; + break; + default: + throw(new Error("Illegal wire type of unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType)); + } + continue; + } + if (field.repeated && !field.options["packed"]) { + msg.add(field.name, field.decode(wireType, buffer)); + } else { + msg.set(field.name, field.decode(wireType, buffer)); + } + } + // Check if all required fields are present + var fields = this.getChildren(ProtoBuf.Reflect.Field); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Field = function(message, rule, type, name, id, options) { + T.call(this, message, name); + + /** + * Message field required flag. + * @type {boolean} + * @expose + */ + this.required = rule == "required"; + + /** + * Message field repeated flag. + * @type {boolean} + * @expose + */ + this.repeated = rule == "repeated"; + + /** + * Message field type. Type reference string if unresolved, protobuf type if resolved. + * @type {string|{name: string, wireType: number} + * @expose + */ + this.type = type; + + /** + * Resolved type reference inside the global namespace. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.resolvedType = null; + + /** + * Unique message field id. + * @type {number} + * @expose + */ + this.id = id; + + /** + * Message field options. + * @type {!Object.} + * @dict + * @expose + */ + this.options = options || {}; + + /** + * Original field name. + * @type {string} + * @expose + */ + this.originalName = this.name; // Used to revert camelcase transformation on naming collisions + + // Convert field names to camel case notation if the override is set + if (ProtoBuf.convertFieldsToCamelCase) { + this.name = this.name.replace(/_([a-zA-Z])/g, function($0, $1) { + return $1.toUpperCase(); + }); + } + }; + + // Extends T + Field.prototype = Object.create(T.prototype); + + /** + * Checks if the given value can be set for this field. + * @param {*} value Value to check + * @param {boolean=} skipRepeated Whether to skip the repeated value check or not. Defaults to false. + * @return {*} Verified, maybe adjusted, value + * @throws {Error} If the value cannot be set for this field + * @expose + */ + Field.prototype.verifyValue = function(value, skipRepeated) { + skipRepeated = skipRepeated || false; + if (value === null) { // NULL values for optional fields + if (this.required) { + throw(new Error("Illegal value for "+this.toString(true)+": "+value+" (required)")); + } + return null; + } + var i; + if (this.repeated && !skipRepeated) { // Repeated values as arrays + if (!ProtoBuf.Util.isArray(value)) { + value = [value]; + } + var res = []; + for (i=0; i>> 0; // Do not cast NaN as it'd become 0 + } + if (ProtoBuf.Long) { + // Signed 64bit + if (this.type == ProtoBuf.TYPES["int64"] || this.type == ProtoBuf.TYPES["sint64"] || this.type == ProtoBuf.TYPES["sfixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, false); + } + return value.unsigned ? value.toSigned() : value; + } + // Unsigned 64bit + if (this.type == ProtoBuf.TYPES["uint64"] || this.type == ProtoBuf.TYPES["fixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, true); + } + return value.unsigned ? value : value.toUnsigned(); + } + } + // Bool + if (this.type == ProtoBuf.TYPES["bool"]) { + if (typeof value === 'string') return value === 'true'; + else return !!value; + } + // Float + if (this.type == ProtoBuf.TYPES["float"] || this.type == ProtoBuf.TYPES["double"]) { + return parseFloat(value); // May also become NaN, +Infinity, -Infinity + } + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]) { + return ""+value; + } + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + if (value && value instanceof ByteBuffer) { + return value; + } + return ByteBuffer.wrap(value); + } + // Constant enum value + if (this.type == ProtoBuf.TYPES["enum"]) { + var values = this.resolvedType.getChildren(Enum.Value); + for (i=0; i 1) { // We need to move the contents + var contents = buffer.slice(start, buffer.offset); + start += varintLen-1; + buffer.offset = start; + buffer.append(contents); + } + buffer.writeVarint32(len, start-varintLen); + } else { + // "If your message definition has repeated elements (without the [packed=true] option), the encoded + // message has zero or more key-value pairs with the same tag number" + for (i=0; i value.length) { // Forgot to flip? + buffer = buffer.clone().flip(); + } + buffer.writeVarint32(value.remaining()); + buffer.append(value); + + // Embedded message + } else if (this.type == ProtoBuf.TYPES["message"]) { + var bb = new ByteBuffer().LE(); + this.resolvedType.encode(value, bb); + buffer.writeVarint32(bb.offset); + buffer.append(bb.flip()); + } else { + // We should never end here + throw(new Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)")); + } + return buffer; + }; + + /** + * Decode the field value from the specified buffer. + * @param {number} wireType Leading wire type + * @param {ByteBuffer} buffer ByteBuffer to decode from + * @param {boolean=} skipRepeated Whether to skip the repeated check or not. Defaults to false. + * @return {*} Decoded value + * @throws {Error} If the field cannot be decoded + * @expose + */ + Field.prototype.decode = function(wireType, buffer, skipRepeated) { + var value, nBytes; + if (wireType != this.type.wireType && (skipRepeated || (wireType != ProtoBuf.WIRE_TYPES.LDELIM || !this.repeated))) { + throw(new Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)")); + } + if (wireType == ProtoBuf.WIRE_TYPES.LDELIM && this.repeated && this.options["packed"]) { + if (!skipRepeated) { + nBytes = buffer.readVarint32(); + nBytes = buffer.offset + nBytes; // Limit + var values = []; + while (buffer.offset < nBytes) { + values.push(this.decode(this.type.wireType, buffer, true)); + } + return values; + } + // Read the next value otherwise... + + } + // 32bit signed varint + if (this.type == ProtoBuf.TYPES["int32"]) { + return buffer.readVarint32() | 0; + } + + // 32bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint32"]) { + return buffer.readVarint32() >>> 0; + } + + // 32bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint32"]) { + return buffer.readZigZagVarint32() | 0; + } + + // Fixed 32bit unsigned + if (this.type == ProtoBuf.TYPES["fixed32"]) { + return buffer.readUint32() >>> 0; + } + + // Fixed 32bit signed + if (this.type == ProtoBuf.TYPES["sfixed32"]) { + return buffer.readInt32() | 0; + } + + // 64bit signed varint + if (this.type == ProtoBuf.TYPES["int64"]) { + return buffer.readVarint64(); + } + + // 64bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint64"]) { + return buffer.readVarint64().toUnsigned(); + } + + // 64bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint64"]) { + return buffer.readZigZagVarint64(); + } + + // Fixed 64bit unsigned + if (this.type == ProtoBuf.TYPES["fixed64"]) { + return buffer.readUint64(); + } + + // Fixed 64bit signed + if (this.type == ProtoBuf.TYPES["sfixed64"]) { + return buffer.readInt64(); + } + + // Bool varint + if (this.type == ProtoBuf.TYPES["bool"]) { + return !!buffer.readVarint32(); + } + + // Constant enum value varint) + if (this.type == ProtoBuf.TYPES["enum"]) { + return buffer.readVarint32(); // The following Builder.Message#set will already throw + } + + // 32bit float + if (this.type == ProtoBuf.TYPES["float"]) { + return buffer.readFloat(); + } + // 64bit float + if (this.type == ProtoBuf.TYPES["double"]) { + return buffer.readDouble(); + } + + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]){ + return buffer.readVString(); + } + + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + nBytes = buffer.readVarint32(); + if (buffer.remaining() < nBytes) { + throw(new Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining())); + } + value = buffer.clone(); // Offset already set + value.length = value.offset+nBytes; + buffer.offset += nBytes; + return value; + } + + // Length-delimited embedded message + if (this.type == ProtoBuf.TYPES["message"]) { + nBytes = buffer.readVarint32(); + return this.resolvedType.decode(buffer, nBytes); + } + + // We should never end here + throw(new Error("[INTERNAL] Illegal wire type for "+this.toString(true)+": "+wireType)); + }; + + /** + * @alias ProtoBuf.Reflect.Message.Field + * @expose + */ + Reflect.Message.Field = Field; + + /** + * Constructs a new Enum. + * @exports ProtoBuf.Reflect.Enum + * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object + * @param {string} name Enum name + * @param {Object.=} options Enum options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Enum = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Runtime enum object. + * @type {Object.|null} + * @expose + */ + this.object = null; + }; + + // Extends Namespace + Enum.prototype = Object.create(Namespace.prototype); + + /** + * Builds this enum and returns the runtime counterpart. + * @return {Object} + * @expose + */ + Enum.prototype.build = function() { + var enm = {}; + var values = this.getChildren(Enum.Value); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Service = function(root, name, options) { + Namespace.call(this, root, name, options); + + /** + * Built runtime service class. + * @type {?function(new:ProtoBuf.Builder.Service)} + */ + this.clazz = null; + }; + + // Extends Namespace + Service.prototype = Object.create(Namespace.prototype); + + /** + * Builds the service and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Service + * @param {boolean=} rebuild Whether to rebuild or not + * @return {Function} Service class + * @throws {Error} If the message cannot be built + * @expose + */ + Service.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + return this.clazz = (function(ProtoBuf, T) { + + /** + * Constructs a new runtime Service. + * @name ProtoBuf.Builder.Service + * @param {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))=} rpcImpl RPC implementation receiving the method name and the message + * @class Barebone of all runtime services. + * @constructor + * @throws {Error} If the service cannot be created + */ + var Service = function(rpcImpl) { + ProtoBuf.Builder.Service.call(this); + + /** + * Service implementation. + * @name ProtoBuf.Builder.Service#rpcImpl + * @type {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} + * @expose + */ + this.rpcImpl = rpcImpl || function(name, msg, callback) { + // This is what a user has to implement: A function receiving the method name, the actual message to + // send (type checked) and the callback that's either provided with the error as its first + // argument or null and the actual response message. + setTimeout(callback.bind(this, new Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0); // Must be async! + }; + }; + + // Extends ProtoBuf.Builder.Service + Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype); + + if (Object.defineProperty) { + Object.defineProperty(Service, "$options", { + "value": T.buildOpt(), + "enumerable": false, + "configurable": false, + "writable": false + }); + Object.defineProperty(Service.prototype, "$options", { + "value": Service["$options"], + "enumerable": false, + "configurable": false, + "writable": false + }); + } + + /** + * Asynchronously performs an RPC call using the given RPC implementation. + * @name ProtoBuf.Builder.Service.[Method] + * @function + * @param {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} rpcImpl RPC implementation + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + /** + * Asynchronously performs an RPC call using the instance's RPC implementation. + * @name ProtoBuf.Builder.Service#[Method] + * @function + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + var rpc = T.getChildren(Reflect.Service.RPCMethod); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Method = function(svc, name, options) { + T.call(this, svc, name); + + /** + * Options. + * @type {Object.} + * @expose + */ + this.options = options || {}; + }; + + // Extends T + Method.prototype = Object.create(T.prototype); + + /** + * Builds the method's '$options' property. + * @name ProtoBuf.Reflect.Service.Method#buildOpt + * @function + * @return {Object.} + */ + Method.prototype.buildOpt = Namespace.prototype.buildOpt; + + /** + * @alias ProtoBuf.Reflect.Service.Method + * @expose + */ + Reflect.Service.Method = Method; + + /** + * RPC service method. + * @exports ProtoBuf.Reflect.Service.RPCMethod + * @param {!ProtoBuf.Reflect.Service} svc Service + * @param {string} name Method name + * @param {string} request Request message name + * @param {string} response Response message name + * @param {Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Service.Method + */ + var RPCMethod = function(svc, name, request, response, options) { + Method.call(this, svc, name, options); + + /** + * Request message name. + * @type {string} + * @expose + */ + this.requestName = request; + + /** + * Response message name. + * @type {string} + * @expose + */ + this.responseName = response; + + /** + * Resolved request message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedRequestType = null; + + /** + * Resolved response message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedResponseType = null; + }; + + // Extends Method + RPCMethod.prototype = Object.create(Method.prototype); + + /** + * @alias ProtoBuf.Reflect.Service.RPCMethod + * @expose + */ + Reflect.Service.RPCMethod = RPCMethod; + + return Reflect; + })(ProtoBuf); + + /** + * @alias ProtoBuf.Builder + * @expose + */ + ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) { + "use strict"; + + /** + * Constructs a new Builder. + * @exports ProtoBuf.Builder + * @class Provides the functionality to build protocol messages. + * @constructor + */ + var Builder = function() { + + /** + * Namespace. + * @type {ProtoBuf.Reflect.Namespace} + * @expose + */ + this.ns = new Reflect.Namespace(null, ""); // Global namespace + + /** + * Namespace pointer. + * @type {ProtoBuf.Reflect.T} + * @expose + */ + this.ptr = this.ns; + + /** + * Resolved flag. + * @type {boolean} + * @expose + */ + this.resolved = false; + + /** + * The current building result. + * @type {Object.|null} + * @expose + */ + this.result = null; + + /** + * Imported files. + * @type {Array.} + * @expose + */ + this.files = {}; + + /** + * Import root override. + * @type {?string} + * @expose + */ + this.importRoot = null; + }; + + /** + * Resets the pointer to the global namespace. + * @expose + */ + Builder.prototype.reset = function() { + this.ptr = this.ns; + }; + + /** + * Defines a package on top of the current pointer position and places the pointer on it. + * @param {string} pkg + * @param {Object.=} options + * @return {ProtoBuf.Builder} this + * @throws {Error} If the package name is invalid + * @expose + */ + Builder.prototype.define = function(pkg, options) { + if (typeof pkg !== 'string' || !Lang.TYPEREF.test(pkg)) { + throw(new Error("Illegal package name: "+pkg)); + } + var part = pkg.split("."), i; + for (i=0; i} def Definition + * @return {boolean} true if valid, else false + * @expose + */ + Builder.isValidMessage = function(def) { + // Messages require a string name + if (typeof def["name"] !== 'string' || !Lang.NAME.test(def["name"])) { + return false; + } + // Messages must not contain values (that'd be an enum) or methods (that'd be a service) + if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined') { + return false; + } + // Fields, enums and messages are arrays if provided + var i; + if (typeof def["fields"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["fields"])) { + return false; + } + var ids = [], id; // IDs must be unique + for (i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + if (typeof def["enums"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["enums"])) { + return false; + } + for (i=0; i + var keys = Object.keys(def["options"]); + for (var i=0; i>} defs Messages, enums or services to create + * @return {ProtoBuf.Builder} this + * @throws {Error} If a message definition is invalid + * @expose + */ + Builder.prototype.create = function(defs) { + if (!defs) return; // Nothing to create + if (!ProtoBuf.Util.isArray(defs)) { + defs = [defs]; + } + if (defs.length == 0) return; + + // It's quite hard to keep track of scopes and memory here, so let's do this iteratively. + var stack = [], def, obj, subObj, i, j; + stack.push(defs); // One level [a, b, c] + while (stack.length > 0) { + defs = stack.pop(); + if (ProtoBuf.Util.isArray(defs)) { // Stack always contains entire namespaces + while (defs.length > 0) { + def = defs.shift(); // Namespace always contains an array of messages, enums and services + if (Builder.isValidMessage(def)) { + obj = new Reflect.Message(this.ptr, def["name"], def["options"]); + // Create fields + if (def["fields"] && def["fields"].length > 0) { + for (i=0; i 0) { + for (i=0; i 0) { + for (i=0; i ProtoBuf.Lang.ID_MAX) { + obj.extensions[1] = ProtoBuf.Lang.ID_MAX; + } + } + this.ptr.addChild(obj); // Add to current namespace + if (subObj.length > 0) { + stack.push(defs); // Push the current level back + defs = subObj; // Continue processing sub level + subObj = null; + this.ptr = obj; // And move the pointer to this namespace + obj = null; + continue; + } + subObj = null; + obj = null; + } else if (Builder.isValidEnum(def)) { + obj = new Reflect.Enum(this.ptr, def["name"], def["options"]); + for (i=0; i obj.extensions[1]) { + throw(new Error("Illegal extended field id in message "+obj.name+": "+def['fields'][i]['id']+" ("+obj.extensions.join(' to ')+" expected)")); + } + obj.addChild(new Reflect.Message.Field(obj, def["fields"][i]["rule"], def["fields"][i]["type"], def["fields"][i]["name"], def["fields"][i]["id"], def["fields"][i]["options"])); + } + /* if (this.ptr instanceof Reflect.Message) { + this.ptr.addChild(obj); // Reference the extended message here to enable proper lookups + } */ + } else { + if (!/\.?google\.protobuf\./.test(def["ref"])) { // Silently skip internal extensions + throw(new Error("Extended message "+def["ref"]+" is not defined")); + } + } + } else { + throw(new Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(def))); + } + def = null; + } + // Break goes here + } else { + throw(new Error("Not a valid namespace definition: "+JSON.stringify(defs))); + } + defs = null; + this.ptr = this.ptr.parent; // This namespace is s done + } + this.resolved = false; // Require re-resolve + this.result = null; // Require re-build + return this; + }; + + /** + * Tests if the specified file is a valid import. + * @param {string} filename + * @returns {boolean} true if valid, false if it should be skipped + * @expose + */ + Builder.isValidImport = function(filename) { + // Ignore google/protobuf/descriptor.proto (for example) as it makes use of low-level + // bootstrapping directives that are not required and therefore cannot be parsed by ProtoBuf.js. + return !(/google\/protobuf\//.test(filename)); + }; + + /** + * Imports another definition into this builder. + * @param {Object.} json Parsed import + * @param {(string|{root: string, file: string})=} filename Imported file name + * @return {ProtoBuf.Builder} this + * @throws {Error} If the definition or file cannot be imported + * @expose + */ + Builder.prototype["import"] = function(json, filename) { + if (typeof filename === 'string') { + if (ProtoBuf.Util.IS_NODE) { + var path = require("path"); + filename = path.resolve(filename); + } + if (!!this.files[filename]) { + this.reset(); + return this; // Skip duplicate imports + } + this.files[filename] = true; + } + if (!!json['imports'] && json['imports'].length > 0) { + var importRoot, delim = '/', resetRoot = false; + if (typeof filename === 'object') { // If an import root is specified, override + this.importRoot = filename["root"]; resetRoot = true; // ... and reset afterwards + importRoot = this.importRoot; + filename = filename["file"]; + if (importRoot.indexOf("\\") >= 0 || filename.indexOf("\\") >= 0) delim = '\\'; + } else if (typeof filename === 'string') { + if (this.importRoot) { // If import root is overridden, use it + importRoot = this.importRoot; + } else { // Otherwise compute from filename + if (filename.indexOf("/") >= 0) { // Unix + importRoot = filename.replace(/\/[^\/]*$/, ""); + if (/* /file.proto */ importRoot === "") importRoot = "/"; + } else if (filename.indexOf("\\") >= 0) { // Windows + importRoot = filename.replace(/\\[^\\]*$/, ""); delim = '\\'; + } else { + importRoot = "."; + } + } + } else { + importRoot = null; + } + + for (var i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + return true; + }; + + /** + * Resolves all namespace objects. + * @throws {Error} If a type cannot be resolved + * @expose + */ + Builder.prototype.resolveAll = function() { + // Resolve all reflected objects + var res; + if (this.ptr == null || typeof this.ptr.type === 'object') return; // Done (already resolved) + if (this.ptr instanceof Reflect.Namespace) { + // Build all children + var children = this.ptr.getChildren(); + for (var i=0; i} + * @throws {Error} If a type could not be resolved + * @expose + */ + Builder.prototype.build = function(path) { + this.reset(); + if (!this.resolved) { + this.resolveAll(); + this.resolved = true; + this.result = null; // Require re-build + } + if (this.result == null) { // (Re-)Build + this.result = this.ns.build(); + } + if (!path) { + return this.result; + } else { + var part = path.split("."); + var ptr = this.result; // Build namespace pointer (no hasChild etc.) + for (var i=0; i=} options Top level options + * @return {ProtoBuf.Builder} New Builder + * @expose + */ + ProtoBuf.newBuilder = function(pkg, options) { + var builder = new ProtoBuf.Builder(); + if (typeof pkg !== 'undefined' && pkg !== null) { + builder.define(pkg, options); + } + return builder; + }; + + /** + * Loads a .json definition and returns the Builder. + * @param {!*|string} json JSON definition + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted. + * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports. + * @return {ProtoBuf.Builder} Builder to create new messages + * @throws {Error} If the definition cannot be parsed or built + * @expose + */ + ProtoBuf.loadJson = function(json, builder, filename) { + if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string')) { + filename = builder; + builder = null; + } + if (!builder || typeof builder !== 'object') builder = ProtoBuf.newBuilder(); + if (typeof json === 'string') json = JSON.parse(json); + builder["import"](json, filename); + builder.resolveAll(); + builder.build(); + return builder; + }; + + /** + * Loads a .json file and returns the Builder. + * @param {string|{root: string, file: string}} filename Path to json file or an object specifying 'file' with + * an overridden 'root' path for all imported files. + * @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. + * If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + * function will return the Builder or NULL if the request has failed. + * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted. + * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the + * request has failed), else undefined + * @expose + */ + ProtoBuf.loadJsonFile = function(filename, callback, builder) { + if (callback && typeof callback === 'object') { + builder = callback; + callback = null; + } else if (!callback || typeof callback !== 'function') { + callback = null; + } + if (callback) { + ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename, function(contents) { + try { + callback(ProtoBuf.loadJson(JSON.parse(contents), builder, filename)); + } catch (err) { + callback(err); + } + }); + } else { + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents !== null ? ProtoBuf.loadJson(JSON.parse(contents), builder, filename) : null; + } + }; + + return ProtoBuf; + } + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadProtoBuf(require("bytebuffer")); + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("ProtoBuf", ["ByteBuffer"], loadProtoBuf); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["ProtoBuf"] = loadProtoBuf(global["dcodeIO"]["ByteBuffer"]); + } + +})(this); \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/ProtoBuf.min.js b/javascript/node_modules/protobufjs/ProtoBuf.min.js new file mode 100644 index 0000000..9e56c0a --- /dev/null +++ b/javascript/node_modules/protobufjs/ProtoBuf.min.js @@ -0,0 +1,93 @@ +/* + ProtoBuf.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/ProtoBuf.js for details +*/ +(function(r){function s(p){var g={VERSION:"2.0.5",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT}, +bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64},"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT}, +message:{name:"message",wireType:g.WIRE_TYPES.LDELIM}};g.Long=p.Long;g.convertFieldsToCamelCase=!1;g.Util=function(){Object.create||(Object.create=function(b){function c(){}if(1=this.source.length)return null;if(this.readingString)return this.readingString=!1,this._readString();var b,k;do{for(b=!1;c.WHITESPACE.test(k=this.source.charAt(this.index));)if(this.index++,"\n"===k&&this.line++,this.index===this.source.length)return null;if("/"===this.source.charAt(this.index))if("/"===this.source.charAt(++this.index)){for(;"\n"!==this.source.charAt(this.index);)if(this.index++,this.index==this.source.length)return null;this.index++;this.line++;b=!0}else if("*"=== +this.source.charAt(this.index)){for(k="";"*/"!==k+(k=this.source.charAt(this.index));)if(this.index++,"\n"===k&&this.line++,this.index===this.source.length)return null;this.index++;b=!0}else throw Error("Invalid comment at line "+this.line+": /"+this.source.charAt(this.index)+" ('/' or '*' expected)");}while(b);if(this.index===this.source.length)return null;b=this.index;c.DELIM.lastIndex=0;if(c.DELIM.test(this.source.charAt(b)))b++;else for(b++;ba?"-":"")+c);};c.prototype._parseId=function(c,a){var d=-1,e=1;"-"==c.charAt(0)&& +(e=-1,c=c.substring(1));if(b.NUMBER_DEC.test(c))d=parseInt(c);else if(b.NUMBER_HEX.test(c))d=parseInt(c.substring(2),16);else if(b.NUMBER_OCT.test(c))d=parseInt(c.substring(1),8);else throw Error("Illegal ID value at line "+this.tn.line+": "+(0>e?"-":"")+c);d=e*d|0;if(!a&&0>d)throw Error("Illegal ID range at line "+this.tn.line+": "+(0>e?"-":"")+c);return d};c.prototype._parsePackage=function(c){c=this.tn.next();if(!b.TYPEREF.test(c))throw Error("Illegal package name at line "+this.tn.line+": "+c); +var a=c;c=this.tn.next();if(c!=b.END)throw Error("Illegal end of package definition at line "+this.tn.line+": "+c+" ('"+b.END+"' expected)");return a};c.prototype._parseImport=function(c){c=this.tn.next();"public"===c&&(c=this.tn.next());if(c!==b.STRINGOPEN)throw Error("Illegal begin of import value at line "+this.tn.line+": "+c+" ('"+b.STRINGOPEN+"' expected)");var a=this.tn.next();c=this.tn.next();if(c!==b.STRINGCLOSE)throw Error("Illegal end of import value at line "+this.tn.line+": "+c+" ('"+ +b.STRINGCLOSE+"' expected)");c=this.tn.next();if(c!==b.END)throw Error("Illegal end of import definition at line "+this.tn.line+": "+c+" ('"+b.END+"' expected)");return a};c.prototype._parseOption=function(c,a){a=this.tn.next();var d=!1;a==b.COPTOPEN&&(d=!0,a=this.tn.next());if(!b.NAME.test(a)&&!/google\.protobuf\./.test(a))throw Error("Illegal option name in message "+c.name+" at line "+this.tn.line+": "+a);var e=a;a=this.tn.next();if(d){if(a!==b.COPTCLOSE)throw Error("Illegal custom option name delimiter in message "+ +c.name+", option "+e+" at line "+this.tn.line+": "+a+" ('"+b.COPTCLOSE+"' expected)");e="("+e+")";a=this.tn.next();b.FQTYPEREF.test(a)&&(e+=a,a=this.tn.next())}if(a!==b.EQUAL)throw Error("Illegal option operator in message "+c.name+", option "+e+" at line "+this.tn.line+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(a===b.STRINGOPEN){if(d=this.tn.next(),a=this.tn.next(),a!==b.STRINGCLOSE)throw Error("Illegal end of option value in message "+c.name+", option "+e+" at line "+this.tn.line+": "+ +a+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(a))d=this._parseNumber(a,!0);else if(b.TYPEREF.test(a))d=a;else throw Error("Illegal option value in message "+c.name+", option "+e+" at line "+this.tn.line+": "+a);a=this.tn.next();if(a!==b.END)throw Error("Illegal end of option in message "+c.name+", option "+e+" at line "+this.tn.line+": "+a+" ('"+b.END+"' expected)");c.options[e]=d};c.prototype._parseIgnoredBlock=function(c,a){var d=this.tn.next();if(!b.TYPEREF.test(d))throw Error("Illegal "+ +a+" type in "+c.name+": "+d);var e=d,d=this.tn.next();if(d!==b.OPEN)throw Error("Illegal OPEN in "+c.name+" after "+a+" "+e+" at line "+this.tn.line+": "+d);var h=1;do{d=this.tn.next();if(null===d)throw Error("Unexpected EOF in "+c.name+", "+a+" (ignored) at line "+this.tn.line+": "+e);if(d===b.OPEN)h++;else if(d===b.CLOSE&&(d=this.tn.peek(),d===b.END&&this.tn.next(),h--,0===h))break}while(1)};c.prototype._parseIgnoredStatement=function(c,a){var d;do{d=this.tn.next();if(null===d)throw Error("Unexpected EOF in "+ +c.name+", "+a+" (ignored) at line "+this.tn.line);if(d===b.END)break}while(1)};c.prototype._parseService=function(c,a){var d=this.tn.next();if(!b.NAME.test(d))throw Error("Illegal service name at line "+this.tn.line+": "+d);var e=d,h={name:e,rpc:{},options:{}},d=this.tn.next();if(d!==b.OPEN)throw Error("Illegal OPEN after service "+e+" at line "+this.tn.line+": "+d+" ('"+b.OPEN+"' expected)");do if(d=this.tn.next(),"option"===d)this._parseOption(h,d);else if("rpc"===d)this._parseServiceRPC(h,d);else if(d!== +b.CLOSE)throw Error("Illegal type for service "+e+" at line "+this.tn.line+": "+d);while(d!==b.CLOSE);c.services.push(h)};c.prototype._parseServiceRPC=function(c,a){var d=a;a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal RPC method name in service "+c.name+" at line "+this.tn.line+": "+a);var e=a,h={request:null,response:null,options:{}};a=this.tn.next();if(a!==b.COPTOPEN)throw Error("Illegal start of request type in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('"+b.COPTOPEN+ +"' expected)");a=this.tn.next();if(!b.TYPEREF.test(a))throw Error("Illegal request type in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a);h.request=a;a=this.tn.next();if(a!=b.COPTCLOSE)throw Error("Illegal end of request type in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('"+b.COPTCLOSE+"' expected)");a=this.tn.next();if("returns"!==a.toLowerCase())throw Error("Illegal request/response delimiter in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('returns' expected)"); +a=this.tn.next();if(a!=b.COPTOPEN)throw Error("Illegal start of response type in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('"+b.COPTOPEN+"' expected)");a=this.tn.next();h.response=a;a=this.tn.next();if(a!==b.COPTCLOSE)throw Error("Illegal end of response type in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('"+b.COPTCLOSE+"' expected)");a=this.tn.next();if(a===b.OPEN){do if(a=this.tn.next(),"option"===a)this._parseOption(h,a);else if(a!==b.CLOSE)throw Error("Illegal start of option in RPC service "+ +c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('option' expected)");while(a!==b.CLOSE)}else if(a!==b.END)throw Error("Illegal method delimiter in RPC service "+c.name+"#"+e+" at line "+this.tn.line+": "+a+" ('"+b.END+"' or '"+b.OPEN+"' expected)");"undefined"===typeof c[d]&&(c[d]={});c[d][e]=h};c.prototype._parseMessage=function(c,a){var d={};a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal message name"+(c?" in message "+c.name:"")+" at line "+this.tn.line+": "+a);d.name=a;a=this.tn.next(); +if(a!=b.OPEN)throw Error("Illegal OPEN after message "+d.name+" at line "+this.tn.line+": "+a+" ('"+b.OPEN+"' expected)");d.fields=[];d.enums=[];d.messages=[];d.options={};do if(a=this.tn.next(),a===b.CLOSE){a=this.tn.peek();a===b.END&&this.tn.next();break}else if(b.RULE.test(a))this._parseMessageField(d,a);else if("enum"===a)this._parseEnum(d,a);else if("message"===a)this._parseMessage(d,a);else if("option"===a)this._parseOption(d,a);else if("extensions"===a)d.extensions=this._parseExtensions(d, +a);else if("extend"===a)this._parseExtend(d,a);else throw Error("Illegal token in message "+d.name+" at line "+this.tn.line+": "+a+" (type or '"+b.CLOSE+"' expected)");while(1);c.messages.push(d);return d};c.prototype._parseMessageField=function(c,a){var d={};d.rule=a;a=this.tn.next();if(!b.TYPE.test(a)&&!b.TYPEREF.test(a))throw Error("Illegal field type in message "+c.name+" at line "+this.tn.line+": "+a);d.type=a;a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal field name in message "+c.name+ +" at line "+this.tn.line+": "+a);d.name=a;a=this.tn.next();if(a!==b.EQUAL)throw Error("Illegal field number operator in message "+c.name+"#"+d.name+" at line "+this.tn.line+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();try{d.id=this._parseId(a)}catch(e){throw Error("Illegal field id in message "+c.name+"#"+d.name+" at line "+this.tn.line+": "+a);}d.options={};a=this.tn.next();a===b.OPTOPEN&&(this._parseFieldOptions(c,d,a),a=this.tn.next());if(a!==b.END)throw Error("Illegal field delimiter in message "+ +c.name+"#"+d.name+" at line "+this.tn.line+": "+a+" ('"+b.END+"' expected)");c.fields.push(d)};c.prototype._parseFieldOptions=function(c,a,d){var e=!0;do{d=this.tn.next();if(d===b.OPTCLOSE)break;else if(d===b.OPTEND){if(e)throw Error("Illegal start of message field options in message "+c.name+"#"+a.name+" at line "+this.tn.line+": "+d);d=this.tn.next()}this._parseFieldOption(c,a,d);e=!1}while(1)};c.prototype._parseFieldOption=function(c,a,d){var e=!1;d===b.COPTOPEN&&(d=this.tn.next(),e=!0);if(!b.NAME.test(d))throw Error("Illegal field option in message "+ +c.name+"#"+a.name+" at line "+this.tn.line+": "+d);var h=d;d=this.tn.next();if(e){if(d!==b.COPTCLOSE)throw Error("Illegal custom field option name delimiter in message "+c.name+"#"+a.name+" at line "+this.tn.line+": "+d+" (')' expected)");h="("+h+")";d=this.tn.next();b.FQTYPEREF.test(d)&&(h+=d,d=this.tn.next())}if(d!==b.EQUAL)throw Error("Illegal field option operation in message "+c.name+"#"+a.name+" at line "+this.tn.line+": "+d+" ('=' expected)");d=this.tn.next();if(d===b.STRINGOPEN){if(e=this.tn.next(), +d=this.tn.next(),d!=b.STRINGCLOSE)throw Error("Illegal end of field value in message "+c.name+"#"+a.name+", option "+h+" at line "+this.tn.line+": "+d+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(d,!0))e=this._parseNumber(d,!0);else if(b.BOOL.test(d))e="true"===d.toLowerCase();else if(b.TYPEREF.test(d))e=d;else throw Error("Illegal field option value in message "+c.name+"#"+a.name+", option "+h+" at line "+this.tn.line+": "+d);a.options[h]=e};c.prototype._parseEnum=function(c,a){var d= +{};a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal enum name in message "+c.name+" at line "+this.tn.line+": "+a);d.name=a;a=this.tn.next();if(a!==b.OPEN)throw Error("Illegal OPEN after enum "+d.name+" at line "+this.tn.line+": "+a);d.values=[];d.options={};do{a=this.tn.next();if(a===b.CLOSE){a=this.tn.peek();a===b.END&&this.tn.next();break}if("option"==a)this._parseOption(d,a);else{if(!b.NAME.test(a))throw Error("Illegal enum value name in enum "+d.name+" at line "+this.tn.line+": "+a); +this._parseEnumValue(d,a)}}while(1);c.enums.push(d)};c.prototype._parseEnumValue=function(c,a){var d={};d.name=a;a=this.tn.next();if(a!==b.EQUAL)throw Error("Illegal enum value operator in enum "+c.name+" at line "+this.tn.line+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();try{d.id=this._parseId(a,!0)}catch(e){throw Error("Illegal enum value id in enum "+c.name+" at line "+this.tn.line+": "+a);}c.values.push(d);a=this.tn.next();a===b.OPTOPEN&&(this._parseFieldOptions(c,{options:{}},a),a=this.tn.next()); +if(a!==b.END)throw Error("Illegal enum value delimiter in enum "+c.name+" at line "+this.tn.line+": "+a+" ('"+b.END+"' expected)");};c.prototype._parseExtensions=function(c,a){var d=[];a=this.tn.next();"min"===a?d.push(b.ID_MIN):"max"===a?d.push(b.ID_MAX):d.push(this._parseNumber(a));a=this.tn.next();if("to"!==a)throw"Illegal extensions delimiter in message "+c.name+" at line "+this.tn.line+" ('to' expected)";a=this.tn.next();"min"===a?d.push(b.ID_MIN):"max"===a?d.push(b.ID_MAX):d.push(this._parseNumber(a)); +a=this.tn.next();if(a!==b.END)throw Error("Illegal extension delimiter in message "+c.name+" at line "+this.tn.line+": "+a+" ('"+b.END+"' expected)");return d};c.prototype._parseExtend=function(c,a){a=this.tn.next();if(!b.TYPEREF.test(a))throw Error("Illegal extended message name at line "+this.tn.line+": "+a);var d={};d.ref=a;d.fields=[];a=this.tn.next();if(a!==b.OPEN)throw Error("Illegal OPEN in extend "+d.name+" at line "+this.tn.line+": "+a+" ('"+b.OPEN+"' expected)");do if(a=this.tn.next(),a=== +b.CLOSE){a=this.tn.peek();a==b.END&&this.tn.next();break}else if(b.RULE.test(a))this._parseMessageField(d,a);else throw Error("Illegal token in extend "+d.name+" at line "+this.tn.line+": "+a+" (rule or '"+b.CLOSE+"' expected)");while(1);c.messages.push(d);return d};c.prototype.toString=function(){return"Parser"};return c}(g,g.Lang,g.DotProto.Tokenizer);g.Reflect=function(c){var b={},g=function(a,c){this.parent=a;this.name=c};g.prototype.fqn=function(){var a=this.name,c=this;do{c=c.parent;if(null== +c)break;a=c.name+"."+a}while(1);return a};g.prototype.toString=function(c){var b=this.fqn();c&&(this instanceof a?b="Message "+b:this instanceof a.Field?b="Message.Field "+b:this instanceof e?b="Enum "+b:this instanceof e.Value?b="Enum.Value "+b:this instanceof h?b="Service "+b:this instanceof h.Method?b=this instanceof h.RPCMethod?"Service.RPCMethod "+b:"Service.Method "+b:this instanceof k&&(b="Namespace "+b));return b};g.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly"); +};b.T=g;var k=function(a,c,b){g.call(this,a,c);this.children=[];this.options=b||{}};k.prototype=Object.create(g.prototype);k.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],b=0;b>3,k=this.getChild(h);if(k)k.repeated&&!k.options.packed? +e.add(k.name,k.decode(g,a)):e.set(k.name,k.decode(g,a));else switch(g){case c.WIRE_TYPES.VARINT:a.readVarint32();break;case c.WIRE_TYPES.BITS32:a.offset+=4;break;case c.WIRE_TYPES.BITS64:a.offset+=8;break;case c.WIRE_TYPES.LDELIM:g=a.readVarint32();a.offset+=g;break;default:throw Error("Illegal wire type of unknown field "+h+" in "+this.toString(!0)+"#decode: "+g);}}d=this.getChildren(c.Reflect.Field);for(g=0;g>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==c.TYPES.sint64||this.type==c.TYPES.sfixed64)return"object"==typeof a&&a instanceof c.Long?a.unsigned?a.toSigned():a:c.Long.fromNumber(a,!1);if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return"object"==typeof a&&a instanceof c.Long?a.unsigned?a:a.toUnsigned():c.Long.fromNumber(a,!0)}if(this.type==c.TYPES.bool)return"string"===typeof a?"true"===a:!!a;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(a); +if(this.type==c.TYPES.string)return""+a;if(this.type==c.TYPES.bytes)return a&&a instanceof p?a:p.wrap(a);if(this.type==c.TYPES["enum"]){h=this.resolvedType.getChildren(e.Value);for(d=0;da.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=(new p).LE();this.resolvedType.encode(a, +d);b.writeVarint32(d.offset);b.append(d.flip())}else throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64(); +if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes){a=b.readVarint32();if(b.remaining()c.Lang.ID_MAX&&(h.extensions[1]=c.Lang.ID_MAX));this.ptr.addChild(h);0h.extensions[1])throw Error("Illegal extended field id in message "+h.name+": "+e.fields[f].id+" ("+h.extensions.join(" to ")+" expected)");h.addChild(new g.Message.Field(h,e.fields[f].rule, +e.fields[f].type,e.fields[f].name,e.fields[f].id,e.fields[f].options))}else{if(!/\.?google\.protobuf\./.test(e.ref))throw Error("Extended message "+e.ref+" is not defined");}else throw Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};k.isValidImport=function(a){return!/google\/protobuf\//.test(a)};k.prototype["import"]= +function(a,b){if("string"===typeof b){c.Util.IS_NODE&&(b=require("path").resolve(b));if(this.files[b])return this.reset(),this;this.files[b]=!0}if(a.imports&&0 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ProtoBuf.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ProtoBuf.js for details + */ +(function(global) { + "use strict"; + + function loadProtoBuf(ByteBuffer) { + + /** + * The ProtoBuf namespace. + * @exports ProtoBuf + * @namespace + * @expose + */ + var ProtoBuf = {}; + + /** + * ProtoBuf.js version. + * @type {string} + * @const + * @expose + */ + ProtoBuf.VERSION = "2.0.5"; + + /** + * Wire types. + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES = {}; + + /** + * Varint wire type. + * @type {number} + * @expose + */ + ProtoBuf.WIRE_TYPES.VARINT = 0; + + /** + * Fixed 64 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS64 = 1; + + /** + * Length delimited wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.LDELIM = 2; + + /** + * Start group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.STARTGROUP = 3; + + /** + * End group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.ENDGROUP = 4; + + /** + * Fixed 32 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS32 = 5; + + /** + * Types. + * @dict + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.TYPES = { + // According to the protobuf spec. + "int32": { + name: "int32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint32": { + name: "uint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint32": { + name: "sint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "int64": { + name: "int64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint64": { + name: "uint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint64": { + name: "sint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "bool": { + name: "bool", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "double": { + name: "double", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "string": { + name: "string", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "bytes": { + name: "bytes", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "fixed32": { + name: "fixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "sfixed32": { + name: "sfixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "fixed64": { + name: "fixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "sfixed64": { + name: "sfixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "float": { + name: "float", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "enum": { + name: "enum", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "message": { + name: "message", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + } + }; + + /** + * @type {?Long} + */ + ProtoBuf.Long = ByteBuffer.Long; + + /** + * If set to `true`, field names will be converted from underscore notation to camel case. Defaults to `false`. + * Must be set prior to parsing. + * @type {boolean} + * @expose + */ + ProtoBuf.convertFieldsToCamelCase = false; + + /** + * @alias ProtoBuf.Util + * @expose + */ + ProtoBuf.Util = (function() { + "use strict"; + + // Object.create polyfill + // ref: https://developer.mozilla.org/de/docs/JavaScript/Reference/Global_Objects/Object/create + if (!Object.create) { + /** @expose */ + Object.create = function (o) { + if (arguments.length > 1) { + throw new Error('Object.create implementation only accepts the first parameter.'); + } + function F() {} + F.prototype = o; + return new F(); + }; + } + + /** + * ProtoBuf utilities. + * @exports ProtoBuf.Util + * @namespace + */ + var Util = {}; + + /** + * Flag if running in node or not. + * @type {boolean} + * @const + * @expose + */ + Util.IS_NODE = (typeof window === 'undefined' || !window.window) && typeof require === 'function' && typeof process !== 'undefined' && typeof process["nextTick"] === 'function'; + + /** + * Constructs a XMLHttpRequest object. + * @return {XMLHttpRequest} + * @throws {Error} If XMLHttpRequest is not supported + * @expose + */ + Util.XHR = function() { + // No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html + var XMLHttpFactories = [ + function () {return new XMLHttpRequest()}, + function () {return new ActiveXObject("Msxml2.XMLHTTP")}, + function () {return new ActiveXObject("Msxml3.XMLHTTP")}, + function () {return new ActiveXObject("Microsoft.XMLHTTP")} + ]; + /** @type {?XMLHttpRequest} */ + var xhr = null; + for (var i=0;i} + * @namespace + * @expose + */ + var Lang = { // Look, so cute! + OPEN: "{", + CLOSE: "}", + OPTOPEN: "[", + OPTCLOSE: "]", + OPTEND: ",", + EQUAL: "=", + END: ";", + STRINGOPEN: '"', + STRINGCLOSE: '"', + COPTOPEN: '(', + COPTCLOSE: ')', + + DELIM: /[\s\{\}=;\[\],"\(\)]/g, + + KEYWORD: /^(?:package|option|import|message|enum|extend|service|syntax|extensions)$/, + RULE: /^(?:required|optional|repeated)$/, + TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/, + NAME: /^[a-zA-Z][a-zA-Z_0-9]*$/, + OPTNAME: /^(?:[a-zA-Z][a-zA-Z_0-9]*|\([a-zA-Z][a-zA-Z_0-9]*\))$/, + TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/, + TYPEREF: /^(?:\.?[a-zA-Z][a-zA-Z_0-9]*)+$/, + FQTYPEREF: /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/, + NUMBER: /^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+)$/, + NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/, + NUMBER_HEX: /^0x[0-9a-fA-F]+$/, + NUMBER_OCT: /^0[0-7]+$/, + NUMBER_FLT: /^[0-9]*\.[0-9]+$/, + ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + WHITESPACE: /\s/, + STRING: /"([^"\\]*(\\.[^"\\]*)*)"/g, + BOOL: /^(?:true|false)$/i, + + ID_MIN: 1, + ID_MAX: 0x1FFFFFFF + }; + return Lang; + })(); + + // This build of ProtoBuf.js does not include DotProto support. + + /** + * @alias ProtoBuf.Reflect + * @expose + */ + ProtoBuf.Reflect = (function(ProtoBuf) { + "use strict"; + + /** + * @exports ProtoBuf.Reflect + * @namespace + */ + var Reflect = {}; + + /** + * Constructs a Reflect base class. + * @exports ProtoBuf.Reflect.T + * @constructor + * @param {ProtoBuf.Reflect.T} parent Parent object + * @param {string} name Object name + */ + var T = function(parent, name) { + /** + * Parent object. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.parent = parent; + + /** + * Object name in namespace. + * @type {string} + * @expose + */ + this.name = name; + }; + + /** + * Returns the fully qualified name of this object. + * @returns {string} Fully qualified name as of ".PATH.TO.THIS" + * @expose + */ + T.prototype.fqn = function() { + var name = this.name, + ptr = this; + do { + ptr = ptr.parent; + if (ptr == null) break; + name = ptr.name+"."+name; + } while (true); + return name; + }; + + /** + * Returns a string representation of this Reflect object (its fully qualified name). + * @param {boolean=} includeClass Set to true to include the class name. Defaults to false. + * @return String representation + * @expose + */ + T.prototype.toString = function(includeClass) { + var name = this.fqn(); + if (includeClass) { + if (this instanceof Message) { + name = "Message "+name; + } else if (this instanceof Message.Field) { + name = "Message.Field "+name; + } else if (this instanceof Enum) { + name = "Enum "+name; + } else if (this instanceof Enum.Value) { + name = "Enum.Value "+name; + } else if (this instanceof Service) { + name = "Service "+name; + } else if (this instanceof Service.Method) { + if (this instanceof Service.RPCMethod) { + name = "Service.RPCMethod "+name; + } else { + name = "Service.Method "+name; // Should not happen as it is abstract + } + } else if (this instanceof Namespace) { + name = "Namespace "+name; + } + } + return name; + }; + + /** + * Builds this type. + * @throws {Error} If this type cannot be built directly + * @expose + */ + T.prototype.build = function() { + throw(new Error(this.toString(true)+" cannot be built directly")); + }; + + /** + * @alias ProtoBuf.Reflect.T + * @expose + */ + Reflect.T = T; + + /** + * Constructs a new Namespace. + * @exports ProtoBuf.Reflect.Namespace + * @param {ProtoBuf.Reflect.Namespace|null} parent Namespace parent + * @param {string} name Namespace name + * @param {Object.} options Namespace options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Namespace = function(parent, name, options) { + T.call(this, parent, name); + + /** + * Children inside the namespace. + * @type {Array.} + */ + this.children = []; + + /** + * Options. + * @type {Object.} + */ + this.options = options || {}; + }; + + // Extends T + Namespace.prototype = Object.create(T.prototype); + + /** + * Returns an array of the namespace's children. + * @param {ProtoBuf.Reflect.T=} type Filter type (returns instances of this type only). Defaults to null (all children). + * @return {Array.} + * @expose + */ + Namespace.prototype.getChildren = function(type) { + type = type || null; + if (type == null) { + return this.children.slice(); + } + var children = []; + for (var i=0; i} Runtime namespace + * @expose + */ + Namespace.prototype.build = function() { + /** @dict */ + var ns = {}; + var children = this.getChildren(), child; + for (var i=0; i} + */ + Namespace.prototype.buildOpt = function() { + var opt = {}; + var keys = Object.keys(this.options); + for (var i=0; i}null} Option value or NULL if there is no such option + */ + Namespace.prototype.getOption = function(name) { + if (typeof name == 'undefined') { + return this.options; + } + return typeof this.options[name] != 'undefined' ? this.options[name] : null; + }; + + /** + * @alias ProtoBuf.Reflect.Namespace + * @expose + */ + Reflect.Namespace = Namespace; + + /** + * Constructs a new Message. + * @exports ProtoBuf.Reflect.Message + * @param {ProtoBuf.Reflect.Namespace} parent Parent message or namespace + * @param {string} name Message name + * @param {Object.} options Message options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Message = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Extensions range. + * @type {!Array.} + * @expose + */ + this.extensions = [ProtoBuf.Lang.ID_MIN, ProtoBuf.Lang.ID_MAX]; + + /** + * Runtime message class. + * @type {?function(new:ProtoBuf.Builder.Message)} + * @expose + */ + this.clazz = null; + }; + + // Extends Namespace + Message.prototype = Object.create(Namespace.prototype); + + /** + * Builds the message and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Message + * @param {boolean=} rebuild Whether to rebuild or not, defaults to false + * @return {ProtoBuf.Reflect.Message} Message class + * @throws {Error} If the message cannot be built + * @expose + */ + Message.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + + // We need to create a prototyped Message class in an isolated scope + var clazz = (function(ProtoBuf, T) { + var fields = T.getChildren(Reflect.Message.Field); + + /** + * Constructs a new runtime Message. + * @name ProtoBuf.Builder.Message + * @class Barebone of all runtime messages. + * @param {Object.|...[string]} values Preset values + * @constructor + * @throws {Error} If the message cannot be created + */ + var Message = function(values) { + ProtoBuf.Builder.Message.call(this); + var i, field; + + // Create fields on the object itself to allow setting and getting through Message#fieldname + for (i=0; i} + * @expose + */ + var O_o; // for cc + + if (Object.defineProperty) { + Object.defineProperty(Message, '$options', { + 'value': T.buildOpt(), + 'enumerable': false, + 'configurable': false, + 'writable': false + }); + } + + return Message; + + })(ProtoBuf, this); + + // Static enums and prototyped sub-messages + var children = this.getChildren(); + for (var i=0; i 0)) { + var tag = buffer.readVarint32(); + var wireType = tag & 0x07, + id = tag >> 3; + var field = this.getChild(id); // Message.Field only + if (!field) { + // "messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing." + switch (wireType) { + case ProtoBuf.WIRE_TYPES.VARINT: + buffer.readVarint32(); + break; + case ProtoBuf.WIRE_TYPES.BITS32: + buffer.offset += 4; + break; + case ProtoBuf.WIRE_TYPES.BITS64: + buffer.offset += 8; + break; + case ProtoBuf.WIRE_TYPES.LDELIM: + var len = buffer.readVarint32(); + buffer.offset += len; + break; + default: + throw(new Error("Illegal wire type of unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType)); + } + continue; + } + if (field.repeated && !field.options["packed"]) { + msg.add(field.name, field.decode(wireType, buffer)); + } else { + msg.set(field.name, field.decode(wireType, buffer)); + } + } + // Check if all required fields are present + var fields = this.getChildren(ProtoBuf.Reflect.Field); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Field = function(message, rule, type, name, id, options) { + T.call(this, message, name); + + /** + * Message field required flag. + * @type {boolean} + * @expose + */ + this.required = rule == "required"; + + /** + * Message field repeated flag. + * @type {boolean} + * @expose + */ + this.repeated = rule == "repeated"; + + /** + * Message field type. Type reference string if unresolved, protobuf type if resolved. + * @type {string|{name: string, wireType: number} + * @expose + */ + this.type = type; + + /** + * Resolved type reference inside the global namespace. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.resolvedType = null; + + /** + * Unique message field id. + * @type {number} + * @expose + */ + this.id = id; + + /** + * Message field options. + * @type {!Object.} + * @dict + * @expose + */ + this.options = options || {}; + + /** + * Original field name. + * @type {string} + * @expose + */ + this.originalName = this.name; // Used to revert camelcase transformation on naming collisions + + // Convert field names to camel case notation if the override is set + if (ProtoBuf.convertFieldsToCamelCase) { + this.name = this.name.replace(/_([a-zA-Z])/g, function($0, $1) { + return $1.toUpperCase(); + }); + } + }; + + // Extends T + Field.prototype = Object.create(T.prototype); + + /** + * Checks if the given value can be set for this field. + * @param {*} value Value to check + * @param {boolean=} skipRepeated Whether to skip the repeated value check or not. Defaults to false. + * @return {*} Verified, maybe adjusted, value + * @throws {Error} If the value cannot be set for this field + * @expose + */ + Field.prototype.verifyValue = function(value, skipRepeated) { + skipRepeated = skipRepeated || false; + if (value === null) { // NULL values for optional fields + if (this.required) { + throw(new Error("Illegal value for "+this.toString(true)+": "+value+" (required)")); + } + return null; + } + var i; + if (this.repeated && !skipRepeated) { // Repeated values as arrays + if (!ProtoBuf.Util.isArray(value)) { + value = [value]; + } + var res = []; + for (i=0; i>> 0; // Do not cast NaN as it'd become 0 + } + if (ProtoBuf.Long) { + // Signed 64bit + if (this.type == ProtoBuf.TYPES["int64"] || this.type == ProtoBuf.TYPES["sint64"] || this.type == ProtoBuf.TYPES["sfixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, false); + } + return value.unsigned ? value.toSigned() : value; + } + // Unsigned 64bit + if (this.type == ProtoBuf.TYPES["uint64"] || this.type == ProtoBuf.TYPES["fixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, true); + } + return value.unsigned ? value : value.toUnsigned(); + } + } + // Bool + if (this.type == ProtoBuf.TYPES["bool"]) { + if (typeof value === 'string') return value === 'true'; + else return !!value; + } + // Float + if (this.type == ProtoBuf.TYPES["float"] || this.type == ProtoBuf.TYPES["double"]) { + return parseFloat(value); // May also become NaN, +Infinity, -Infinity + } + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]) { + return ""+value; + } + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + if (value && value instanceof ByteBuffer) { + return value; + } + return ByteBuffer.wrap(value); + } + // Constant enum value + if (this.type == ProtoBuf.TYPES["enum"]) { + var values = this.resolvedType.getChildren(Enum.Value); + for (i=0; i 1) { // We need to move the contents + var contents = buffer.slice(start, buffer.offset); + start += varintLen-1; + buffer.offset = start; + buffer.append(contents); + } + buffer.writeVarint32(len, start-varintLen); + } else { + // "If your message definition has repeated elements (without the [packed=true] option), the encoded + // message has zero or more key-value pairs with the same tag number" + for (i=0; i value.length) { // Forgot to flip? + buffer = buffer.clone().flip(); + } + buffer.writeVarint32(value.remaining()); + buffer.append(value); + + // Embedded message + } else if (this.type == ProtoBuf.TYPES["message"]) { + var bb = new ByteBuffer().LE(); + this.resolvedType.encode(value, bb); + buffer.writeVarint32(bb.offset); + buffer.append(bb.flip()); + } else { + // We should never end here + throw(new Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)")); + } + return buffer; + }; + + /** + * Decode the field value from the specified buffer. + * @param {number} wireType Leading wire type + * @param {ByteBuffer} buffer ByteBuffer to decode from + * @param {boolean=} skipRepeated Whether to skip the repeated check or not. Defaults to false. + * @return {*} Decoded value + * @throws {Error} If the field cannot be decoded + * @expose + */ + Field.prototype.decode = function(wireType, buffer, skipRepeated) { + var value, nBytes; + if (wireType != this.type.wireType && (skipRepeated || (wireType != ProtoBuf.WIRE_TYPES.LDELIM || !this.repeated))) { + throw(new Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)")); + } + if (wireType == ProtoBuf.WIRE_TYPES.LDELIM && this.repeated && this.options["packed"]) { + if (!skipRepeated) { + nBytes = buffer.readVarint32(); + nBytes = buffer.offset + nBytes; // Limit + var values = []; + while (buffer.offset < nBytes) { + values.push(this.decode(this.type.wireType, buffer, true)); + } + return values; + } + // Read the next value otherwise... + + } + // 32bit signed varint + if (this.type == ProtoBuf.TYPES["int32"]) { + return buffer.readVarint32() | 0; + } + + // 32bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint32"]) { + return buffer.readVarint32() >>> 0; + } + + // 32bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint32"]) { + return buffer.readZigZagVarint32() | 0; + } + + // Fixed 32bit unsigned + if (this.type == ProtoBuf.TYPES["fixed32"]) { + return buffer.readUint32() >>> 0; + } + + // Fixed 32bit signed + if (this.type == ProtoBuf.TYPES["sfixed32"]) { + return buffer.readInt32() | 0; + } + + // 64bit signed varint + if (this.type == ProtoBuf.TYPES["int64"]) { + return buffer.readVarint64(); + } + + // 64bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint64"]) { + return buffer.readVarint64().toUnsigned(); + } + + // 64bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint64"]) { + return buffer.readZigZagVarint64(); + } + + // Fixed 64bit unsigned + if (this.type == ProtoBuf.TYPES["fixed64"]) { + return buffer.readUint64(); + } + + // Fixed 64bit signed + if (this.type == ProtoBuf.TYPES["sfixed64"]) { + return buffer.readInt64(); + } + + // Bool varint + if (this.type == ProtoBuf.TYPES["bool"]) { + return !!buffer.readVarint32(); + } + + // Constant enum value varint) + if (this.type == ProtoBuf.TYPES["enum"]) { + return buffer.readVarint32(); // The following Builder.Message#set will already throw + } + + // 32bit float + if (this.type == ProtoBuf.TYPES["float"]) { + return buffer.readFloat(); + } + // 64bit float + if (this.type == ProtoBuf.TYPES["double"]) { + return buffer.readDouble(); + } + + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]){ + return buffer.readVString(); + } + + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + nBytes = buffer.readVarint32(); + if (buffer.remaining() < nBytes) { + throw(new Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining())); + } + value = buffer.clone(); // Offset already set + value.length = value.offset+nBytes; + buffer.offset += nBytes; + return value; + } + + // Length-delimited embedded message + if (this.type == ProtoBuf.TYPES["message"]) { + nBytes = buffer.readVarint32(); + return this.resolvedType.decode(buffer, nBytes); + } + + // We should never end here + throw(new Error("[INTERNAL] Illegal wire type for "+this.toString(true)+": "+wireType)); + }; + + /** + * @alias ProtoBuf.Reflect.Message.Field + * @expose + */ + Reflect.Message.Field = Field; + + /** + * Constructs a new Enum. + * @exports ProtoBuf.Reflect.Enum + * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object + * @param {string} name Enum name + * @param {Object.=} options Enum options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Enum = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Runtime enum object. + * @type {Object.|null} + * @expose + */ + this.object = null; + }; + + // Extends Namespace + Enum.prototype = Object.create(Namespace.prototype); + + /** + * Builds this enum and returns the runtime counterpart. + * @return {Object} + * @expose + */ + Enum.prototype.build = function() { + var enm = {}; + var values = this.getChildren(Enum.Value); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Service = function(root, name, options) { + Namespace.call(this, root, name, options); + + /** + * Built runtime service class. + * @type {?function(new:ProtoBuf.Builder.Service)} + */ + this.clazz = null; + }; + + // Extends Namespace + Service.prototype = Object.create(Namespace.prototype); + + /** + * Builds the service and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Service + * @param {boolean=} rebuild Whether to rebuild or not + * @return {Function} Service class + * @throws {Error} If the message cannot be built + * @expose + */ + Service.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + return this.clazz = (function(ProtoBuf, T) { + + /** + * Constructs a new runtime Service. + * @name ProtoBuf.Builder.Service + * @param {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))=} rpcImpl RPC implementation receiving the method name and the message + * @class Barebone of all runtime services. + * @constructor + * @throws {Error} If the service cannot be created + */ + var Service = function(rpcImpl) { + ProtoBuf.Builder.Service.call(this); + + /** + * Service implementation. + * @name ProtoBuf.Builder.Service#rpcImpl + * @type {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} + * @expose + */ + this.rpcImpl = rpcImpl || function(name, msg, callback) { + // This is what a user has to implement: A function receiving the method name, the actual message to + // send (type checked) and the callback that's either provided with the error as its first + // argument or null and the actual response message. + setTimeout(callback.bind(this, new Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0); // Must be async! + }; + }; + + // Extends ProtoBuf.Builder.Service + Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype); + + if (Object.defineProperty) { + Object.defineProperty(Service, "$options", { + "value": T.buildOpt(), + "enumerable": false, + "configurable": false, + "writable": false + }); + Object.defineProperty(Service.prototype, "$options", { + "value": Service["$options"], + "enumerable": false, + "configurable": false, + "writable": false + }); + } + + /** + * Asynchronously performs an RPC call using the given RPC implementation. + * @name ProtoBuf.Builder.Service.[Method] + * @function + * @param {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} rpcImpl RPC implementation + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + /** + * Asynchronously performs an RPC call using the instance's RPC implementation. + * @name ProtoBuf.Builder.Service#[Method] + * @function + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + var rpc = T.getChildren(Reflect.Service.RPCMethod); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Method = function(svc, name, options) { + T.call(this, svc, name); + + /** + * Options. + * @type {Object.} + * @expose + */ + this.options = options || {}; + }; + + // Extends T + Method.prototype = Object.create(T.prototype); + + /** + * Builds the method's '$options' property. + * @name ProtoBuf.Reflect.Service.Method#buildOpt + * @function + * @return {Object.} + */ + Method.prototype.buildOpt = Namespace.prototype.buildOpt; + + /** + * @alias ProtoBuf.Reflect.Service.Method + * @expose + */ + Reflect.Service.Method = Method; + + /** + * RPC service method. + * @exports ProtoBuf.Reflect.Service.RPCMethod + * @param {!ProtoBuf.Reflect.Service} svc Service + * @param {string} name Method name + * @param {string} request Request message name + * @param {string} response Response message name + * @param {Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Service.Method + */ + var RPCMethod = function(svc, name, request, response, options) { + Method.call(this, svc, name, options); + + /** + * Request message name. + * @type {string} + * @expose + */ + this.requestName = request; + + /** + * Response message name. + * @type {string} + * @expose + */ + this.responseName = response; + + /** + * Resolved request message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedRequestType = null; + + /** + * Resolved response message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedResponseType = null; + }; + + // Extends Method + RPCMethod.prototype = Object.create(Method.prototype); + + /** + * @alias ProtoBuf.Reflect.Service.RPCMethod + * @expose + */ + Reflect.Service.RPCMethod = RPCMethod; + + return Reflect; + })(ProtoBuf); + + /** + * @alias ProtoBuf.Builder + * @expose + */ + ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) { + "use strict"; + + /** + * Constructs a new Builder. + * @exports ProtoBuf.Builder + * @class Provides the functionality to build protocol messages. + * @constructor + */ + var Builder = function() { + + /** + * Namespace. + * @type {ProtoBuf.Reflect.Namespace} + * @expose + */ + this.ns = new Reflect.Namespace(null, ""); // Global namespace + + /** + * Namespace pointer. + * @type {ProtoBuf.Reflect.T} + * @expose + */ + this.ptr = this.ns; + + /** + * Resolved flag. + * @type {boolean} + * @expose + */ + this.resolved = false; + + /** + * The current building result. + * @type {Object.|null} + * @expose + */ + this.result = null; + + /** + * Imported files. + * @type {Array.} + * @expose + */ + this.files = {}; + + /** + * Import root override. + * @type {?string} + * @expose + */ + this.importRoot = null; + }; + + /** + * Resets the pointer to the global namespace. + * @expose + */ + Builder.prototype.reset = function() { + this.ptr = this.ns; + }; + + /** + * Defines a package on top of the current pointer position and places the pointer on it. + * @param {string} pkg + * @param {Object.=} options + * @return {ProtoBuf.Builder} this + * @throws {Error} If the package name is invalid + * @expose + */ + Builder.prototype.define = function(pkg, options) { + if (typeof pkg !== 'string' || !Lang.TYPEREF.test(pkg)) { + throw(new Error("Illegal package name: "+pkg)); + } + var part = pkg.split("."), i; + for (i=0; i} def Definition + * @return {boolean} true if valid, else false + * @expose + */ + Builder.isValidMessage = function(def) { + // Messages require a string name + if (typeof def["name"] !== 'string' || !Lang.NAME.test(def["name"])) { + return false; + } + // Messages must not contain values (that'd be an enum) or methods (that'd be a service) + if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined') { + return false; + } + // Fields, enums and messages are arrays if provided + var i; + if (typeof def["fields"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["fields"])) { + return false; + } + var ids = [], id; // IDs must be unique + for (i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + if (typeof def["enums"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["enums"])) { + return false; + } + for (i=0; i + var keys = Object.keys(def["options"]); + for (var i=0; i>} defs Messages, enums or services to create + * @return {ProtoBuf.Builder} this + * @throws {Error} If a message definition is invalid + * @expose + */ + Builder.prototype.create = function(defs) { + if (!defs) return; // Nothing to create + if (!ProtoBuf.Util.isArray(defs)) { + defs = [defs]; + } + if (defs.length == 0) return; + + // It's quite hard to keep track of scopes and memory here, so let's do this iteratively. + var stack = [], def, obj, subObj, i, j; + stack.push(defs); // One level [a, b, c] + while (stack.length > 0) { + defs = stack.pop(); + if (ProtoBuf.Util.isArray(defs)) { // Stack always contains entire namespaces + while (defs.length > 0) { + def = defs.shift(); // Namespace always contains an array of messages, enums and services + if (Builder.isValidMessage(def)) { + obj = new Reflect.Message(this.ptr, def["name"], def["options"]); + // Create fields + if (def["fields"] && def["fields"].length > 0) { + for (i=0; i 0) { + for (i=0; i 0) { + for (i=0; i ProtoBuf.Lang.ID_MAX) { + obj.extensions[1] = ProtoBuf.Lang.ID_MAX; + } + } + this.ptr.addChild(obj); // Add to current namespace + if (subObj.length > 0) { + stack.push(defs); // Push the current level back + defs = subObj; // Continue processing sub level + subObj = null; + this.ptr = obj; // And move the pointer to this namespace + obj = null; + continue; + } + subObj = null; + obj = null; + } else if (Builder.isValidEnum(def)) { + obj = new Reflect.Enum(this.ptr, def["name"], def["options"]); + for (i=0; i obj.extensions[1]) { + throw(new Error("Illegal extended field id in message "+obj.name+": "+def['fields'][i]['id']+" ("+obj.extensions.join(' to ')+" expected)")); + } + obj.addChild(new Reflect.Message.Field(obj, def["fields"][i]["rule"], def["fields"][i]["type"], def["fields"][i]["name"], def["fields"][i]["id"], def["fields"][i]["options"])); + } + /* if (this.ptr instanceof Reflect.Message) { + this.ptr.addChild(obj); // Reference the extended message here to enable proper lookups + } */ + } else { + if (!/\.?google\.protobuf\./.test(def["ref"])) { // Silently skip internal extensions + throw(new Error("Extended message "+def["ref"]+" is not defined")); + } + } + } else { + throw(new Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(def))); + } + def = null; + } + // Break goes here + } else { + throw(new Error("Not a valid namespace definition: "+JSON.stringify(defs))); + } + defs = null; + this.ptr = this.ptr.parent; // This namespace is s done + } + this.resolved = false; // Require re-resolve + this.result = null; // Require re-build + return this; + }; + + /** + * Tests if the specified file is a valid import. + * @param {string} filename + * @returns {boolean} true if valid, false if it should be skipped + * @expose + */ + Builder.isValidImport = function(filename) { + // Ignore google/protobuf/descriptor.proto (for example) as it makes use of low-level + // bootstrapping directives that are not required and therefore cannot be parsed by ProtoBuf.js. + return !(/google\/protobuf\//.test(filename)); + }; + + /** + * Imports another definition into this builder. + * @param {Object.} json Parsed import + * @param {(string|{root: string, file: string})=} filename Imported file name + * @return {ProtoBuf.Builder} this + * @throws {Error} If the definition or file cannot be imported + * @expose + */ + Builder.prototype["import"] = function(json, filename) { + if (typeof filename === 'string') { + if (ProtoBuf.Util.IS_NODE) { + var path = require("path"); + filename = path.resolve(filename); + } + if (!!this.files[filename]) { + this.reset(); + return this; // Skip duplicate imports + } + this.files[filename] = true; + } + if (!!json['imports'] && json['imports'].length > 0) { + var importRoot, delim = '/', resetRoot = false; + if (typeof filename === 'object') { // If an import root is specified, override + this.importRoot = filename["root"]; resetRoot = true; // ... and reset afterwards + importRoot = this.importRoot; + filename = filename["file"]; + if (importRoot.indexOf("\\") >= 0 || filename.indexOf("\\") >= 0) delim = '\\'; + } else if (typeof filename === 'string') { + if (this.importRoot) { // If import root is overridden, use it + importRoot = this.importRoot; + } else { // Otherwise compute from filename + if (filename.indexOf("/") >= 0) { // Unix + importRoot = filename.replace(/\/[^\/]*$/, ""); + if (/* /file.proto */ importRoot === "") importRoot = "/"; + } else if (filename.indexOf("\\") >= 0) { // Windows + importRoot = filename.replace(/\\[^\\]*$/, ""); delim = '\\'; + } else { + importRoot = "."; + } + } + } else { + importRoot = null; + } + + for (var i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + return true; + }; + + /** + * Resolves all namespace objects. + * @throws {Error} If a type cannot be resolved + * @expose + */ + Builder.prototype.resolveAll = function() { + // Resolve all reflected objects + var res; + if (this.ptr == null || typeof this.ptr.type === 'object') return; // Done (already resolved) + if (this.ptr instanceof Reflect.Namespace) { + // Build all children + var children = this.ptr.getChildren(); + for (var i=0; i} + * @throws {Error} If a type could not be resolved + * @expose + */ + Builder.prototype.build = function(path) { + this.reset(); + if (!this.resolved) { + this.resolveAll(); + this.resolved = true; + this.result = null; // Require re-build + } + if (this.result == null) { // (Re-)Build + this.result = this.ns.build(); + } + if (!path) { + return this.result; + } else { + var part = path.split("."); + var ptr = this.result; // Build namespace pointer (no hasChild etc.) + for (var i=0; i=} options Top level options + * @return {ProtoBuf.Builder} New Builder + * @expose + */ + ProtoBuf.newBuilder = function(pkg, options) { + var builder = new ProtoBuf.Builder(); + if (typeof pkg !== 'undefined' && pkg !== null) { + builder.define(pkg, options); + } + return builder; + }; + + /** + * Loads a .json definition and returns the Builder. + * @param {!*|string} json JSON definition + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted. + * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports. + * @return {ProtoBuf.Builder} Builder to create new messages + * @throws {Error} If the definition cannot be parsed or built + * @expose + */ + ProtoBuf.loadJson = function(json, builder, filename) { + if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string')) { + filename = builder; + builder = null; + } + if (!builder || typeof builder !== 'object') builder = ProtoBuf.newBuilder(); + if (typeof json === 'string') json = JSON.parse(json); + builder["import"](json, filename); + builder.resolveAll(); + builder.build(); + return builder; + }; + + /** + * Loads a .json file and returns the Builder. + * @param {string|{root: string, file: string}} filename Path to json file or an object specifying 'file' with + * an overridden 'root' path for all imported files. + * @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. + * If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + * function will return the Builder or NULL if the request has failed. + * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted. + * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the + * request has failed), else undefined + * @expose + */ + ProtoBuf.loadJsonFile = function(filename, callback, builder) { + if (callback && typeof callback === 'object') { + builder = callback; + callback = null; + } else if (!callback || typeof callback !== 'function') { + callback = null; + } + if (callback) { + ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename, function(contents) { + try { + callback(ProtoBuf.loadJson(JSON.parse(contents), builder, filename)); + } catch (err) { + callback(err); + } + }); + } else { + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents !== null ? ProtoBuf.loadJson(JSON.parse(contents), builder, filename) : null; + } + }; + + return ProtoBuf; + } + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadProtoBuf(require("bytebuffer")); + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("ProtoBuf", ["ByteBuffer"], loadProtoBuf); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["ProtoBuf"] = loadProtoBuf(global["dcodeIO"]["ByteBuffer"]); + } + +})(this); \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/ProtoBuf.noparse.min.js b/javascript/node_modules/protobufjs/ProtoBuf.noparse.min.js new file mode 100644 index 0000000..70f218b --- /dev/null +++ b/javascript/node_modules/protobufjs/ProtoBuf.noparse.min.js @@ -0,0 +1,64 @@ +/* + ProtoBuf.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/ProtoBuf.js for details +*/ +(function(q){function r(p){var k={VERSION:"2.0.5",WIRE_TYPES:{}};k.WIRE_TYPES.VARINT=0;k.WIRE_TYPES.BITS64=1;k.WIRE_TYPES.LDELIM=2;k.WIRE_TYPES.STARTGROUP=3;k.WIRE_TYPES.ENDGROUP=4;k.WIRE_TYPES.BITS32=5;k.TYPES={int32:{name:"int32",wireType:k.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:k.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:k.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:k.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:k.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:k.WIRE_TYPES.VARINT}, +bool:{name:"bool",wireType:k.WIRE_TYPES.VARINT},"double":{name:"double",wireType:k.WIRE_TYPES.BITS64},string:{name:"string",wireType:k.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:k.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:k.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:k.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:k.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:k.WIRE_TYPES.BITS64},"float":{name:"float",wireType:k.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:k.WIRE_TYPES.VARINT}, +message:{name:"message",wireType:k.WIRE_TYPES.LDELIM}};k.Long=p.Long;k.convertFieldsToCamelCase=!1;k.Util=function(){Object.create||(Object.create=function(c){function m(){}if(1>3,l=this.getChild(h);if(l)l.repeated&&!l.options.packed?e.add(l.name,l.decode(g,b)):e.set(l.name,l.decode(g,b));else switch(g){case c.WIRE_TYPES.VARINT:b.readVarint32();break;case c.WIRE_TYPES.BITS32:b.offset+=4;break;case c.WIRE_TYPES.BITS64:b.offset+=8;break;case c.WIRE_TYPES.LDELIM:g=b.readVarint32();b.offset+=g;break; +default:throw Error("Illegal wire type of unknown field "+h+" in "+this.toString(!0)+"#decode: "+g);}}d=this.getChildren(c.Reflect.Field);for(g=0;g>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==c.TYPES.sint64||this.type==c.TYPES.sfixed64)return"object"==typeof b&&b instanceof c.Long?b.unsigned?b.toSigned():b:c.Long.fromNumber(b,!1);if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return"object"== +typeof b&&b instanceof c.Long?b.unsigned?b:b.toUnsigned():c.Long.fromNumber(b,!0)}if(this.type==c.TYPES.bool)return"string"===typeof b?"true"===b:!!b;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(b);if(this.type==c.TYPES.string)return""+b;if(this.type==c.TYPES.bytes)return b&&b instanceof p?b:p.wrap(b);if(this.type==c.TYPES["enum"]){g=this.resolvedType.getChildren(d.Value);for(e=0;eb.length&&(a=a.clone().flip()),a.writeVarint32(b.remaining()),a.append(b);else if(this.type==c.TYPES.message){var d=(new p).LE();this.resolvedType.encode(b,d);a.writeVarint32(d.offset);a.append(d.flip())}else throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+b+" (unknown type)");return a}};e.prototype.decode=function(b,a,d){if(b!=this.type.wireType&&(d||b!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+ +this.toString(!0)+": "+b+" ("+this.type.wireType+" expected)");if(b==c.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&!d){b=a.readVarint32();b=a.offset+b;for(d=[];a.offset>>0;if(this.type==c.TYPES.sint32)return a.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return a.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return a.readInt32()| +0;if(this.type==c.TYPES.int64)return a.readVarint64();if(this.type==c.TYPES.uint64)return a.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return a.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return a.readUint64();if(this.type==c.TYPES.sfixed64)return a.readInt64();if(this.type==c.TYPES.bool)return!!a.readVarint32();if(this.type==c.TYPES["enum"])return a.readVarint32();if(this.type==c.TYPES["float"])return a.readFloat();if(this.type==c.TYPES["double"])return a.readDouble();if(this.type== +c.TYPES.string)return a.readVString();if(this.type==c.TYPES.bytes){b=a.readVarint32();if(a.remaining()c.Lang.ID_MAX&&(g.extensions[1]=c.Lang.ID_MAX));this.ptr.addChild(g);0g.extensions[1])throw Error("Illegal extended field id in message "+g.name+": "+d.fields[b].id+" ("+g.extensions.join(" to ")+" expected)");g.addChild(new m.Message.Field(g,d.fields[b].rule,d.fields[b].type,d.fields[b].name,d.fields[b].id,d.fields[b].options))}else{if(!/\.?google\.protobuf\./.test(d.ref))throw Error("Extended message "+d.ref+" is not defined");}else throw Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(d));else throw Error("Not a valid namespace definition: "+ +JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};l.isValidImport=function(a){return!/google\/protobuf\//.test(a)};l.prototype["import"]=function(a,e){if("string"===typeof e){c.Util.IS_NODE&&(e=require("path").resolve(e));if(this.files[e])return this.reset(),this;this.files[e]=!0}if(a.imports&&0IkBSnWr&utIdJ_qJN1+o&r` zbXnai{}1n%xpQWo^UN*ho_p>*vAWu-S$(Xx= z(OcQr+rZ7v+t13=7NGFX&Dxe--Nnk@R^Qg@oxjJBEf@e`ic^Ouyn-(5!YSPif4~Pq zg#8J_6!6VK-?h>T=4#^KvIzVHzTp(2s|@cfGAfOg0ePC7Q zD-{(Zl?iO8b$ww;Ey$Mn?PQ6q=3B_OauK~}JR8VH3~q1#$kk#6xqlP9-@b8~Egi9e z3`93$R{YvK(EC^8(kT#51$LG;Bbnbzw*wOGam084z}p;7@w)+_dj|PcNO0#+dEXg8 zgu=w-bYD00UrHgm;9sJU?xfMMnKQyCP%~r4@OS9{g7ZYdWda?Bwn3yjjYbe8FpT03 zX?!0frjg;dVLvyA7?!B`t~l|J#!11xKba23M%^9IUON1vA~)=R3_ruh5AG~E}qpS;elN&i2bCxD9nKF;FX@j8Qt6m*Au`*eHM zrNWui0coZ@1N`$AUx5Swm|!D<`$IAeIjSxlroMdt^Wk5$&;on=IsqS!DtTd$m|2GT z{}xN-?ex*m-z0;P0~sY`xK&v@wo4ve`i5>U+6L`;M{m_R4%-$nbfr3^tOaizF-bAs z5+&&o$_*fC$A1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uhp9Mu_)9(|> zI_l~mvtZ^*t7xSj@>7ccxIvY5;PC!(|I&>s=Ngz&214&!s;v+~%$mmaI1lH{a-oJ% zF3sV_yA#S@-6fTN*&mNmAl+z=C5N9J+m461CtAxsfgKGK0x2%#-lMLo_wx{emud0~ zxu>BCtxhhIgD$h;pnLgVgR9xt6=yV><{LlROd4n8v(Ic)>0R2JYtF)?4)`X0rit+(nAp)%4-+>BG-D3$Q<**DP%CkH@`@Q39p$C8&4KE`%MDg z2X@5x$5H0%ape~>e-H_e?)>>jJqJ^!7WmgxSu3Z^9mm1OF)LyEpvuP6{8H%+W?kRD z`tHNumY)zI5|yuV64;2YSSKv#NETGUQ1~=Ps^Y%WoN_BzetoGRdH>jl9}kx5H%k}-1W#WdAC`f-Yz1k5kt8EHJa^JPtf4Yx%E1b(m4Qu)AX6U3fWfo^G4R;V{^0T&VUkcJA85qN|QSggzqt>dGu4? zm7m^RV4pi_punBTJQ{a{Bq{o*o6t5Ch&dUWC$(AXtuff8q7R)SY#5N7KWmJKF7?FjhjA{sCgDJKO~kwN^I%ox{F;XYP*kpLhfK gpD+{p_*S?Rz)}9Hc`AYM=wDb}SsPNV_%`hS05CO-&j0`b literal 0 HcmV?d00001 diff --git a/javascript/node_modules/protobufjs/README.md b/javascript/node_modules/protobufjs/README.md new file mode 100644 index 0000000..5c018b5 --- /dev/null +++ b/javascript/node_modules/protobufjs/README.md @@ -0,0 +1,52 @@ +![ProtoBuf.js - protobuf for JavaScript](https://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.png) +===================================== + +**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use +in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/docs/overview)). + +**ProtoBuf.js** is a pure JavaScript implementation on top of [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) +including a .proto parser, message class building and simple encoding and decoding. There is no compilation step +required, it's super easy to use and it works out of the box on .proto files! + +Getting started +--------------- +* **Step 1:** Become familar with [Google's Protocol Buffers (protobuf)](https://developers.google.com/protocol-buffers/docs/overview) +* **Step 2:** Head straight to [our wiki for up to date usage information and examples](https://github.com/dcodeIO/ProtoBuf.js/wiki) +* **Step 3:** Build something cool! :-) + +Features +-------- +* [RequireJS](http://requirejs.org/)/AMD compatible +* [node.js](http://nodejs.org)/CommonJS compatible, also available via [npm](https://npmjs.org/package/protobufjs) +* Browser compatible +* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/ProtoBuf.js/tree/master/externs)) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* Well tested through [test.js](https://github.com/dcodeIO/test.js) +* [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) is the only production dependency +* Fully compatible to the official implementation including advanced features +* Small footprint (even smaller if you use a noparse build) +* proto2js command line utility + +Documentation +------------- +* [Read the official protobuf guide](https://developers.google.com/protocol-buffers/docs/overview) +* [Read our wiki](https://github.com/dcodeIO/ProtoBuf.js/wiki) +* [Read the API docs](http://htmlpreview.github.com/?http://github.com/dcodeIO/ProtoBuf.js/master/docs/ProtoBuf.html) +* [Check out the examples](https://github.com/dcodeIO/ProtoBuf.js/tree/master/examples) + +Tests [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js) +------------------ +* [View source](https://github.com/dcodeIO/ProtoBuf.js/blob/master/tests/suite.js) +* [View report](https://travis-ci.org/dcodeIO/ProtoBuf.js) + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/ProtoBuf.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/ProtoBuf.js/tarball/master) + +Contributors +------------ +[Daniel Wirtz](https://github.com/dcodeIO) (maintainer), [Frank Xu](https://github.com/yyfrankyy), +[Dretch](https://github.com/Dretch), [shirmin](https://github.com/shirmin), [Nikolai Vavilov](https://github.com/seishun) + +**License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) - Logo derived from [W3C HTML5 Logos](http://www.w3.org/html/logo/) (CC A 3.0) diff --git a/javascript/node_modules/protobufjs/bin/proto2js b/javascript/node_modules/protobufjs/bin/proto2js new file mode 100755 index 0000000..63bed00 --- /dev/null +++ b/javascript/node_modules/protobufjs/bin/proto2js @@ -0,0 +1,263 @@ +#!/usr/bin/env node +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ProtoBuf.js: proto2js Command Line Utility (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ProtoBuf.js for details + */ + +var ProtoBuf = require(__dirname+"/../ProtoBuf.js"), + fs = require("fs"), + path = require("path"), + pkg = require(__dirname+"/../package.json"), + ascli = require("ascli"); + +if (!fs.existsSync) fs.existsSync = path.existsSync; // node 0.6 + +if (process.argv.length < 3) { + ascli.banner("proto".green.bold+"2".white.bold+"js".green.bold, "ProtoBuf.js v"+pkg['version']+" "+"https://github.com/dcodeIO/ProtoBuf.js".grey); + console.log("Usage: "+path.basename(process.argv[1]).green.bold+" protoFile [-class[=My.Package]|-commonjs[=My.Package]|-amd[=My.Package]] [-min] [> outFile]\n"); + console.log("Options:\n"); + console.log(" -class[=My.Package] Creates the classes instead of just a JSON definition."); + console.log(" If you do not specify a package, the package"); + console.log(" declaration from the .proto file is used instead.\n"); + console.log(" -commonjs[=My.Package] Creates a CommonJS export instead of just a JSON def."); + console.log(" If you do not specify a package, the package"); + console.log(" declaration from the .proto file is used instead.\n"); + console.log(" -amd[=My.Package] Creates an AMD define instead of just a JSON def."); + console.log(" If you do not specify a package, the package"); + console.log(" declaration from the .proto file is used instead.\n"); + console.log("If none of -class, -commonjs or -amd is specified, the raw AST will be returned.\n"); + console.log(" -min Minifies the output.\n"); + console.log(" -path=DIR Adds a directory to the include path."); + process.exit(1); +} +var options = {}; +for (var i=3; i 0) { // Replace import file names with the actual structures + var imports = []; + ast['imports'].forEach(function(ifile, i) { + if (ProtoBuf.Builder.isValidImport(ifile)) { + var pfile = path.resolve(base, ifile), + ofile = pfile; + if (!fs.existsSync(pfile)) { + for (var i=0; i i) { + if (astPart[i] != part[i]) return false; + } else { + for (var j=0; j + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ProtoBuf.js Build Script (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ProtoBuf.js for details + */ + +var Preprocessor = require("preprocessor"), + fs = require("fs"); + +var pkg = require(__dirname+"/package.json"); + +// Full build +var source = new Preprocessor(fs.readFileSync(__dirname+"/src/ProtoBuf.js"), __dirname+"/src").process({ + "NOPARSE": false, + "VERSION": pkg.version +}); +console.log("Writing ProtoBuf.js: "+source.length+" bytes"); +fs.writeFileSync(__dirname+"/ProtoBuf.js", source); + +// Noparse build +source = new Preprocessor(fs.readFileSync(__dirname+"/src/ProtoBuf.js"), __dirname+"/src").process({ + "NOPARSE": true, + "VERSION": pkg.version +}); +console.log("Writing ProtoBuf.noparse.js: "+source.length+" bytes"); +fs.writeFileSync(__dirname+"/ProtoBuf.noparse.js", source); + +// Bower versioning +source = new Preprocessor(fs.readFileSync(__dirname+"/src/bower.json"), __dirname+"/src").process({ + "VERSION": pkg.version +}); +console.log("Writing bower.json: "+source.length+" bytes"); +fs.writeFileSync(__dirname+"/bower.json", source); diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Message.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Message.html new file mode 100644 index 0000000..da7104c --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Message.html @@ -0,0 +1,2707 @@ + + + + + Class: Message + + + + + + + + + + +
+ +

Class: Message

+ + + + + +
+ +
+

+ ProtoBuf.Builder. + + Message +

+ +

Barebone of all runtime messages.

+ +
+ +
+
+ + + + +
+

new Message(values)

+ + +
+
+ + +
+

Constructs a new runtime Message.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
values + + +Object.<string,*> +| + +...[string] + + + +

Preset values

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be created +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static> $options :Object.<string,*>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> decode(buffer, enc) → {ProtoBuf.Builder.Message}

+ + +
+
+ + +
+

Decodes the message from the specified buffer or string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
buffer + + +ByteBuffer +| + +!ArrayBuffer +| + +!Buffer +| + +string + + + + + + + +

Buffer to decode from

enc + + +string + + + + + + <optional>
+ + + +

Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded message

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder.Message + + +
+
+ + + + +
+ + + +
+

<static> decode64(str) → {ProtoBuf.Builder.Message}

+ + +
+
+ + +
+

Decodes the message from the specified base64 encoded string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +string + + + +

String to decode from

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded message

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder.Message + + +
+
+ + + + +
+ + + +
+

<static> decodeHex(str) → {ProtoBuf.Builder.Message}

+ + +
+
+ + +
+

Decodes the message from the specified hex encoded string.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +string + + + +

String to decode from

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded message

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder.Message + + +
+
+ + + + +
+ + + +
+

add(key, value)

+ + +
+
+ + +
+

Adds a value to a repeated field.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +string + + + +

Field name

value + + +* + + + +

Value to add

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be added +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

encode(buffer) → {ByteBuffer}

+ + +
+
+ + +
+

Encodes the message.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
buffer + + +!ByteBuffer +| + +boolean + + + + + + <optional>
+ + + +

ByteBuffer to encode to. Will create a new one if omitted.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded ByteBuffer in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Encoded message as a ByteBuffer

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

encode64() → {string}

+ + +
+
+ + +
+

Directly encodes the message to a base64 encoded string.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the underlying buffer cannot be encoded or if required fields are missing. The later still returns the encoded base64 string in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Base64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

encodeAB() → {ArrayBuffer}

+ + +
+
+ + +
+

Directly encodes the message to an ArrayBuffer.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded ArrayBuffer in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Encoded message as ArrayBuffer

+
+ + + +
+
+ Type +
+
+ +ArrayBuffer + + +
+
+ + + + +
+ + + +
+

encodeHex() → {string}

+ + +
+
+ + +
+

Directly encodes the message to a hex encoded string.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the underlying buffer cannot be encoded or if required fields are missing. The later still returns the encoded hex string in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Hex encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

encodeNB() → {Buffer}

+ + +
+
+ + +
+

Directly encodes the message to a node Buffer.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded, not running under node.js or if required fields are missing. The later still returns the encoded node Buffer in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Buffer + + +
+
+ + + + +
+ + + +
+

encodeNB() → {Buffer}

+ + +
+
+ + +
+

Returns the message as a node Buffer. This is an alias for ProtoBuf.Builder.Message#encodeNB.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded node Buffer in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Buffer + + +
+
+ + + + +
+ + + +
+

get(key) → {*}

+ + +
+
+ + +
+

Gets a value.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +string + + + +

Key

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If there is no such field +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Value

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + +
+ + + +
+

<virtual> get[SomeField]() → {*}

+ + +
+
+ + +
+

Gets a value. This method is present for each field, but only if there is no name conflict with +another field.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The value

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + +
+ + + +
+

<virtual> get_[some_field]() → {*}

+ + +
+
+ + +
+

Gets a value. This method is present for each field, but only if there is no name conflict with +another field.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The value

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + +
+ + + +
+

set(key, value)

+ + +
+
+ + +
+

Sets a field value.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +string + + + +

Key

value + + +* + + + +

Value to set

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be set +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

<virtual> set[SomeField](value)

+ + +
+
+ + +
+

Sets a value. This method is present for each field, but only if there is no name conflict with +another field.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +* + + + +

Value to set

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be set +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

<virtual> set_[some_field](value)

+ + +
+
+ + +
+

Sets a value. This method is present for each field, but only if there is no name conflict with +another field.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +* + + + +

Value to set

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be set +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

toArrayBuffer() → {ArrayBuffer}

+ + +
+
+ + +
+

Returns the message as an ArrayBuffer. This is an alias for ProtoBuf.Builder.Message#encodeAB.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded ArrayBuffer in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Encoded message as ArrayBuffer

+
+ + + +
+
+ Type +
+
+ +ArrayBuffer + + +
+
+ + + + +
+ + + +
+

toBase64() → {string}

+ + +
+
+ + +
+

Returns the message as a base64 encoded string. This is an alias for ProtoBuf.Builder.Message#encode64.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded base64 string in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Base64 encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toHex() → {string}

+ + +
+
+ + +
+

Returns the message as a hex encoded string. This is an alias for ProtoBuf.Builder.Message#encodeHex.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be encoded or if required fields are missing. The later still returns the encoded hex string in the `encoded` property on the error. +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Hex encoded string

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString() → {string}

+ + +
+
+ + +
+

Returns a string representation of this Message.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation as of ".Fully.Qualified.MessageName"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Service.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Service.html new file mode 100644 index 0000000..132eb28 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.Service.html @@ -0,0 +1,574 @@ + + + + + Class: Service + + + + + + + + + + +
+ +

Class: Service

+ + + + + +
+ +
+

+ ProtoBuf.Builder. + + Service +

+ +

Barebone of all runtime services.

+ +
+ +
+
+ + + + +
+

new Service(rpcImpl)

+ + +
+
+ + +
+

Constructs a new runtime Service.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
rpcImpl + + +function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=)) + + + + + + <optional>
+ + + +

RPC implementation receiving the method name and the message

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the service cannot be created +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

rpcImpl :function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))

+ + +
+
+ +
+

Service implementation.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<virtual, static> [Method](rpcImpl, req, callback)

+ + +
+
+ + +
+

Asynchronously performs an RPC call using the given RPC implementation.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rpcImpl + + +function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=)) + + + +

RPC implementation

req + + +ProtoBuf.Builder.Message + + + +

Request

callback + + +function(Error, (ProtoBuf.Builder.Message +| + +ByteBuffer +| + +Buffer +| + +string)=) + + + +

Callback receiving + the error if any and the response either as a pre-parsed message or as its raw bytes

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+

<virtual> [Method](req, callback)

+ + +
+
+ + +
+

Asynchronously performs an RPC call using the instance's RPC implementation.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
req + + +ProtoBuf.Builder.Message + + + +

Request

callback + + +function(Error, (ProtoBuf.Builder.Message +| + +ByteBuffer +| + +Buffer +| + +string)=) + + + +

Callback receiving + the error if any and the response either as a pre-parsed message or as its raw bytes

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.html new file mode 100644 index 0000000..526896a --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Builder.html @@ -0,0 +1,2243 @@ + + + + + Class: Builder + + + + + + + + + + +
+ +

Class: Builder

+ + + + + +
+ +
+

+ ProtoBuf. + + Builder +

+ +

Provides the functionality to build protocol messages.

+ +
+ +
+
+ + + + +
+

new Builder()

+ + +
+
+ + +
+

Constructs a new Builder.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + +

Classes

+ +
+
Message
+
+ +
Service
+
+
+ + + + + +

Members

+ +
+ +
+

files :Array.<string>

+ + +
+
+ +
+

Imported files.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

importRoot :string

+ + +
+
+ +
+

Import root override.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

ns :ProtoBuf.Reflect.Namespace

+ + +
+
+ +
+

Namespace.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

ptr :ProtoBuf.Reflect.T

+ + +
+
+ +
+

Namespace pointer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

resolved :boolean

+ + +
+
+ +
+

Resolved flag.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

result :Object.<string,ProtoBuf.Builder.Message|Object>|null

+ + +
+
+ +
+

The current building result.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> isValidEnum(def) → {boolean}

+ + +
+
+ + +
+

Tests if a definition is a valid enum definition.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
def + + +Object + + + +

Definition

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> isValidExtend(def) → {boolean}

+ + +
+
+ + +
+

Tests if a definition is a valid extension.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
def + + +Object + + + +

Definition

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> isValidImport(filename) → {boolean}

+ + +
+
+ + +
+

Tests if the specified file is a valid import.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filename + + +string + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, false if it should be skipped

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> isValidMessage(def) → {boolean}

+ + +
+
+ + +
+

Tests if a definition is a valid message definition.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
def + + +Object.<string,*> + + + +

Definition

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> isValidMessageField(def) → {boolean}

+ + +
+
+ + +
+

Tests if a definition is a valid message field definition.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
def + + +Object + + + +

Definition

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> isValidService(def) → {boolean}

+ + +
+
+ + +
+

Tests if a definition is a valid service definition.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
def + + +Object + + + +

Definition

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if valid, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

["import"](json, filename) → {ProtoBuf.Builder}

+ + +
+
+ + +
+

Imports another definition into this builder.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
json + + +Object.<string,*> + + + + + + + +

Parsed import

filename + + +string +| + +{root: string, file: string} + + + + + + <optional>
+ + + +

Imported file name

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the definition or file cannot be imported +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder + + +
+
+ + + + +
+ + + +
+

build(path) → {ProtoBuf.Builder.Message|Object.<string,*>}

+ + +
+
+ + +
+

Builds the protocol. This will first try to resolve all definitions and, if this has been successful, +return the built package.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
path + + +string + + + + + + <optional>
+ + + +

Specifies what to return. If omitted, the entire namespace will be returned.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If a type could not be resolved +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ProtoBuf.Builder.Message +| + +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

create(defs) → {ProtoBuf.Builder}

+ + +
+
+ + +
+

Creates ths specified protocol types at the current pointer position.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
defs + + +Array.<Object.<string,*>> + + + +

Messages, enums or services to create

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If a message definition is invalid +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder + + +
+
+ + + + +
+ + + +
+

define(pkg, options) → {ProtoBuf.Builder}

+ + +
+
+ + +
+

Defines a package on top of the current pointer position and places the pointer on it.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
pkg + + +string + + + + + + + +
options + + +Object.<string,*> + + + + + + <optional>
+ + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the package name is invalid +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder + + +
+
+ + + + +
+ + + +
+

lookup(path) → {ProtoBuf.Reflect.T}

+ + +
+
+ + +
+

Similar to ProtoBuf.Builder#build, but looks up the internal reflection descriptor.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
path + + +string + + + + + + <optional>
+ + + +

Specifies what to return. If omitted, the entire namespace wiil be returned.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Reflection descriptor or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.T + + +
+
+ + + + +
+ + + +
+

reset()

+ + +
+
+ + +
+

Resets the pointer to the global namespace.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+

resolveAll()

+ + +
+
+ + +
+

Resolves all namespace objects.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If a type cannot be resolved +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

toString() → {string}

+ + +
+
+ + +
+

Returns a string representation of this object.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation as of "Builder"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Parser.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Parser.html new file mode 100644 index 0000000..1e3aca3 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Parser.html @@ -0,0 +1,422 @@ + + + + + Class: Parser + + + + + + + + + + +
+ +

Class: Parser

+ + + + + +
+ +
+

+ ProtoBuf.DotProto. + + Parser +

+ +

A ProtoBuf .proto parser.

+ +
+ +
+
+ + + + +
+

new Parser(proto)

+ + +
+
+ + +
+

Constructs a new Parser.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
proto + + +string + + + +

Protocol source

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

tn :ProtoBuf.DotProto.Tokenizer

+ + +
+
+ +
+

Tokenizer.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

parse() → {{package: string|null, messages: Array.<object>, enums: Array.<object>, imports: Array.<string>, options: object<string,*>}}

+ + +
+
+ + +
+

Runs the parser.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the source cannot be parsed +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +{package: string +| + +null, messages: Array.<object>, enums: Array.<object>, imports: Array.<string>, options: object<string,*>} + + +
+
+ + + + +
+ + + +
+

toString() → {string}

+ + +
+
+ + +
+

Returns a string representation of this object.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation as of "Parser"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Tokenizer.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Tokenizer.html new file mode 100644 index 0000000..73e935b --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.Tokenizer.html @@ -0,0 +1,705 @@ + + + + + Class: Tokenizer + + + + + + + + + + +
+ +

Class: Tokenizer

+ + + + + +
+ +
+

+ ProtoBuf.DotProto. + + Tokenizer +

+ +

A ProtoBuf .proto Tokenizer.

+ +
+ +
+
+ + + + +
+

new Tokenizer(proto)

+ + +
+
+ + +
+

Constructs a new Tokenizer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
proto + + +string + + + +

Proto to tokenize

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

index :number

+ + +
+
+ +
+

Current index.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

line :number

+ + +
+
+ +
+

Current line.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

readingString :boolean

+ + +
+
+ +
+

Whether currently reading a string or not.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

source :string

+ + +
+
+ +
+

Source to parse.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

stack :Array

+ + +
+
+ +
+

Stacked values.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

next() → {string}

+ + +
+
+ + +
+

Gets the next token and advances by one.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid proto file +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Token or null on EOF

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

peek() → {string}

+ + +
+
+ + +
+

Peeks for the next token.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If it's not a valid proto file +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Token or null on EOF

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString() → {string}

+ + +
+
+ + +
+

Returns a string representation of this object.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation as of "Tokenizer(index/length)"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.html new file mode 100644 index 0000000..c1080c4 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.DotProto.html @@ -0,0 +1,124 @@ + + + + + Namespace: DotProto + + + + + + + + + + +
+ +

Namespace: DotProto

+ + + + + +
+ +
+

+ ProtoBuf. + + DotProto +

+ +
+ +
+
+ + + + +

Utilities to parse .proto files.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + +

Classes

+ +
+
Parser
+
+ +
Tokenizer
+
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Lang.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Lang.html new file mode 100644 index 0000000..99fce72 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Lang.html @@ -0,0 +1,114 @@ + + + + + Namespace: Lang + + + + + + + + + + +
+ +

Namespace: Lang

+ + + + + +
+ +
+

+ ProtoBuf. + + Lang +

+ +
+ +
+
+ + + + +

ProtoBuf Language.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.Value.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.Value.html new file mode 100644 index 0000000..336da00 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.Value.html @@ -0,0 +1,692 @@ + + + + + Class: Value + + + + + + + + + + +
+ +

Class: Value

+ + + + + +
+ +
+

+ ProtoBuf.Reflect.Enum. + + Value +

+ +
+ +
+
+ + + + +
+

new Value(enm, name, id)

+ + +
+
+ + +
+

Constructs a new Enum Value.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enm + + +ProtoBuf.Reflect.Enum + + + +

Enum reference

name + + +string + + + +

Field name

id + + +number + + + +

Unique field id

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + +

Members

+ +
+ +
+

id :number

+ + +
+
+ +
+

Unique enum value id.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

build()

+ + +
+
+ + +
+

Builds this type.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If this type cannot be built directly +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.html new file mode 100644 index 0000000..3d321e1 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Enum.html @@ -0,0 +1,1758 @@ + + + + + Class: Enum + + + + + + + + + + +
+ +

Class: Enum

+ + + + + +
+ +
+

+ ProtoBuf.Reflect. + + Enum +

+ +
+ +
+
+ + + + +
+

new Enum(parent, name, options)

+ + +
+
+ + +
+

Constructs a new Enum.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
parent + + +ProtoBuf.Reflect.T + + + + + + + +

Parent Reflect object

name + + +string + + + + + + + +

Enum name

options + + +Object.<string.*> + + + + + + <optional>
+ + + +

Enum options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + +

Classes

+ +
+
Value
+
+
+ + + + + +

Members

+ +
+ +
+

children :Array.<ProtoBuf.Reflect.T>

+ + +
+
+ +
+

Children inside the namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

object :Object.<string,number>|null

+ + +
+
+ +
+

Runtime enum object.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

addChild(child)

+ + +
+
+ + +
+

Adds a child to the namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
child + + +ProtoBuf.Reflect.T + + + +

Child

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the child cannot be added (duplicate) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

build() → {Object<string,*>}

+ + +
+
+ + +
+

Builds this enum and returns the runtime counterpart.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object<string,*> + + +
+
+ + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the namespace's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

getChild(nameOrId) → {ProtoBuf.Reflect.T}

+ + +
+
+ + +
+

Gets a child by its name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The child or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.T + + +
+
+ + + + +
+ + + +
+

getChildren(type) → {Array.<ProtoBuf.Reflect.T>}

+ + +
+
+ + +
+

Returns an array of the namespace's children.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
type + + +ProtoBuf.Reflect.T + + + + + + <optional>
+ + + +

Filter type (returns instances of this type only). Defaults to null (all children).

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<ProtoBuf.Reflect.T> + + +
+
+ + + + +
+ + + +
+

getOption(name) → {*|Object.<string,*>}

+ + +
+
+ + +
+

Gets the value assigned to the option with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
name + + +string + + + + + + <optional>
+ + + +

Returns the option value if specified, otherwise all options are returned.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

null} Option value or NULL if there is no such option

+
+ + + +
+
+ Type +
+
+ +* +| + +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

hasChild(nameOrId) → {boolean}

+ + +
+
+ + +
+

Tests if this namespace has a child with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if there is one, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

resolve(qn, excludeFields) → {ProtoBuf.Reflect.Namespace|null}

+ + +
+
+ + +
+

Resolves a reflect object inside of this namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
qn + + +string + + + + + + + +

Qualified name to resolve

excludeFields + + +boolean + + + + + + <optional>
+ + + +

Excludes fields, defaults to false

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The resolved type or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.Namespace +| + +null + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.Field.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.Field.html new file mode 100644 index 0000000..3d39fa8 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.Field.html @@ -0,0 +1,1774 @@ + + + + + Class: Field + + + + + + + + + + +
+ +

Class: Field

+ + + + + +
+ +
+

+ ProtoBuf.Reflect.Message. + + Field +

+ +
+ +
+
+ + + + +
+

new Field(message, rule, type, name, id, options)

+ + +
+
+ + +
+

Constructs a new Message Field.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
message + + +ProtoBuf.Reflect.Message + + + + + + + +

Message reference

rule + + +string + + + + + + + +

Rule, one of requried, optional, repeated

type + + +string + + + + + + + +

Data type, e.g. int32

name + + +string + + + + + + + +

Field name

id + + +number + + + + + + + +

Unique field id

options + + +Object.<string.*> + + + + + + <optional>
+ + + +

Options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + +

Members

+ +
+ +
+

id :number

+ + +
+
+ +
+

Unique message field id.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string,*>

+ + +
+
+ +
+

Message field options.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

originalName :string

+ + +
+
+ +
+

Original field name.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

repeated :boolean

+ + +
+
+ +
+

Message field repeated flag.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

required :boolean

+ + +
+
+ +
+

Message field required flag.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

resolvedType :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Resolved type reference inside the global namespace.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

type

+ + +
+
+ +
+

Message field type. Type reference string if unresolved, protobuf type if resolved.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

build()

+ + +
+
+ + +
+

Builds this type.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If this type cannot be built directly +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

decode(wireType, buffer, skipRepeated) → {*}

+ + +
+
+ + +
+

Decode the field value from the specified buffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
wireType + + +number + + + + + + + +

Leading wire type

buffer + + +ByteBuffer + + + + + + + +

ByteBuffer to decode from

skipRepeated + + +boolean + + + + + + <optional>
+ + + +

Whether to skip the repeated check or not. Defaults to false.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the field cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded value

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + +
+ + + +
+

encode(value, buffer) → {ByteBuffer}

+ + +
+
+ + +
+

Encodes the specified field value to the specified buffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +* + + + +

Field value

buffer + + +ByteBuffer + + + +

ByteBuffer to encode to

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the field cannot be encoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The ByteBuffer for chaining

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

encodeValue(value, buffer) → {ByteBuffer}

+ + +
+
+ + +
+

Encodes a value to the specified buffer. Does not encode the key.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +* + + + +

Field value

buffer + + +ByteBuffer + + + +

ByteBuffer to encode to

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be encoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

The ByteBuffer for chaining

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ + + +
+

verifyValue(value, skipRepeated) → {*}

+ + +
+
+ + +
+

Checks if the given value can be set for this field.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
value + + +* + + + + + + + +

Value to check

skipRepeated + + +boolean + + + + + + <optional>
+ + + +

Whether to skip the repeated value check or not. Defaults to false.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the value cannot be set for this field +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Verified, maybe adjusted, value

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.html new file mode 100644 index 0000000..54ef00b --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Message.html @@ -0,0 +1,2103 @@ + + + + + Class: Message + + + + + + + + + + +
+ +

Class: Message

+ + + + + +
+ +
+

+ ProtoBuf.Reflect. + + Message +

+ +
+ +
+
+ + + + +
+

new Message(parent, name, options)

+ + +
+
+ + +
+

Constructs a new Message.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parent + + +ProtoBuf.Reflect.Namespace + + + +

Parent message or namespace

name + + +string + + + +

Message name

options + + +Object.<string,*> + + + +

Message options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + +

Classes

+ +
+
Field
+
+
+ + + + + +

Members

+ +
+ +
+

children :Array.<ProtoBuf.Reflect.T>

+ + +
+
+ +
+

Children inside the namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

clazz :function(new:ProtoBuf.Builder.Message)

+ + +
+
+ +
+

Runtime message class.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

extensions :Array.<number>

+ + +
+
+ +
+

Extensions range.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

addChild(child)

+ + +
+
+ + +
+

Adds a child to the namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
child + + +ProtoBuf.Reflect.T + + + +

Child

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the child cannot be added (duplicate) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

build(rebuild) → {ProtoBuf.Reflect.Message}

+ + +
+
+ + +
+

Builds the message and returns the runtime counterpart, which is a fully functional class.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
rebuild + + +boolean + + + + + + <optional>
+ + + +

Whether to rebuild or not, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be built +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Message class

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.Message + + +
+
+ + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the namespace's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

decode(buffer, length) → {ProtoBuf.Builder.Message}

+ + +
+
+ + +
+

Decodes an encoded message and returns the decoded message.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
buffer + + +ByteBuffer + + + + + + + +

ByteBuffer to decode from

length + + +number + + + + + + <optional>
+ + + +

Message length. Defaults to decode all the available data.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be decoded +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Decoded message

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Builder.Message + + +
+
+ + + + +
+ + + +
+

encode(message, buffer) → {ByteBuffer}

+ + +
+
+ + +
+

Encodes a runtime message's contents to the specified buffer.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
message + + +ProtoBuf.Builder.Message + + + +

Runtime message to encode

buffer + + +ByteBuffer + + + +

ByteBuffer to write to

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If requried fields are missing or the message cannot be encoded for another reason +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
Returns:
+ + +
+

The ByteBuffer for chaining

+
+ + + +
+
+ Type +
+
+ +ByteBuffer + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

getChild(nameOrId) → {ProtoBuf.Reflect.T}

+ + +
+
+ + +
+

Gets a child by its name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The child or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.T + + +
+
+ + + + +
+ + + +
+

getChildren(type) → {Array.<ProtoBuf.Reflect.T>}

+ + +
+
+ + +
+

Returns an array of the namespace's children.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
type + + +ProtoBuf.Reflect.T + + + + + + <optional>
+ + + +

Filter type (returns instances of this type only). Defaults to null (all children).

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<ProtoBuf.Reflect.T> + + +
+
+ + + + +
+ + + +
+

getOption(name) → {*|Object.<string,*>}

+ + +
+
+ + +
+

Gets the value assigned to the option with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
name + + +string + + + + + + <optional>
+ + + +

Returns the option value if specified, otherwise all options are returned.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

null} Option value or NULL if there is no such option

+
+ + + +
+
+ Type +
+
+ +* +| + +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

hasChild(nameOrId) → {boolean}

+ + +
+
+ + +
+

Tests if this namespace has a child with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if there is one, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

resolve(qn, excludeFields) → {ProtoBuf.Reflect.Namespace|null}

+ + +
+
+ + +
+

Resolves a reflect object inside of this namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
qn + + +string + + + + + + + +

Qualified name to resolve

excludeFields + + +boolean + + + + + + <optional>
+ + + +

Excludes fields, defaults to false

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The resolved type or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.Namespace +| + +null + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Namespace.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Namespace.html new file mode 100644 index 0000000..4275041 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Namespace.html @@ -0,0 +1,1649 @@ + + + + + Class: Namespace + + + + + + + + + + +
+ +

Class: Namespace

+ + + + + +
+ +
+

+ ProtoBuf.Reflect. + + Namespace +

+ +
+ +
+
+ + + + +
+

new Namespace(parent, name, options)

+ + +
+
+ + +
+

Constructs a new Namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parent + + +ProtoBuf.Reflect.Namespace +| + +null + + + +

Namespace parent

name + + +string + + + +

Namespace name

options + + +Object.<string,*> + + + +

Namespace options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + +

Members

+ +
+ +
+

children :Array.<ProtoBuf.Reflect.T>

+ + +
+
+ +
+

Children inside the namespace.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

addChild(child)

+ + +
+
+ + +
+

Adds a child to the namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
child + + +ProtoBuf.Reflect.T + + + +

Child

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the child cannot be added (duplicate) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

build() → {Object.<string,Function|Object>}

+ + +
+
+ + +
+

Builds the namespace and returns the runtime counterpart.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Runtime namespace

+
+ + + +
+
+ Type +
+
+ +Object.<string,Function +| + +Object> + + +
+
+ + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the namespace's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

getChild(nameOrId) → {ProtoBuf.Reflect.T}

+ + +
+
+ + +
+

Gets a child by its name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The child or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.T + + +
+
+ + + + +
+ + + +
+

getChildren(type) → {Array.<ProtoBuf.Reflect.T>}

+ + +
+
+ + +
+

Returns an array of the namespace's children.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
type + + +ProtoBuf.Reflect.T + + + + + + <optional>
+ + + +

Filter type (returns instances of this type only). Defaults to null (all children).

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<ProtoBuf.Reflect.T> + + +
+
+ + + + +
+ + + +
+

getOption(name) → {*|Object.<string,*>}

+ + +
+
+ + +
+

Gets the value assigned to the option with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
name + + +string + + + + + + <optional>
+ + + +

Returns the option value if specified, otherwise all options are returned.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

null} Option value or NULL if there is no such option

+
+ + + +
+
+ Type +
+
+ +* +| + +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

hasChild(nameOrId) → {boolean}

+ + +
+
+ + +
+

Tests if this namespace has a child with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if there is one, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

resolve(qn, excludeFields) → {ProtoBuf.Reflect.Namespace|null}

+ + +
+
+ + +
+

Resolves a reflect object inside of this namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
qn + + +string + + + + + + + +

Qualified name to resolve

excludeFields + + +boolean + + + + + + <optional>
+ + + +

Excludes fields, defaults to false

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The resolved type or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.Namespace +| + +null + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.Method.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.Method.html new file mode 100644 index 0000000..d6f95f7 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.Method.html @@ -0,0 +1,790 @@ + + + + + Class: Method + + + + + + + + + + +
+ +

Class: Method

+ + + + + +
+ +
+

+ ProtoBuf.Reflect.Service. + + Method +

+ +
+ +
+
+ + + + +
+

new Method(svc, name, options)

+ + +
+
+ + +
+

Abstract service method.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
svc + + +ProtoBuf.Reflect.Service + + + + + + + +

Service

name + + +string + + + + + + + +

Method name

options + + +Object.<string,*> + + + + + + <optional>
+ + + +

Options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + +

Members

+ +
+ +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

build()

+ + +
+
+ + +
+

Builds this type.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If this type cannot be built directly +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the method's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.RPCMethod.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.RPCMethod.html new file mode 100644 index 0000000..3bde127 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.RPCMethod.html @@ -0,0 +1,1038 @@ + + + + + Class: RPCMethod + + + + + + + + + + +
+ +

Class: RPCMethod

+ + + + + +
+ +
+

+ ProtoBuf.Reflect.Service. + + RPCMethod +

+ +
+ +
+
+ + + + +
+

new RPCMethod(svc, name, request, response, options)

+ + +
+
+ + +
+

RPC service method.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
svc + + +ProtoBuf.Reflect.Service + + + + + + + +

Service

name + + +string + + + + + + + +

Method name

request + + +string + + + + + + + +

Request message name

response + + +string + + + + + + + +

Response message name

options + + +Object.<string,*> + + + + + + <optional>
+ + + +

Options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + +

Members

+ +
+ +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

requestName :string

+ + +
+
+ +
+

Request message name.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

resolvedRequestType :ProtoBuf.Reflect.Message

+ + +
+
+ +
+

Resolved request message type.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

resolvedResponseType :ProtoBuf.Reflect.Message

+ + +
+
+ +
+

Resolved response message type.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

responseName :string

+ + +
+
+ +
+

Response message name.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

build()

+ + +
+
+ + +
+

Builds this type.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If this type cannot be built directly +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the method's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.html new file mode 100644 index 0000000..3ff61b1 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.Service.html @@ -0,0 +1,1852 @@ + + + + + Class: Service + + + + + + + + + + +
+ +

Class: Service

+ + + + + +
+ +
+

+ ProtoBuf.Reflect. + + Service +

+ +
+ +
+
+ + + + +
+

new Service(root, name, options)

+ + +
+
+ + +
+

Constructs a new Service.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
root + + +ProtoBuf.Reflect.Namespace + + + + + + + +

Root

name + + +string + + + + + + + +

Service name

options + + +Object.<string,*> + + + + + + <optional>
+ + + +

Options

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + +

Classes

+ +
+
Method
+
+ +
RPCMethod
+
+
+ + + + + +

Members

+ +
+ +
+

children :Array.<ProtoBuf.Reflect.T>

+ + +
+
+ +
+

Children inside the namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

clazz :function(new:ProtoBuf.Builder.Service)

+ + +
+
+ +
+

Built runtime service class.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

options :Object.<string, *>

+ + +
+
+ +
+

Options.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

addChild(child)

+ + +
+
+ + +
+

Adds a child to the namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
child + + +ProtoBuf.Reflect.T + + + +

Child

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If the child cannot be added (duplicate) +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

build(rebuild) → {Function}

+ + +
+
+ + +
+

Builds the service and returns the runtime counterpart, which is a fully functional class.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
rebuild + + +boolean + + + + + + <optional>
+ + + +

Whether to rebuild or not

+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
See:
+
+ +
+ + + +
+ + + + + +
Throws:
+ + +
+ If the message cannot be built +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + +
+

Service class

+
+ + + +
+
+ Type +
+
+ +Function + + +
+
+ + + + +
+ + + +
+

buildOpt() → {Object.<string,*>}

+ + +
+
+ + +
+

Builds the namespace's '$options' property.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

getChild(nameOrId) → {ProtoBuf.Reflect.T}

+ + +
+
+ + +
+

Gets a child by its name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The child or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.T + + +
+
+ + + + +
+ + + +
+

getChildren(type) → {Array.<ProtoBuf.Reflect.T>}

+ + +
+
+ + +
+

Returns an array of the namespace's children.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
type + + +ProtoBuf.Reflect.T + + + + + + <optional>
+ + + +

Filter type (returns instances of this type only). Defaults to null (all children).

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<ProtoBuf.Reflect.T> + + +
+
+ + + + +
+ + + +
+

getOption(name) → {*|Object.<string,*>}

+ + +
+
+ + +
+

Gets the value assigned to the option with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
name + + +string + + + + + + <optional>
+ + + +

Returns the option value if specified, otherwise all options are returned.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

null} Option value or NULL if there is no such option

+
+ + + +
+
+ Type +
+
+ +* +| + +Object.<string,*> + + +
+
+ + + + +
+ + + +
+

hasChild(nameOrId) → {boolean}

+ + +
+
+ + +
+

Tests if this namespace has a child with the specified name.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nameOrId + + +string +| + +number + + + +

Child name or id

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if there is one, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

resolve(qn, excludeFields) → {ProtoBuf.Reflect.Namespace|null}

+ + +
+
+ + +
+

Resolves a reflect object inside of this namespace.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
qn + + +string + + + + + + + +

Qualified name to resolve

excludeFields + + +boolean + + + + + + <optional>
+ + + +

Excludes fields, defaults to false

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

The resolved type or null if not found

+
+ + + +
+
+ Type +
+
+ +ProtoBuf.Reflect.Namespace +| + +null + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + +
Inherited From:
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.T.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.T.html new file mode 100644 index 0000000..8d97295 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.T.html @@ -0,0 +1,593 @@ + + + + + Class: T + + + + + + + + + + +
+ +

Class: T

+ + + + + +
+ +
+

+ ProtoBuf.Reflect. + + T +

+ +
+ +
+
+ + + + +
+

new T(parent, name)

+ + +
+
+ + +
+

Constructs a Reflect base class.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parent + + +ProtoBuf.Reflect.T + + + +

Parent object

name + + +string + + + +

Object name

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

name :string

+ + +
+
+ +
+

Object name in namespace.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

parent :ProtoBuf.Reflect.T|null

+ + +
+
+ +
+

Parent object.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

build()

+ + +
+
+ + +
+

Builds this type.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If this type cannot be built directly +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + + + +
+ + + +
+

fqn() → {string}

+ + +
+
+ + +
+

Returns the fully qualified name of this object.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Fully qualified name as of ".PATH.TO.THIS"

+
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + +
+ + + +
+

toString(includeClass)

+ + +
+
+ + +
+

Returns a string representation of this Reflect object (its fully qualified name).

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
includeClass + + +boolean + + + + + + <optional>
+ + + +

Set to true to include the class name. Defaults to false.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

String representation

+
+ + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.html new file mode 100644 index 0000000..249461a --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Reflect.html @@ -0,0 +1,131 @@ + + + + + Namespace: Reflect + + + + + + + + + + +
+ +

Namespace: Reflect

+ + + + + +
+ +
+

+ ProtoBuf. + + Reflect +

+ +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + +

Classes

+ +
+
Enum
+
+ +
Message
+
+ +
Namespace
+
+ +
Service
+
+ +
T
+
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.Util.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.Util.html new file mode 100644 index 0000000..57ad4b5 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.Util.html @@ -0,0 +1,564 @@ + + + + + Namespace: Util + + + + + + + + + + +
+ +

Namespace: Util

+ + + + + +
+ +
+

+ ProtoBuf. + + Util +

+ +
+ +
+
+ + + + +

ProtoBuf utilities.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + +

Members

+ +
+ +
+

<static, constant> IS_NODE :boolean

+ + +
+
+ +
+

Flag if running in node or not.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> fetch(path, callback) → {string|undefined}

+ + +
+
+ + +
+

Fetches a resource.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
path + + +string + + + + + + + +

Resource path

callback + + +function(?string) + + + + + + <optional>
+ + + +

Callback receiving the resource's contents. If omitted the resource will + be fetched synchronously. If the request failed, contents will be null.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

Resource contents if callback is omitted (null if the request failed), else undefined.

+
+ + + +
+
+ Type +
+
+ +string +| + +undefined + + +
+
+ + + + +
+ + + +
+

<static> isArray(obj) → {boolean}

+ + +
+
+ + +
+

Tests if an object is an array.

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +* + + + +

Object to test

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Returns:
+ + +
+

true if it is an array, else false

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + +
+ + + +
+

<static> XHR() → {XMLHttpRequest}

+ + +
+
+ + +
+

Constructs a XMLHttpRequest object.

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
Throws:
+ + +
+ If XMLHttpRequest is not supported +
+ + + +
+
+ Type +
+
+ +Error + + +
+
+ + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +XMLHttpRequest + + +
+
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+ + + +
+ + + + diff --git a/javascript/node_modules/protobufjs/docs/ProtoBuf.html b/javascript/node_modules/protobufjs/docs/ProtoBuf.html new file mode 100644 index 0000000..c0e5687 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/ProtoBuf.html @@ -0,0 +1,2120 @@ + + + + + Namespace: ProtoBuf + + + + + + + + + + +
+ +

Namespace: ProtoBuf

+ + + + + +
+ +
+

+ ProtoBuf +

+ +
+ +
+
+ + + + +

The ProtoBuf namespace.

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + +

Classes

+ +
+
Builder
+
+
+ + + +

Namespaces

+ +
+
DotProto
+
+ +
Lang
+
+ +
Reflect
+
+ +
Util
+
+
+ + + +

Members

+ +
+ +
+

<static> convertFieldsToCamelCase :boolean

+ + +
+
+ +
+

If set to true, field names will be converted from underscore notation to camel case. Defaults to false. + Must be set prior to parsing.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static> Long :Long

+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> TYPES :Object.<string,{name: string, wireType: number}>

+ + +
+
+ +
+

Types.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> VERSION :string

+ + +
+
+ +
+

ProtoBuf.js version.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> WIRE_TYPES :Object.<string,number>

+ + +
+
+ +
+

Wire types.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> WIRE_TYPES.BITS32 :number

+ + +
+
+ +
+

Fixed 32 bits wire type.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> WIRE_TYPES.BITS64 :number

+ + +
+
+ +
+

Fixed 64 bits wire type.

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+

<static, constant> WIRE_TYPES.ENDGROUP :number

+ + +
+
+ +
+

End group wire type.

+
+ + + +
+ + + + + + + + + +
Deprecated:
  • Not supported.
    + + + + + + + + + + + + + + + +
    + + + +
    + + + +
    +

    <static, constant> WIRE_TYPES.LDELIM :number

    + + +
    +
    + +
    +

    Length delimited wire type.

    +
    + + + +
    + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + +
    +

    <static, constant> WIRE_TYPES.STARTGROUP :number

    + + +
    +
    + +
    +

    Start group wire type.

    +
    + + + +
    + + + + + + + + + +
    Deprecated:
    • Not supported.
      + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> WIRE_TYPES.VARINT :number

      + + +
      +
      + +
      +

      Varint wire type.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + +
      + + + +

      Methods

      + +
      + +
      +

      <static> loadJson(json, builder, filename) → {ProtoBuf.Builder}

      + + +
      +
      + + +
      +

      Loads a .json definition and returns the Builder.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      json + + +* +| + +string + + + + + + + +

      JSON definition

      builder + + +ProtoBuf.Builder +| + +string +| + +{root: string, file: string} + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      filename + + +string +| + +{root: string, file: string} + + + + + + <optional>
      + + + +

      The corresponding file name if known. Must be specified for imports.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the definition cannot be parsed or built +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Builder to create new messages

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder + + +
      +
      + + + + +
      + + + +
      +

      <static> loadJsonFile(filename, callback, builder) → {ProtoBuf.Builder|undefined}

      + + +
      +
      + + +
      +

      Loads a .json file and returns the Builder.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      filename + + +string +| + +{root: string, file: string} + + + + + + + +

      Path to json file or an object specifying 'file' with + an overridden 'root' path for all imported files.

      callback + + +function(ProtoBuf.Builder) + + + + + + <optional>
      + + + +

      Callback that will receive the Builder as its first argument. + If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + function will return the Builder or NULL if the request has failed.

      builder + + +ProtoBuf.Builder + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The Builder if synchronous (no callback specified, will be NULL if the + request has failed), else undefined

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder +| + +undefined + + +
      +
      + + + + +
      + + + +
      +

      <static> loadProto(proto, builder, filename) → {ProtoBuf.Builder}

      + + +
      +
      + + +
      +

      Loads a .proto string and returns the Builder.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      proto + + +string + + + + + + + +

      .proto file contents

      builder + + +ProtoBuf.Builder +| + +string +| + +{root: string, file: string} + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      filename + + +string +| + +{root: string, file: string} + + + + + + <optional>
      + + + +

      The corresponding file name if known. Must be specified for imports.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the definition cannot be parsed or built +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Builder to create new messages

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder + + +
      +
      + + + + +
      + + + +
      +

      <static> loadProtoFile(filename, callback, builder) → {ProtoBuf.Builder|undefined}

      + + +
      +
      + + +
      +

      Loads a .proto file and returns the Builder.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      filename + + +string +| + +{root: string, file: string} + + + + + + + +

      Path to proto file or an object specifying 'file' with + an overridden 'root' path for all imported files.

      callback + + +function(ProtoBuf.Builder) + + + + + + <optional>
      + + + +

      Callback that will receive the Builder as its first argument. + If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + function will return the Builder or NULL if the request has failed.

      builder + + +ProtoBuf.Builder + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The Builder if synchronous (no callback specified, will be NULL if the + request has failed), else undefined

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder +| + +undefined + + +
      +
      + + + + +
      + + + +
      +

      <static> newBuilder(pkg, options) → {ProtoBuf.Builder}

      + + +
      +
      + + +
      +

      Constructs a new Builder with the specified package defined.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      pkg + + +string + + + + + + <optional>
      + + + +

      Package name as fully qualified name, e.g. "My.Game". If no package is specified, the +builder will only contain a global namespace.

      options + + +Object.<string,*> + + + + + + <optional>
      + + + +

      Top level options

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      New Builder

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder + + +
      +
      + + + + +
      + + + +
      +

      <static> protoFromFile(filename, callback, builder) → {ProtoBuf.Builder|undefined}

      + + +
      +
      + + +
      +

      Loads a .proto file and returns the Builder. This is an alias of ProtoBuf.loadProtoFile.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      filename + + +string +| + +{root: string, file: string} + + + + + + + +

      Path to proto file or an object specifying 'file' with + an overridden 'root' path for all imported files.

      callback + + +function(ProtoBuf.Builder) + + + + + + <optional>
      + + + +

      Callback that will receive the Builder as its first argument. + If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + function will return the Builder or NULL if the request has failed.

      builder + + +ProtoBuf.Builder + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The Builder if synchronous (no callback specified, will be NULL if the + request has failed), else undefined

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder +| + +undefined + + +
      +
      + + + + +
      + + + +
      +

      <static> protoFromString(proto, builder, filename) → {ProtoBuf.Builder}

      + + +
      +
      + + +
      +

      Loads a .proto string and returns the Builder. This is an alias of ProtoBuf.loadProto.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      proto + + +string + + + + + + + +

      .proto file contents

      builder + + +ProtoBuf.Builder +| + +string + + + + + + <optional>
      + + + +

      Builder to append to. Will create a new one if omitted.

      filename + + +string +| + +{root: string, file: string} + + + + + + <optional>
      + + + +

      The corresponding file name if known. Must be specified for imports.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the definition cannot be parsed or built +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Builder to create new messages

      +
      + + + +
      +
      + Type +
      +
      + +ProtoBuf.Builder + + +
      +
      + + + + +
      + +
      + + + + + +
      + +
      + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/docs/index.html b/javascript/node_modules/protobufjs/docs/index.html new file mode 100644 index 0000000..5106c4a --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
      + +

      Index

      + + + + + + + +

      + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/docs/scripts/html5.js b/javascript/node_modules/protobufjs/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/protobufjs/docs/scripts/prettify/prettify.js b/javascript/node_modules/protobufjs/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/protobufjs/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p= 0.6.0" + }, + "dependencies": {}, + "devDependencies": { + "mocha": "*" + }, + "optionalDependencies": {}, + "main": "lib/open.js", + "scripts": { + "test": "node_modules/mocha/bin/mocha" + }, + "readme": "# open\n\nopen a file or url in the user's preferred application\n\n# usage\n\n```javascript\nvar open = require('open');\nopen('http://www.google.com');\n```\n\n# install\n\n npm install open\n\n# how it works\n\n- on `win32` uses `start`\n- on `darwin` uses `open`\n- otherwise uses the `xdg-open` script from [freedesktop.org](http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html)\n\n# warning\n\nThe same care should be taken when calling open as if you were calling child_process.exec directly. If it is an executable it will run in a new shell.\n", + "readmeFilename": "README.md", + "_id": "open@0.0.3", + "dist": { + "shasum": "e304f99ab36884291a0f1fabc71df4874dc11716" + }, + "_from": "open@0.0.3", + "_resolved": "https://registry.npmjs.org/open/-/open-0.0.3.tgz" +} diff --git a/javascript/node_modules/protobufjs/examples/websocket/node_modules/open/vendor/xdg-open b/javascript/node_modules/protobufjs/examples/websocket/node_modules/open/vendor/xdg-open new file mode 100644 index 0000000..13caac1 --- /dev/null +++ b/javascript/node_modules/protobufjs/examples/websocket/node_modules/open/vendor/xdg-open @@ -0,0 +1,767 @@ +#!/bin/sh +#--------------------------------------------- +# xdg-open +# +# Utility script to open a URL in the registered default application. +# +# Refer to the usage() function below for usage. +# +# Copyright 2009-2010, Fathi Boudra +# Copyright 2009-2010, Rex Dieter +# Copyright 2006, Kevin Krammer +# Copyright 2006, Jeremy White +# +# 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. +# +#--------------------------------------------- + +manualpage() +{ +cat << _MANUALPAGE +Name + + xdg-open -- opens a file or URL in the user's preferred + application + +Synopsis + + xdg-open { file | URL } + + xdg-open { --help | --manual | --version } + +Description + + xdg-open opens a file or URL in the user's preferred + application. If a URL is provided the URL will be opened in the + user's preferred web browser. If a file is provided the file + will be opened in the preferred application for files of that + type. xdg-open supports file, ftp, http and https URLs. + + xdg-open is for use inside a desktop session only. It is not + recommended to use xdg-open as root. + +Options + + --help + Show command synopsis. + + --manual + Show this manual page. + + --version + Show the xdg-utils version information. + +Exit Codes + + An exit code of 0 indicates success while a non-zero exit code + indicates failure. The following failure codes can be returned: + + 1 + Error in command line syntax. + + 2 + One of the files passed on the command line did not + exist. + + 3 + A required tool could not be found. + + 4 + The action failed. + +Examples + +xdg-open 'http://www.freedesktop.org/' + + Opens the freedesktop.org website in the user's default + browser. + +xdg-open /tmp/foobar.png + + Opens the PNG image file /tmp/foobar.png in the user's default + image viewing application. +_MANUALPAGE +} + +usage() +{ +cat << _USAGE + xdg-open -- opens a file or URL in the user's preferred + application + +Synopsis + + xdg-open { file | URL } + + xdg-open { --help | --manual | --version } + +_USAGE +} + +#@xdg-utils-common@ + +#---------------------------------------------------------------------------- +# Common utility functions included in all XDG wrapper scripts +#---------------------------------------------------------------------------- + +DEBUG() +{ + [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; + [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; + shift + echo "$@" >&2 +} + +# This handles backslashes but not quote marks. +first_word() +{ + read first rest + echo "$first" +} + +#------------------------------------------------------------- +# map a binary to a .desktop file +binary_to_desktop_file() +{ + search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + binary="`which "$1"`" + binary="`readlink -f "$binary"`" + base="`basename "$binary"`" + IFS=: + for dir in $search; do + unset IFS + [ "$dir" ] || continue + [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue + for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do + [ -r "$file" ] || continue + # Check to make sure it's worth the processing. + grep -q "^Exec.*$base" "$file" || continue + # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop"). + grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue + command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" + command="`which "$command"`" + if [ x"`readlink -f "$command"`" = x"$binary" ]; then + # Fix any double slashes that got added path composition + echo "$file" | sed -e 's,//*,/,g' + return + fi + done + done +} + +#------------------------------------------------------------- +# map a .desktop file to a binary +## FIXME: handle vendor dir case +desktop_file_to_binary() +{ + search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + desktop="`basename "$1"`" + IFS=: + for dir in $search; do + unset IFS + [ "$dir" ] && [ -d "$dir/applications" ] || continue + file="$dir/applications/$desktop" + [ -r "$file" ] || continue + # Remove any arguments (%F, %f, %U, %u, etc.). + command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" + command="`which "$command"`" + readlink -f "$command" + return + done +} + +#------------------------------------------------------------- +# Exit script on successfully completing the desired operation + +exit_success() +{ + if [ $# -gt 0 ]; then + echo "$@" + echo + fi + + exit 0 +} + + +#----------------------------------------- +# Exit script on malformed arguments, not enough arguments +# or missing required option. +# prints usage information + +exit_failure_syntax() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + echo "Try 'xdg-open --help' for more information." >&2 + else + usage + echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info." + fi + + exit 1 +} + +#------------------------------------------------------------- +# Exit script on missing file specified on command line + +exit_failure_file_missing() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + fi + + exit 2 +} + +#------------------------------------------------------------- +# Exit script on failure to locate necessary tool applications + +exit_failure_operation_impossible() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + fi + + exit 3 +} + +#------------------------------------------------------------- +# Exit script on failure returned by a tool application + +exit_failure_operation_failed() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + fi + + exit 4 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_read() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + fi + + exit 5 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to write a specified file + +exit_failure_file_permission_write() +{ + if [ $# -gt 0 ]; then + echo "xdg-open: $@" >&2 + fi + + exit 6 +} + +check_input_file() +{ + if [ ! -e "$1" ]; then + exit_failure_file_missing "file '$1' does not exist" + fi + if [ ! -r "$1" ]; then + exit_failure_file_permission_read "no permission to read file '$1'" + fi +} + +check_vendor_prefix() +{ + file_label="$2" + [ -n "$file_label" ] || file_label="filename" + file=`basename "$1"` + case "$file" in + [a-zA-Z]*-*) + return + ;; + esac + + echo "xdg-open: $file_label '$file' does not have a proper vendor prefix" >&2 + echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2 + echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2 + echo "Use --novendor to override or 'xdg-open --manual' for additional info." >&2 + exit 1 +} + +check_output_file() +{ + # if the file exists, check if it is writeable + # if it does not exists, check if we are allowed to write on the directory + if [ -e "$1" ]; then + if [ ! -w "$1" ]; then + exit_failure_file_permission_write "no permission to write to file '$1'" + fi + else + DIR=`dirname "$1"` + if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then + exit_failure_file_permission_write "no permission to create file '$1'" + fi + fi +} + +#---------------------------------------- +# Checks for shared commands, e.g. --help + +check_common_commands() +{ + while [ $# -gt 0 ] ; do + parm="$1" + shift + + case "$parm" in + --help) + usage + echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info." + exit_success + ;; + + --manual) + manualpage + exit_success + ;; + + --version) + echo "xdg-open 1.1.0 rc1" + exit_success + ;; + esac + done +} + +check_common_commands "$@" + +[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; +if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then + # Be silent + xdg_redirect_output=" > /dev/null 2> /dev/null" +else + # All output to stderr + xdg_redirect_output=" >&2" +fi + +#-------------------------------------- +# Checks for known desktop environments +# set variable DE to the desktop environments name, lowercase + +detectDE() +{ + # see https://bugs.freedesktop.org/show_bug.cgi?id=34164 + unset GREP_OPTIONS + + if [ -n "${XDG_CURRENT_DESKTOP}" ]; then + case "${XDG_CURRENT_DESKTOP}" in + GNOME) + DE=gnome; + ;; + KDE) + DE=kde; + ;; + LXDE) + DE=lxde; + ;; + XFCE) + DE=xfce + esac + fi + + if [ x"$DE" = x"" ]; then + # classic fallbacks + if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; + elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; + elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate; + elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome; + elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce; + elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce + fi + fi + + if [ x"$DE" = x"" ]; then + # fallback to checking $DESKTOP_SESSION + case "$DESKTOP_SESSION" in + gnome) + DE=gnome; + ;; + LXDE|Lubuntu) + DE=lxde; + ;; + xfce|xfce4|'Xfce Session') + DE=xfce; + ;; + esac + fi + + if [ x"$DE" = x"" ]; then + # fallback to uname output for other platforms + case "$(uname 2>/dev/null)" in + Darwin) + DE=darwin; + ;; + esac + fi + + if [ x"$DE" = x"gnome" ]; then + # gnome-default-applications-properties is only available in GNOME 2.x + # but not in GNOME 3.x + which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3" + fi +} + +#---------------------------------------------------------------------------- +# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 +# It also always returns 1 in KDE 3.4 and earlier +# Simply return 0 in such case + +kfmclient_fix_exit_code() +{ + version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'` + major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'` + minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'` + release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` + test "$major" -gt 3 && return $1 + test "$minor" -gt 5 && return $1 + test "$release" -gt 4 && return $1 + return 0 +} + +# This handles backslashes but not quote marks. +first_word() +{ + read first rest + echo "$first" +} + +last_word() +{ + read first rest + echo "$rest" +} + +open_darwin() +{ + open "$1" + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +open_kde() +{ + if kde-open -v 2>/dev/null 1>&2; then + kde-open "$1" + else + if [ x"$KDE_SESSION_VERSION" = x"4" ]; then + kfmclient openURL "$1" + else + kfmclient exec "$1" + kfmclient_fix_exit_code $? + fi + fi + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +open_gnome() +{ + if gvfs-open --help 2>/dev/null 1>&2; then + gvfs-open "$1" + else + gnome-open "$1" + fi + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +open_mate() +{ + if gvfs-open --help 2>/dev/null 1>&2; then + gvfs-open "$1" + else + mate-open "$1" + fi + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +open_xfce() +{ + exo-open "$1" + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +#----------------------------------------- +# Recursively search .desktop file + +search_desktop_file() +{ + local default="$1" + local dir="$2" + local arg="$3" + + local file="" + # look for both vendor-app.desktop, vendor/app.desktop + if [ -r "$dir/$default" ]; then + file="$dir/$default" + elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then + file="$dir/`echo $default | sed -e 's|-|/|'`" + fi + + if [ -r "$file" ] ; then + command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" + command_exec=`which $command 2>/dev/null` + arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | last_word`" + arg_one="`echo $arg | sed 's/&/\\\\&/g'`" + arguments_exec="`echo $arguments | sed -e 's*%[fFuU]*"'"$arg_one"'"*g'`" + + if [ -x "$command_exec" ] ; then + if echo $arguments | grep -iq '%[fFuU]' ; then + echo START $command_exec $arguments_exec + eval $command_exec $arguments_exec + else + echo START $command_exec $arguments_exec "$arg" + eval $command_exec $arguments_exec "$arg" + fi + + if [ $? -eq 0 ]; then + exit_success + fi + fi + fi + + for d in $dir/*/; do + [ -d "$d" ] && search_desktop_file "$default" "$d" "$arg" + done +} + + +open_generic_xdg_mime() +{ + filetype="$2" + default=`xdg-mime query default "$filetype"` + if [ -n "$default" ] ; then + xdg_user_dir="$XDG_DATA_HOME" + [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" + + xdg_system_dirs="$XDG_DATA_DIRS" + [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ + +DEBUG 3 "$xdg_user_dir:$xdg_system_dirs" + for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do + search_desktop_file "$default" "$x/applications/" "$1" + done + fi +} + +open_generic_xdg_file_mime() +{ + filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` + open_generic_xdg_mime "$1" "$filetype" +} + +open_generic_xdg_x_scheme_handler() +{ + scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`" + if [ -n $scheme ]; then + filetype="x-scheme-handler/$scheme" + open_generic_xdg_mime "$1" "$filetype" + fi +} + +open_generic() +{ + # Paths or file:// URLs + if (echo "$1" | grep -q '^file://' || + ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'); then + + local file="$1" + + # Decode URLs + if echo "$file" | grep -q '^file:///'; then + file=${file#file://} + file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")" + fi + check_input_file "$file" + + open_generic_xdg_file_mime "$file" + + if [ -f /etc/debian_version ] && + which run-mailcap 2>/dev/null 1>&2; then + run-mailcap --action=view "$file" + if [ $? -eq 0 ]; then + exit_success + fi + fi + + if mimeopen -v 2>/dev/null 1>&2; then + mimeopen -L -n "$file" + if [ $? -eq 0 ]; then + exit_success + fi + fi + fi + + open_generic_xdg_x_scheme_handler "$1" + + IFS=":" + for browser in $BROWSER; do + if [ x"$browser" != x"" ]; then + + browser_with_arg=`printf "$browser" "$1" 2>/dev/null` + if [ $? -ne 0 ]; then + browser_with_arg=$browser; + fi + + if [ x"$browser_with_arg" = x"$browser" ]; then + eval '$browser $1'$xdg_redirect_output; + else eval '$browser_with_arg'$xdg_redirect_output; + fi + + if [ $? -eq 0 ]; then + exit_success; + fi + fi + done + + exit_failure_operation_impossible "no method available for opening '$1'" +} + +open_lxde() +{ + # pcmanfm only knows how to handle file:// urls and filepaths, it seems. + if (echo "$1" | grep -q '^file://' || + ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:') + then + local file="$(echo "$1" | sed 's%^file://%%')" + + # handle relative paths + if ! echo "$file" | grep -q '^/'; then + file="$(pwd)/$file" + fi + + pcmanfm "$file" + + else + open_generic "$1" + fi + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + +[ x"$1" != x"" ] || exit_failure_syntax + +url= +while [ $# -gt 0 ] ; do + parm="$1" + shift + + case "$parm" in + -*) + exit_failure_syntax "unexpected option '$parm'" + ;; + + *) + if [ -n "$url" ] ; then + exit_failure_syntax "unexpected argument '$parm'" + fi + url="$parm" + ;; + esac +done + +if [ -z "${url}" ] ; then + exit_failure_syntax "file or URL argument missing" +fi + +detectDE + +if [ x"$DE" = x"" ]; then + DE=generic +fi + +DEBUG 2 "Selected DE $DE" + +# if BROWSER variable is not set, check some well known browsers instead +if [ x"$BROWSER" = x"" ]; then + BROWSER=links2:elinks:links:lynx:w3m + if [ -n "$DISPLAY" ]; then + BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER + fi +fi + +case "$DE" in + kde) + open_kde "$url" + ;; + + gnome*) + open_gnome "$url" + ;; + + mate) + open_mate "$url" + ;; + + xfce) + open_xfce "$url" + ;; + + lxde) + open_lxde "$url" + ;; + + generic) + open_generic "$url" + ;; + + *) + exit_failure_operation_impossible "no method available for opening '$url'" + ;; +esac diff --git a/javascript/node_modules/protobufjs/examples/websocket/package.json b/javascript/node_modules/protobufjs/examples/websocket/package.json new file mode 100644 index 0000000..2cb46a9 --- /dev/null +++ b/javascript/node_modules/protobufjs/examples/websocket/package.json @@ -0,0 +1,16 @@ +{ + "name": "protobufjs-websocket-example", + "version": "1.0.0", + "dependencies": { + "protobufjs": "latest", + "ws": "~0.4", + "open": "0.0.3" + }, + "engines": { + "node": ">=0.6" + }, + "scripts": { + "run": "node server.js" + }, + "private": true +} diff --git a/javascript/node_modules/protobufjs/examples/websocket/server.js b/javascript/node_modules/protobufjs/examples/websocket/server.js new file mode 100644 index 0000000..741182a --- /dev/null +++ b/javascript/node_modules/protobufjs/examples/websocket/server.js @@ -0,0 +1,97 @@ +// Set up: npm install +var http = require("http"), + fs = require("fs"), + path = require("path"), + ws = require("ws"), + open = require("open"), + ProtoBuf = require("protobufjs"); + +// Copy dependencies to "www/" (example specific, you usually don't have to care +var deps = [ + ["Long.min.js", "./node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.min.js"], + ["ByteBuffer.min.js", "./node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js"], + ["ProtoBuf.min.js", "./node_modules/protobufjs/ProtoBuf.min.js"] +]; +for (var i=0, dep, data; i + + + + + + + + +
      + + + + + diff --git a/javascript/node_modules/protobufjs/externs/ByteBuffer.js b/javascript/node_modules/protobufjs/externs/ByteBuffer.js new file mode 100644 index 0000000..d99ed97 --- /dev/null +++ b/javascript/node_modules/protobufjs/externs/ByteBuffer.js @@ -0,0 +1,767 @@ +/* + * Copyright 2012 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Externs for ByteBuffer.js. + * @see https://github.com/dcodeIO/ByteBuffer.js + * @externs + */ + +/** + BEGIN_NODE_INCLUDE + var ByteBuffer = require('bytebuffer'); + END_NODE_INCLUDE + */ + +/** + * @param {number=} capacity + * @param {boolean=} littleEndian + * @constructor + */ +function ByteBuffer(capacity, littleEndian) {}; + +/** + * @type {?ArrayBuffer} + */ +ByteBuffer.prototype.array; + +/** + * @type {number} + */ +ByteBuffer.prototype.offset; + +/** + * @type {number} + */ +ByteBuffer.prototype.markedOffset; + +/** + * @type {number} + */ +ByteBuffer.prototype.length; + +/** + * @type {boolean} + */ +ByteBuffer.prototype.littleEndian; + +/** + * @type {string} + * @const + */ +ByteBuffer.VERSION; + +/** + * @type {number} + * @const + */ +ByteBuffer.DEFAULT_CAPACITY = 32; + +/** + * @type {boolean} + * @const + */ +ByteBuffer.LITTLE_ENDIAN = true; + +/** + * @type {boolean} + * @const + */ +ByteBuffer.BIG_ENDIAN = false; + +/** + * @param {number=} capacity + * @param {boolean=} littleEndian + * @returns {!ByteBuffer} + * @nosideeffects + */ +ByteBuffer.allocate = function(capacity, littleEndian) {}; + +/** + * @param {!ArrayBuffer|!Buffer|!{array: ArrayBuffer}|!{buffer: ArrayBuffer}|string} buffer + * @param {(string|boolean)=} enc + * @param {boolean=} littleEndian + * @returns {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.wrap = function(buffer, enc, littleEndian) {}; + +/** + * @param {*} bb + * @returns {boolean} + * @nosideeffects + */ +ByteBuffer.isByteBuffer = function(bb) {}; + +/** + * @param {boolean=} littleEndian + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.LE = function(littleEndian) {}; + +/** + * @param {boolean=} bigEndian + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.BE = function(bigEndian) {}; + +/** + * @param {number} capacity + * @returns {boolean} + */ +ByteBuffer.prototype.resize = function(capacity) {}; + +/** + * @param {number} begin + * @param {number} end + * @returns {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.prototype.slice = function(begin, end) {}; + +/** + * @param {number} begin + * @param {number} end + * @returns {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.prototype.sliceAndCompact = function(begin, end) {}; + +/** + * @param {number} capacity + * @returns {boolean} + */ +ByteBuffer.prototype.ensureCapacity = function(capacity) {}; + +/** + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.flip = function() {}; + +/** + * @param {number=} offset + * @returns {!ByteBuffer} + * @throws {Error} + */ +ByteBuffer.prototype.mark = function(offset) {}; + +/** + * @returns {!ByteBuffer} this + */ +ByteBuffer.prototype.reset = function() {}; + +/** + * @returns {!ByteBuffer} + * @nosideeffects + */ +ByteBuffer.prototype.clone = function() {}; + +/** + * @returns {!ByteBuffer} + * @nosideeffects + */ +ByteBuffer.prototype.copy = function() {}; + +/** + * @returns {number} + * @nosideeffects + */ +ByteBuffer.prototype.remaining = function() {}; + +/** + * @returns {number} + * @nosideeffects + */ +ByteBuffer.prototype.capacity = function() {}; + +/** + * @returns {!ByteBuffer} + * @throws {Error} + */ +ByteBuffer.prototype.compact = function() {}; + +/** + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.destroy = function() {}; + +/** + * @returns {!ByteBuffer} + * @throws {Error} + */ +ByteBuffer.prototype.reverse = function() {}; + +/** + * @param {!ByteBuffer} src + * @param {number=} offset + * @returns {!ByteBuffer} + * @throws {Error} + */ +ByteBuffer.prototype.append = function(src, offset) {}; + +/** + * @param {!ByteBuffer} src + * @param {number=} offset + * @returns {!ByteBuffer} + * @throws {Error} + */ +ByteBuffer.prototype.prepend = function(src, offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeInt8 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readInt8 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeByte = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readByte = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeUint8 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readUint8 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeInt16 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readInt16 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeShort = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readShort = function (offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeUint16 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readUint16 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeInt32 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readInt32 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeInt = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readInt = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeUint32 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readUint32 = function(offset) {}; + +/** + * @param {number|Long} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeInt64 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {Long} + * @throws {Error} + */ +ByteBuffer.prototype.readInt64 = function(offset) {}; + +/** + * @param {number|Long} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeUint64 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {Long} + * @throws {Error} + */ +ByteBuffer.prototype.readUint64 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeFloat32 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readFloat32 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeFloat = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readFloat = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeFloat64 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readFloat64 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeDouble = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readDouble = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer} + */ +ByteBuffer.prototype.writeLong = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.prototype.readLong = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeVarint32 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number|!{value: number, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readVarint32 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number|{value: number, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readZigZagVarint32 = function(offset) {}; + +/** + * @param {number|Long} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + * @throws {Error} + */ +ByteBuffer.prototype.writeVarint64 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {!Long|{value: !Long, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readVarint64 = function(offset) {}; + +/** + * @param {number|Long} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + * @throws {Error} + */ +ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {!Long|!{value: !Long, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readZigZagVarint64 = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeVarint = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number|!{value: number, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readVarint = function(offset) {}; + +/** + * @param {number} value + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeZigZagVarint = function(value, offset) {}; + +/** + * @param {number=} offset + * @returns {number|{value: number, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readZigZagVarint = function(offset) {}; + +/** + * @param {number} value + * @returns {number} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.calculateVarint32 = function(value) {}; + +/** + * @param {number} value + * @returns {number} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.calculateVarint64 = function(value) {}; + +/** + * @param {string} str + * @returns {number} + * @nosideeffects + */ +ByteBuffer.calculateUTF8String = function(str) {}; + +/** + * @param {string} str + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeUTF8String = function(str, offset) {}; + +/** + * @param {number} chars + * @param {number=} offset + * @returns {string|!{string: string, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readUTF8String = function(chars, offset) {}; + +/** + * @param {number} length + * @param {number} offset + * @throws {Error} + */ +ByteBuffer.prototype.readUTF8StringBytes = function(length, offset) {}; + +/** + * @param {string} str + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeLString = function(str, offset) {}; + +/** + * @param {number=} offset + * @returns {string|!{string: string, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readLString = function(offset) {}; + +/** + * @param {string} str + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeVString = function(str, offset) {}; + +/** + * @param {number=} offset + * @returns {string|!{string: string, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readVString = function(offset) {}; + +/** + * @param {string} str + * @param {number=} offset + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeCString = function(str, offset) {}; + +/** + * @param {number=} offset + * @returns {string|!{string: string, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readCString = function(offset) {}; + +/** + * @param {*} data + * @param {number=} offset + * @param {(function(*):string)=} stringify + * @returns {!ByteBuffer|number} + */ +ByteBuffer.prototype.writeJSON = function(data, offset, stringify) {}; + +/** + * @param {number=} offset + * @param {(function(string):*)=} parse + * @returns {*|!{data: *, length: number}} + * @throws {Error} + */ +ByteBuffer.prototype.readJSON = function(offset, parse) {}; + +/** + * @param {number=} wrap + * @returns {string} + * @nosideeffects + */ +ByteBuffer.prototype.toColumns = function(wrap) {}; + +/** + * @param {function(string)=} out + */ +ByteBuffer.prototype.printDebug = function(out) {}; + +/** + * @param {boolean=} debug + * @returns {string} + * @nosideeffects + */ +ByteBuffer.prototype.toHex = function(debug) {}; + +/** + * @returns {string} + * @nosideeffects + */ +ByteBuffer.prototype.toUTF8 = function() {}; + +/** + * @returns {string} + * @nosideeffects + */ +ByteBuffer.prototype.toBase64 = function() {}; + +/** + * @param {string=} enc + * @returns {string} + * @nosideeffects + */ +ByteBuffer.prototype.toString = function(enc) {}; + +/** + * @param {boolean=} forceCopy + * @returns {ArrayBuffer} + * @nosideeffects + */ +ByteBuffer.prototype.toArrayBuffer = function(forceCopy) {}; + +/** + * @param {!ByteBuffer} src + * @param {number} offset + * @returns {!{char: number, length: number}} + * @nosideeffects + */ +ByteBuffer.decodeUTF8Char = function(src, offset) {}; + +/** + * @param {number} charCode + * @param {!ByteBuffer} dst + * @param {number} offset + * @returns {number} + * @throws {Error} + */ +ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) {}; + +/** + * @param {number} charCode + * @returns {number} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.calculateUTF8Char = function(charCode) {}; + +/** + * @param {number} n + * @returns {number} + * @nosideeffects + */ +ByteBuffer.zigZagEncode32 = function(n) {}; + +/** + * @param {number} n + * @returns {number} + * @nosideeffects + */ +ByteBuffer.zigZagDecode32 = function(n) {}; + +/** + * @param {!ByteBuffer} bb + * @returns {string} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.encode64 = function(bb) {}; + +/** + * @param {string} str + * @param {boolean=} littleEndian + * @returns {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.decode64 = function(str, littleEndian) {}; + +/** + * @param {!ByteBuffer} bb + * @returns {string} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.encodeHex = function(bb) {}; + +/** + * @param {string} str + * @param {boolean=} littleEndian + * @returns {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ByteBuffer.decodeHex = function(str, littleEndian) {}; + +/** + * @type {number} + * @const + */ +ByteBuffer.MAX_VARINT32_BYTES = 5; + +/** + * @type {number} + * @const + */ +ByteBuffer.MAX_VARINT64_BYTES = 10; diff --git a/javascript/node_modules/protobufjs/externs/Long.js b/javascript/node_modules/protobufjs/externs/Long.js new file mode 100644 index 0000000..f33180f --- /dev/null +++ b/javascript/node_modules/protobufjs/externs/Long.js @@ -0,0 +1,328 @@ +/* + * Copyright 2012 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Externs for Long.js. + * @see https://github.com/dcodeIO/Long.js + * @externs + */ + +/** + BEGIN_NODE_INCLUDE + var Long = require('long'); + END_NODE_INCLUDE + */ + +/** + * @param {number} low + * @param {number} high + * @param {boolean=} unsigned + * @constructor + */ +var Long = function(low, high, unsigned) {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @return {!Long} + */ +Long.fromInt = function(value, unsigned) {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @return {!Long} + */ +Long.fromNumber = function(value, unsigned) {}; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @return {!Long} + */ +Long.fromBits = function(lowBits, highBits, unsigned) {}; + +/** + * @param {number} part0 + * @param {number} part1 + * @param {number} part2 + * @param {boolean=} unsigned + * @return {!Long} + */ +Long.from28Bits = function(part0, part1, part2, unsigned) {}; + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @return {!Long} + */ +Long.fromString = function(str, unsigned, radix) {}; + +/** + * @type {!Long} + */ +Long.ZERO; + +/** + * @type {!Long} + */ +Long.ONE; + +/** + * @type {!Long} + */ +Long.NEG_ONE; + +/** + * @type {!Long} + */ +Long.MAX_SIGNED_VALUE; + +/** + * @type {!Long} + */ +Long.MIN_SIGNED_VALUE; + +/** + * @type {!Long} + */ +Long.MAX_UNSIGNED_VALUE; + +/** + * @type {!Long} + */ +Long.MIN_UNSIGNED_VALUE; + +/** + * @type {!Long} + */ +Long.MAX_VALUE; + +/** + * @type {!Long} + */ +Long.MIN_VALUE; + +/** + * @type {number} + */ +Long.prototype.low; + +/** + * @type {number} + */ +Long.prototype.high; + +/** + * @type {boolean} + */ +Long.prototype.unsigned; + +/** + * @return {number} + */ +Long.prototype.toInt = function() {}; + +/** + * @return {number} + */ +Long.prototype.toNumber = function() {}; + +/** + * @param {number=} radix + * @return {string} + */ +Long.prototype.toString = function(radix) {}; + +/** + * @return {number} + */ +Long.prototype.getHighBits = function() {}; + +/** + * @return {number} + */ +Long.prototype.getHighBitsUnsigned = function() {}; + +/** + * @return {number} + */ +Long.prototype.getLowBits = function() {}; + +/** + * @return {number} + */ +Long.prototype.getLowBitsUnsigned = function() {}; + +/** + * @return {number} + */ +Long.prototype.getNumBitsAbs = function() {}; + +/** + * @return {boolean} + */ +Long.prototype.isZero = function() {}; + +/** + * @return {boolean} + */ +Long.prototype.isNegative = function() {}; + +/** + * @return {boolean} + */ +Long.prototype.isOdd = function() {}; + +/** + * @return {boolean} + */ +Long.prototype.isEven = function() {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.equals = function(other) {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.notEquals = function(other) {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.lessThan = function(other) {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.lessThanOrEqual = function(other) {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.greaterThan = function(other) {}; + +/** + * @param {Long} other + * @return {boolean} + */ +Long.prototype.greaterThanOrEqual = function(other) {}; + +/** + * @param {Long} other + * @return {number} + */ +Long.prototype.compare = function(other) {}; + +/** + * @return {!Long} + */ +Long.prototype.negate = function() {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.add = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.subtract = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.multiply = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.div = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.modulo = function(other) {}; + +/** + * @return {!Long} + */ +Long.prototype.not = function() {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.and = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.or = function(other) {}; + +/** + * @param {Long} other + * @return {!Long} + */ +Long.prototype.xor = function(other) {}; + +/** + * @param {number} numBits + * @return {!Long} + */ +Long.prototype.shiftLeft = function(numBits) {}; + +/** + * @param {number} numBits + * @return {!Long} + */ +Long.prototype.shiftRight = function(numBits) {}; + +/** + * @param {number} numBits + * @return {!Long} + */ +Long.prototype.shiftRightUnsigned = function(numBits) {}; + +/** + * @return {!Long} + */ +Long.prototype.toSigned = function() {}; + +/** + * @return {!Long} + */ +Long.prototype.toUnsigned = function() {}; + +/** + * @return {!Long} + */ +Long.prototype.clone = function() {}; diff --git a/javascript/node_modules/protobufjs/externs/ProtoBuf.js b/javascript/node_modules/protobufjs/externs/ProtoBuf.js new file mode 100644 index 0000000..3eb3b24 --- /dev/null +++ b/javascript/node_modules/protobufjs/externs/ProtoBuf.js @@ -0,0 +1,875 @@ +/* + * Copyright 2012 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Externs for ProtoBuf.js. + * @see https://github.com/dcodeIO/ProtoBuf.js + * @externs + */ + +/** + BEGIN_NODE_INCLUDE + var ProtoBuf = require('protobufjs'); + END_NODE_INCLUDE + */ + +/** + * {@type object.} + */ +var ProtoBuf = {}; + +/** + * @type {string} + * @const + */ +ProtoBuf.VERSION = "0.9.2"; + +/** + * @type {!object.} + * @const + */ +ProtoBuf.WIRE_TYPES = {}; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.VARINT = 0; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.BITS64 = 1; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.LDELIM = 2; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.STARTGROUP = 3; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.ENDGROUP = 4; + +/** + * @type {number} + * @const + */ +ProtoBuf.WIRE_TYPES.BITS32 = 5; + +/** + * @type {boolean} + */ +ProtoBuf.convertFieldsToCamelCase = false; + +/** + * @dict + * @type {!object.} + * @const + */ +ProtoBuf.TYPES = { + "int32": { + name: "int32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint32": { + name: "uint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint32": { + name: "sint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "bool": { + name: "bool", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "double": { + name: "double", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "string": { + name: "string", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "bytes": { + name: "bytes", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "fixed32": { + name: "fixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "sfixed32": { + name: "sfixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "float": { + name: "float", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "enum": { + name: "enum", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "message": { + name: "message", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + } +}; + +/** + * @type {!object.} + */ +ProtoBuf.Lang = {}; + +/** + * @type {!object.} + */ +ProtoBuf.DotProto = {}; + +/** + * @param {string} proto + * @constructor + */ +ProtoBuf.DotProto.Tokenizer = function(proto) {}; + +/** + * @type {string} + */ +ProtoBuf.DotProto.Tokenizer.prototype.source; + +/** + * @type {number} + */ +ProtoBuf.DotProto.Tokenizer.prototype.index; + +/** + * @type {number} + */ +ProtoBuf.DotProto.Tokenizer.prototype.line; + +/** + * @type {array.} + */ +ProtoBuf.DotProto.Tokenizer.prototype.stack; + +/** + * @type {boolean} + */ +ProtoBuf.DotProto.Tokenizer.prototype.readingString; + +/** + * @return {?string} + * @throws {Error} + */ +ProtoBuf.DotProto.Tokenizer.prototype.next = function() {}; + +/** + * @return {?string} + * @thorws {Error} + */ +ProtoBuf.DotProto.Tokenizer.prototype.peek = function() {}; + +/** + * @return {string} + * @nosideeffects + */ +ProtoBuf.DotProto.Tokenizer.prototype.toString = function() {}; + +/** + * @param {string} proto + * @constructor + */ +ProtoBuf.DotProto.Parser = function(proto) {}; + +/** + * @type {!ProtoBuf.DotProto.Tokenizer} + */ +ProtoBuf.DotProto.Parser.prototype.tn; + +/** + * @return {{package: string|null, messages: Array., enums: Array., imports: Array., options: object}} + * @throws {Error} + */ +ProtoBuf.DotProto.Parser.prototype.parse = function() {}; + +/** + * @return {string} + * @nosideeffects + */ +ProtoBuf.DotProto.Parser.prototype.toString = function() {}; + +/** + * @type {Object.} + */ +ProtoBuf.Reflect.Reflect = {}; + +/** + * @constructor + * @param {ProtoBuf.Reflect.T} parent + * @param {string} name Object name + */ +ProtoBuf.Reflect.T = function(parent, name) {}; + +/** + * @type {?ProtoBuf.Reflect.T} + */ +ProtoBuf.Reflect.T.prototype.parent; + +/** + * @type {string} + */ +ProtoBuf.Reflect.T.prototype.name; + +/** + * @returns {string} + * @nosideeffects + */ +ProtoBuf.Reflect.T.prototype.fqn = function() {}; + +/** + * @param {boolean=} includeClass + * @returns {string} + * @nosideeffects + */ +ProtoBuf.Reflect.T.prototype.toString = function(includeClass) {}; + +/** + * @throws {Error} + */ +ProtoBuf.Reflect.T.prototype.build = function() {}; + +/** + * @param {?ProtoBuf.Reflect.Namespace} parent + * @param {string} name + * @constructor + * @extends ProtoBuf.Reflect.T + */ +ProtoBuf.Reflect.Namespace = function(parent, name) {}; + +/** + * @type {Array.} + */ +ProtoBuf.Reflect.Namespace.prototype.children; + +/** + * @param {ProtoBuf.Reflect.T=} type + * @return {Array.} + * @nosideeffects + */ +ProtoBuf.Reflect.Namespace.prototype.getChildren = function(type) {}; + +/** + * @param {ProtoBuf.Reflect.T} child + * @throws {Error} + */ +ProtoBuf.Reflect.Namespace.prototype.addChild = function(child) {}; + +/** + * @param {string|number} nameOrId + * @returns {boolean} + * @nosideeffects + */ +ProtoBuf.Reflect.Namespace.prototype.hasChild = function(nameOrId) {}; + +/** + * @param {string|number} nameOrId + * @return {?ProtoBuf.Reflect.T} + * @nosideeffects + */ +ProtoBuf.Reflect.Namespace.prototype.getChild = function(nameOrId) {}; + +/** + * @param {string} qn + * @param {boolean=} excludeFields + * @return {?ProtoBuf.Reflect.Namespace} + * @nosideeffects + */ +ProtoBuf.Reflect.Namespace.prototype.resolve = function(qn, excludeFields) {}; + +/** + * @return {Object.} + */ +ProtoBuf.Reflect.Namespace.prototype.build = function() {}; + +/** + * @param {!ProtoBuf.Reflect.Namespace} parent + * @param {string} name + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ +ProtoBuf.Reflect.Message = function(parent, name) {}; + +/** + * @type {?Array.} + */ +ProtoBuf.Reflect.Message.prototype.extensions; + +/** + * @type {?ProtoBuf.Builder.Message} + */ +ProtoBuf.Reflect.Message.prototype.clazz; + +/** + * @return {!ProtoBuf.Builder.Message} + * @throws {Error} + */ +ProtoBuf.Reflect.Message.prototype.build = function() {}; + +/** + * @param {!ProtoBuf.Builder.Message} message + * @param {!ByteBuffer} buffer + * @return {!ByteBuffer} + * @throws {string} + */ +ProtoBuf.Reflect.Message.prototype.encode = function(message, buffer) {}; + +/** + * @param {!ByteBuffer} buffer + * @param {number=} length + * @return {!ProtoBuf.Builder.Message} + * @throws {Error} + */ +ProtoBuf.Reflect.Message.prototype.decode = function(buffer, length) {}; + +/** + * @param {!ProtoBuf.Reflect.Message} message + * @param {string} rule + * @param {string} type + * @param {string} name + * @param {number} id + * @param {Object.=} options + * @constructor + * @extends ProtoBuf.Reflect.T + */ +ProtoBuf.Reflect.Message.Field = function(message, rule, type, name, id, options) {}; + +/** + * @type {boolean} + */ +ProtoBuf.Reflect.Message.Field.prototype.required; + +/** + * @type {boolean} + */ +ProtoBuf.Reflect.Message.Field.prototype.repeated; + +/** + * @type {string|{name: string, wireType: number}} + */ +ProtoBuf.Reflect.Message.Field.prototype.type; + +/** + * @type {number} + */ +ProtoBuf.Reflect.Message.Field.prototype.id; + +/** + * @type {!Object.} + */ +ProtoBuf.Reflect.Message.Field.prototype.options; + +/** + * @type {?ProtoBuf.Reflect.T} + */ +ProtoBuf.Reflect.Message.Field.prototype.resolvedType; + +/** + * @type {string} + */ +ProtoBuf.Reflect.Message.Field.prototype.originalName; + +/** + * @param {*} value + * @param {boolean=} skipRepeated + * @return {*} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Reflect.Message.Field.prototype.verifyValue = function(value, skipRepeated) {}; + +/** + * @param {*} value + * @param {!ByteBuffer} buffer + * @return {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Reflect.Message.Field.prototype.encode = function(value, buffer) {}; + +/** + * @param {number} wireType + * @param {!ByteBuffer} buffer + * @return {*} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Reflect.Message.Field.prototype.decode = function(wireType, buffer) {}; + +/** + * @param {*} value + * @param {!ByteBuffer} buffer + * @return {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Reflect.Message.Field.prototype.encodeValue = function(value, buffer) {}; + +/** + * @param {!ProtoBuf.Reflect.T} parent + * @param {string} name + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ +ProtoBuf.Reflect.Enum = function(parent, name) {}; + +/** + * @return {Object} + */ +ProtoBuf.Reflect.Enum.prototype.build = function() {}; + +/** + * @type {?Object.} + */ +ProtoBuf.Reflect.Enum.prototype.object; + +/** + * @param {!ProtoBuf.Reflect.Enum} enm + * @param {string} name + * @param {number} id + * @constructor + * @extends ProtoBuf.Reflect.T + */ +ProtoBuf.Reflect.Enum.Value = function(enm, name, id) {}; + +/** + * @type {number} + */ +ProtoBuf.Reflect.Enum.Value.prototype.id; + +/** + * @param {!ProtoBuf.Reflect.Namespace} root + * @param {string} name Service name + * @param {Object.=} options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ +ProtoBuf.Reflect.Service = function(root, name, options) {}; + +/** + * @type {ProtoBuf.Builder.Service} + */ +ProtoBuf.Reflect.Service.prototype.clazz; + +/** + * @return {!ProtoBuf.Builder.Service} + * @throws {Error} + */ +ProtoBuf.Reflect.Service.prototype.build = function() {}; + +/** + * @param {!ProtoBuf.Reflect.Service} svc + * @param {string} name + * @param {Object.=} options + * @constructor + * @extends ProtoBuf.Reflect.T + */ +ProtoBuf.Reflect.Service.Method = function(svc, name, options) {}; + +/** + * @return {Object.} + */ +ProtoBuf.Reflect.Service.Method.prototype.buildOpt = function() {}; + +/** + * @param {!ProtoBuf.Reflect.Service} svc + * @param {string} name + * @param {string} request + * @param {string} response + * @param {Object.=} options + * @constructor + * @extends ProtoBuf.Reflect.Service.Method + */ +ProtoBuf.Reflect.Service.RPCMethod = function(svc, name, request, response, options) {}; + +/** + * @type {string} + */ +ProtoBuf.Reflect.Service.RPCMethod.prototype.requestName; + +/** + * @type {string} + */ +ProtoBuf.Reflect.Service.RPCMethod.prototype.responseName; + +/** + * @type {ProtoBuf.Reflect.Message} + */ +ProtoBuf.Reflect.Service.RPCMethod.prototype.resolvedRequestType; + +/** + * @type {ProtoBuf.Reflect.Message} + */ +ProtoBuf.Reflect.Service.RPCMethod.prototype.resolvedResponseType; + +/** + * @constructor + */ +ProtoBuf.Builder = function() {}; + +/** + * @type {!ProtoBuf.Reflect.Namespace} + */ +ProtoBuf.Builder.prototype.ns; + +/** + * @type {?ProtoBuf.Reflect.T} + */ +ProtoBuf.Builder.prototype.ptr; + +/** + * @type {boolean} + */ +ProtoBuf.Builder.prototype.resolved; + +/** + * @type {Object.|null} + */ +ProtoBuf.Builder.prototype.result; + +/** + * @type {Array.} + */ +ProtoBuf.Builder.prototype.files; + +/** + * @type {?string} + */ +ProtoBuf.Builder.prototype.importRoot; + +/** + */ +ProtoBuf.Builder.prototype.reset = function() {}; + +/** + * @param {string} pkg + * @return {!ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.Builder.prototype.define = function(pkg) {}; + +/** + * @param {Object.} def + * @return {boolean} + * @nosideeffects + */ +ProtoBuf.Builder.isValidMessage = function(def) {}; + +/** + * @param {Object.} def + * @return {boolean} + * @nosideeffects + */ +ProtoBuf.Builder.isValidMessageField = function(def) {}; + +/** + * @param {Object.} def + * @return {boolean} + */ +ProtoBuf.Builder.isValidEnum = function(def) {}; + +/** + * @param {Object.} def + * @return {boolean} + */ +ProtoBuf.Builder.isValidService = function(def) {}; + +/** + * @param {Object.} def + * @return {boolean} + */ +ProtoBuf.Builder.isValidExtend = function(def) {}; + +/** + * @param {Array.>} messages + * @return {ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.Builder.prototype.create = function(messages) {}; + +/** + * @name ProtoBuf.Builder.prototype.import + * @function + * @param {ProtoBuf.Builder} builder + * @param {(string|{root: string, file: string})=} filename + * @return {!ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.Builder.prototype["import"] = function(builder, filename) {}; + +/** + * @throws {Error} + */ +ProtoBuf.Builder.prototype.resolveAll = function() {}; + +/** + * @param {string=} path + * @return {ProtoBuf.Builder.Message|Object.} + * @throws {Error} + */ +ProtoBuf.Builder.prototype.build = function(path) {}; + +/** + * @param {string=} path + * @return {?ProtoBuf.Reflect.T} + */ +ProtoBuf.Builder.prototype.lookup = function(path) {}; + +/** + * @return {string} + * @nosideeffects + */ +ProtoBuf.Builder.prototype.toString = function() {}; + +/** + * @param {Object.} values + * @constructor + * @throws {Error} + */ +ProtoBuf.Builder.Message = function(values) {}; + +/** + * @param {string} key + * @param {*} value + * @throws {Error} + */ +ProtoBuf.Builder.Message.prototype.add = function(key, value) {}; + +/** + * @param {string} key + * @param {*} value + * @throws {Error} + */ +ProtoBuf.Builder.Message.prototype.set = function(key, value) {}; + +/** + * @param {string} key + * @return {*} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.get = function(key) {}; + +/** + * @param {ByteBuffer=} buffer + * @return {!ByteBuffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.encode = function(buffer) {}; + +/** + * @return {!ArrayBuffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.encodeAB = function() {}; + +/** + * @return {!ArrayBuffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.toArrayBuffer = function() {}; + +/** + * @return {!Buffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.encodeNB = function() {}; + +/** + * @return {!Buffer} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.toBuffer = function() {}; + +/** + * @return {string} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.encode64 = function() {}; + +/** + * @return {string} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.toBase64 = function() {}; + +/** + * @return {string} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.encodeHex = function() {}; + +/** + * @return {string} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.toHex = function() {}; + +/** + * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer + * @param {string=} enc + * @return {!ProtoBuf.Builder.Message} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.decode = function(buffer, enc) {}; + +/** + * @param {string} str + * @return {!ProtoBuf.Builder.Message} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.decode64 = function(str) {}; + +/** + * @param {string} str + * @return {!ProtoBuf.Builder.Message} + * @throws {Error} + * @nosideeffects + */ +ProtoBuf.Builder.Message.decodeHex = function(str) {}; + +/** + * @return {string} + * @nosideeffects + */ +ProtoBuf.Builder.Message.prototype.toString = function() {}; + +/** + * @param {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} rpcImpl + * @constructor + */ +ProtoBuf.Builder.Service = function(rpcImpl) {}; + +/** + * @type {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} + */ +ProtoBuf.Builder.prototype.rpcImpl; + +/** + * @param {string} proto + * @param {(ProtoBuf.Builder|string)=} builder + * @param {(string|{root: string, file: string})=} filename + * @return {!ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.loadProto = function(proto, builder, filename) {}; + +/** + * @param {string} proto + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder + * @param {(string|{root: string, file: string})=} filename + * @return {!ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.protoFromString = function(proto, builder, filename) {}; + +/** + * @param {string|{root: string, file: string}} filename + * @param {(function(ProtoBuf.Builder)|ProtoBuf.Builder)=} callback + * @param {ProtoBuf.Builder=} builder + * @return {ProtoBuf.Builder|undefined} + * @throws {Error} + */ +ProtoBuf.loadProtoFile = function(filename, callback, builder) {}; + +/** + * @param {string|{root: string, file: string}} filename + * @param {(function(ProtoBuf.Builder)|ProtoBuf.Builder)=} callback + * @param {ProtoBuf.Builder=} builder + * @return {ProtoBuf.Builder|undefined} + * @throws {Error} + */ +ProtoBuf.protoFromFile = function(filename, callback, builder) {}; + +/** + * @param {!*|string} proto + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder + * @param {(string|{root: string, file: string})=} filename + * @return {!ProtoBuf.Builder} + * @throws {Error} + */ +ProtoBuf.loadJson = function(json, builder, filename) {}; + +/** + * @param {string|{root: string, file: string}} filename + * @param {(function(ProtoBuf.Builder)|ProtoBuf.Builder)=} callback + * @param {ProtoBuf.Builder=} builder + * @return {ProtoBuf.Builder|undefined} + * @throws {Error} + */ +ProtoBuf.loadJsonFile = function(filename, callback, builder) {}; + +/** + * @param {string=} pkg + * @return {!ProtoBuf.Builder} + */ +ProtoBuf.newBuilder = function(pkg) {}; + +ProtoBuf.Util = {}; + +/** + * @type {boolean} + */ +ProtoBuf.Util.IS_NODE; + +/** + * @return {XMLHttpRequest} + */ +ProtoBuf.Util.XHR = function() {}; + +/** + * @param {string} path + * @param {function(?string)=} callback + * @return {?string|undefined} + */ +ProtoBuf.Util.fetch = function(path, callback) {}; + +/** + * @param {*} obj + * @return {boolean} + */ +ProtoBuf.Util.isArray = function(obj) {}; diff --git a/javascript/node_modules/protobufjs/externs/fs.js b/javascript/node_modules/protobufjs/externs/fs.js new file mode 100644 index 0000000..04b422d --- /dev/null +++ b/javascript/node_modules/protobufjs/externs/fs.js @@ -0,0 +1,644 @@ +/* + * Copyright 2012 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Definitions for node's "fs" module. + * @see http://nodejs.org/api/fs.html + * @externs + * @author Daniel Wirtz + */ + +/** + BEGIN_NODE_INCLUDE + var fs = require('fs'); + END_NODE_INCLUDE + */ + +var fs = {}; + +/** + * @param {string} oldPath + * @param {string} newPath + * @param {function(...)=} callback + */ +fs.rename = function(oldPath, newPath, callback) {}; + +/** + * @param {string} oldPath + * @param {string} newPath + */ +fs.renameSync = function(oldPath, newPath) {}; + +/** + * @param {*} fd + * @param {number} len + * @param {function(...)=} callback + */ +fs.truncate = function(fd, len, callback) {}; + +/** + * @param {*} fd + * @param {number} len + */ +fs.truncateSync = function(fd, len) {}; + +/** + * @param {string} path + * @param {number} uid + * @param {number} gid + * @param {function(...)=} callback + */ +fs.chown = function(path, uid, gid, callback) {}; + +/** + * @param {string} path + * @param {number} uid + * @param {number} gid + */ +fs.chownSync = function(path, uid, gid) {}; + +/** + * @param {*} fd + * @param {number} uid + * @param {number} gid + * @param {function(...)=} callback + */ +fs.fchown = function(fd, uid, gid, callback) {}; + +/** + * @param {*} fd + * @param {number} uid + * @param {number} gid + */ +fs.fchownSync = function(fd, uid, gid) {}; + +/** + * @param {string} path + * @param {number} uid + * @param {number} gid + * @param {function(...)=} callback + */ +fs.lchown = function(path, uid, gid, callback) {}; + +/** + * @param {string} path + * @param {number} uid + * @param {number} gid + */ +fs.lchownSync = function(path, uid, gid) {}; + +/** + * @param {string} path + * @param {number} mode + * @param {function(...)=} callback + */ +fs.chmod = function(path, mode, callback) {}; + +/** + * @param {string} path + * @param {number} mode + */ +fs.chmodSync = function(path, mode) {}; + +/** + * @param {*} fd + * @param {number} mode + * @param {function(...)=} callback + */ +fs.fchmod = function(fd, mode, callback) {}; + +/** + * @param {*} fd + * @param {number} mode + */ +fs.fchmodSync = function(fd, mode) {}; + +/** + * @param {string} path + * @param {number} mode + * @param {function(...)=} callback + */ +fs.lchmod = function(path, mode, callback) {}; + +/** + * @param {string} path + * @param {number} mode + */ +fs.lchmodSync = function(path, mode) {}; + +/** + * @param {string} path + * @param {function(string, fs.Stats)=} callback + * @nosideeffects + */ +fs.stat = function(path, callback) {}; + +/** + * @param {string} path + * @return {fs.Stats} + * @nosideeffects + */ +fs.statSync = function(path) {} + +/** + * @param {*} fd + * @param {function(string, fs.Stats)=} callback + * @nosideeffects + */ +fs.fstat = function(fd, callback) {}; + +/** + * @param {*} fd + * @return {fs.Stats} + * @nosideeffects + */ +fs.fstatSync = function(fd) {} + +/** + * @param {string} path + * @param {function(string, fs.Stats)=} callback + * @nosideeffects + */ +fs.lstat = function(path, callback) {}; + +/** + * @param {string} path + * @return {fs.Stats} + * @nosideeffects + */ +fs.lstatSync = function(path) {} + +/** + * @param {string} srcpath + * @param {string} dstpath + * @param {function(...)=} callback + */ +fs.link = function(srcpath, dstpath, callback) {}; + +/** + * @param {string} srcpath + * @param {string} dstpath + */ +fs.linkSync = function(srcpath, dstpath) {}; + +/** + * @param {string} srcpath + * @param {string} dstpath + * @param {string=} type + * @param {function(...)=} callback + */ +fs.symlink = function(srcpath, dstpath, type, callback) {}; + +/** + * @param {string} srcpath + * @param {string} dstpath + * @param {string=} type + */ +fs.symlinkSync = function(srcpath, dstpath, type) {}; + +/** + * @param {string} path + * @param {function(string, string)=} callback + * @nosideeffects + */ +fs.readlink = function(path, callback) {}; + +/** + * @param {string} path + * @return {string} + * @nosideeffects + */ +fs.readlinkSync = function(path) {}; + +/** + * @param {string} path + * @param {object.=|function(string, string)=} cache + * @param {function(string, string)=} callback + * @nosideeffects + */ +fs.realpath = function(path, cache, callback) {}; + +/** + * @param {string} path + * @param {object.=} cache + * @return {string} + * @nosideeffects + */ +fs.realpathSync = function(path, cache) {}; + +/** + * @param {string} path + * @param {function(...)=} callback + */ +fs.unlink = function(path, callback) {}; + +/** + * @param {string} path + */ +fs.unlinkSync = function(path) {}; + +/** + * @param {string} path + * @param {function(...)=} callback + */ +fs.rmdir = function(path, callback) {}; + +/** + * @param {string} path + */ +fs.rmdirSync = function(path) {}; + +/** + * @param {string} path + * @param {number=} mode + * @param {function(...)=} callback + */ +fs.mkdir = function(path, mode, callback) {}; + +/** + * @param {string} path + * @param {number=} mode + */ +fs.mkdirSync = function(path, mode) {}; + +/** + * @param {string} path + * @param {function(string,array.)=} callback + * @nosideeffects + */ +fs.readdir = function(path, callback) {}; + +/** + * @param {string} path + * @return {array.} + * @nosideeffects + */ +fs.readdirSync = function(path) {}; + +/** + * @param {*} fd + * @param {function(...)=} callback + */ +fs.close = function(fd, callback) {}; + +/** + * @param {*} fd + */ +fs.closeSync = function(fd) {}; + +/** + * @param {string} path + * @param {string} flags + * @param {number=} mode + * @param {function(string, *)=} callback + * @nosideeffects + */ +fs.open = function(path, flags, mode, callback) {}; + +/** + * @param {string} path + * @param {string} flags + * @param {number=} mode + * @return {*} + * @nosideeffects + */ +fs.openSync = function(path, flags, mode) {}; + +/** + * @param {string} path + * @param {number} atime + * @param {number} mtime + * @param {function(...)=} callback + * @nosideeffects + */ +fs.utimes = function(path, atime, mtime, callback) {}; + +/** + * @param {string} path + * @param {number} atime + * @param {number} mtime + * @nosideeffects + */ +fs.utimesSync = function(path, atime, mtime) {}; + +/** + * @param {*} fd + * @param {number} atime + * @param {number} mtime + * @param {function(...)=} callback + * @nosideeffects + */ +fs.futimes = function(fd, atime, mtime, callback) {}; + +/** + * @param {*} fd + * @param {number} atime + * @param {number} mtime + * @nosideeffects + */ +fs.futimesSync = function(fd, atime, mtime) {}; + +/** + * @param {*} fd + * @param {function(...)=} callback + */ +fs.fsync = function(fd, callback) {}; + +/** + * @param {*} fd + */ +fs.fsyncSync = function(fd) {}; + +/** + * @param {*} fd + * @param {*} buffer + * @param {number} offset + * @param {number} length + * @param {number} position + * @param {function(string, number, *)=} callback + */ +fs.write = function(fd, buffer, offset, length, position, callback) {}; + +/** + * @param {*} fd + * @param {*} buffer + * @param {number} offset + * @param {number} length + * @param {number} position + * @return {number} + */ +fs.writeSync = function(fd, buffer, offset, length, position) {}; + +/** + * @param {*} fd + * @param {*} buffer + * @param {number} offset + * @param {number} length + * @param {number} position + * @param {function(string, number, *)=} callback + * @nosideeffects + */ +fs.read = function(fd, buffer, offset, length, position, callback) {}; + +/** + * @param {*} fd + * @param {*} buffer + * @param {number} offset + * @param {number} length + * @param {number} position + * @return {number} + * @nosideeffects + */ +fs.readSync = function(fd, buffer, offset, length, position) {}; + +/** + * @param {string} filename + * @param {string=|function(string, *)=}encoding + * @param {function(string, *)=} callback + * @nosideeffects + */ +fs.readFile = function(filename, encoding, callback) {}; + +/** + * @param {string} filename + * @param {string=} encoding + * @nosideeffects + */ +fs.readFileSync = function(filename, encoding) {}; + +/** + * @param {string} filename + * @param {*} data + * @param {string=|function(string)=} encoding + * @param {function(string)=} callback + */ +fs.writeFile = function(filename, data, encoding, callback) {}; + +/** + * @param {string} filename + * @param {*} data + * @param {string=} encoding + */ +fs.writeFileSync = function(filename, data, encoding) {}; + +/** + * @param {string} filename + * @param {*} data + * @param {string=|function(string)=} encoding + * @param {function(string)=} callback + */ +fs.appendFile = function(filename, data, encoding, callback) {}; + +/** + * @param {string} filename + * @param {*} data + * @param {string=|function(string)=} encoding + */ +fs.appendFileSync = function(filename, data, encoding) {}; + +/** + * @param {string} filename + * @param {{persistent: boolean, interval: number}=|function(*,*)} options + * @param {function(*,*)=} listener + */ +fs.watchFile = function(filename, options, listener) {}; + +/** + * @param {string} filename + * @param {function=} listener + */ +fs.unwatchFile = function(filename, listener) {}; + +/** + * + * @param {string} filename + * @param {{persistent: boolean}=|function(string, string)} options + * @param {function(string, string)=} listener + * @return {fs.FSWatcher} + */ +fs.watch = function(filename, options, listener) {}; + +/** + * @param {string} path + * @param {function(boolean)} callback + * @nosideeffects + */ +fs.exists = function(path, callback) {}; + +/** + * @param {string} path + * @nosideeffects + */ +fs.existsSync = function(path) {}; + +/** + * @constructor + */ +fs.Stats = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isFile = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isDirectory = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isBlockDevice = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isCharacterDevice = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isSymbolicLink = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isFIFO = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +fs.Stats.prototype.isSocket = function() {}; + +/** + * @type {number} + */ +fs.Stats.prototype.dev = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.ino = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.mode = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.nlink = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.uid = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.gid = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.rdev = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.size = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.blkSize = 0; + +/** + * @type {number} + */ +fs.Stats.prototype.blocks = 0; + +/** + * @type {Date} + */ +fs.Stats.prototype.atime = 0; + +/** + * @type {Date} + */ +fs.Stats.prototype.mtime = 0; + +/** + * @type {Date} + */ +fs.Stats.prototype.ctime = 0; + +/** + * @param {string} path + * @param {{flags: string, encoding: ?string, fd: *, mode: number, bufferSize: number}=} options + * @nosideeffects + */ +fs.createReadStream = function(path, options) {}; + +/** + * @constructor + * @extends {stream.ReadableStream} + */ +fs.ReadStream = function() {}; + +/** + * @param {string} path + * @param {{flags: string, encoding: ?string, mode: number}=} options + * @nosideeffects + */ +fs.createWriteStream = function(path, options) {}; + +/** + * @constructor + * @extends {stream.WritableStream} + */ +fs.WriteStream = function() {}; + +/** + * @param {string} event + * @param {function(...)} callback + */ +fs.WriteStream.prototype.on = function(event, callback) {}; + +/** + * @constructor + */ +fs.FSWatcher = function() {}; + +/** + */ +fs.FSWatcher.prototype.close = function() {}; + +/** + * @param {string} event + * @param {function(...)} callback + */ +fs.FSWatcher.prototype.on = function(event, callback) {}; diff --git a/javascript/node_modules/protobufjs/jsdoc.json b/javascript/node_modules/protobufjs/jsdoc.json new file mode 100644 index 0000000..79658ae --- /dev/null +++ b/javascript/node_modules/protobufjs/jsdoc.json @@ -0,0 +1,13 @@ +{ + "tags": { + "allowUnknownTags": true + }, + "source": { + "include": ["ProtoBuf.js"] + }, + "opts": { + "template": "templates/esoccer", + "destination": "docs" + }, + "plugins": ["plugins/markdown"] +} \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/.npmignore b/javascript/node_modules/protobufjs/node_modules/ascli/.npmignore new file mode 100644 index 0000000..db479e3 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/.npmignore @@ -0,0 +1,4 @@ +node_modules/ +npm-debug.log +ascli.png +example.png diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/LICENSE b/javascript/node_modules/protobufjs/node_modules/ascli/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/README.md b/javascript/node_modules/protobufjs/node_modules/ascli/README.md new file mode 100644 index 0000000..c883e38 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/README.md @@ -0,0 +1,61 @@ +![ascli](https://raw.github.com/dcodeIO/ascli/master/ascli.png) +===== +**Why?** Some of us are not only programmers but also part-time artist. So am I. This is good. However, to limit myself +a bit to a straight look of my CLI apps, I've created ascli based on the thought of not making things too fancy but +still looking good. So, basically, this package is meant to be used by me but if you like my interpretation of +unobtrusiveness and ease-of-use ... You are welcome! + +

      + example +

      + +Installation +------------ +`npm install ascli` + +Usage +----- +```js +var ascli = require("ascli").app("myApp"); +ascli.banner(ascli.appName.green.bold, "v1.0.0 by Foo Bar "); +console.log("Hello!"); +// If it worked: +ascli.ok("It worked!"); +// If it didn't: +ascli.fail("Nope, sorry.", /* exit code */ 1); +``` + +#### Using another alphabet +By default ascli uses a modified version of the **straight** ASCII alphabet. If you don't like it, you are free to +replace it: + +```js +ascli.use("/path/to/my/alphabet.json"); +// or +var myAlphabet = { ... }; +ascli.use(myAlphabet); +``` + +See the `alphabet/` directory for an example. + +#### Using colors +ascli automatically looks up and translates ANSI terminal colors applied to the title string. For that it depends on +[colour.js](https://github.com/dcodeIO/colour.js) which is also exposed as a property of the ascli namespace: +`ascli.colour` / `ascli.colors`. Also means: You don't need another ANSI terminal colors dependency. + +#### Indentation +ascli automatically indents all console output by one space just because it looks better with the banner. + +Parsing command line arguments +------------------------------ +[opt.js](https://github.com/dcodeIO/opt.js) will be pre-run on the `ascli` namespace and also exposed as `ascli.optjs()`. +```js +ascli.node // Node executable +ascli.script // Executed script +ascli.opt // Options as a hash +ascli.argv // Remaining non-option arguments +``` + +License +------- +Apache License, Version 2.0 diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/alphabet/straight.json b/javascript/node_modules/protobufjs/node_modules/ascli/alphabet/straight.json new file mode 100644 index 0000000..b290bc4 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/alphabet/straight.json @@ -0,0 +1,212 @@ +{ + "a": [ + " _ ", + "(_|", + " " + ], + "b": [ + "|_ ", + "|_)", + " " + ], + "c": [ + " _", + "( ", + " " + ], + "d": [ + " _|", + "(_|", + " " + ], + "e": [ + " _", + "(-", + " " + ], + "f": [ + "(_", + "| ", + " " + ], + "g": [ + " _ ", + "(_)", + "_/ " + ], + "h": [ + "|_ ", + "| )", + " " + ], + "i": [ + ".", + "|", + " " + ], + "j": [ + ".", + "|", + "'" + ], + "k": [ + "| ", + "|<", + " " + ], + "l": [ + "|", + "|", + " " + ], + "m": [ + " _ ", + "||)", + " " + ], + "n": [ + " _ ", + "| )", + " " + ], + "o": [ + " _ ", + "(_)", + " " + ], + "p": [ + " _ ", + "|_)", + "| " + ], + "q": [ + " _ ", + "(_|", + " |" + ], + "r": [ + " _", + "| ", + " " + ], + "s": [ + " _", + "_)", + " " + ], + "t": [ + "|_", + "|_", + " " + ], + "u": [ + " ", + "|_|", + " " + ], + "v": [ + " ", + "\\/", + " " + ], + "w": [ + " ", + "\\)/", + " " + ], + "x": [ + " ", + ")(", + " " + ], + "y": [ + " ", + "\\/", + "/ " + ], + "z": [ + "_ ", + "/_", + " " + ], + "0": [ + " _ ", + "/ \\", + "\\_/" + ], + "1": [ + " .", + "/|", + " |" + ], + "2": [ + " _ ", + " _)", + "(_ " + ], + "3": [ + "_ ", + "_)", + "_)" + ], + "4": [ + " ", + "|_|", + " |" + ], + "5": [ + " _ ", + "|_ ", + " _)" + ], + "6": [ + " ", + " / ", + "(_)" + ], + "7": [ + "__", + " /", + "/ " + ], + "8": [ + " _ ", + "(_)", + "(_)" + ], + "9": [ + " _ ", + "( )", + " /" + ], + ".": [ + " ", + ".", + " " + ], + ",": [ + " ", + ",", + " " + ], + "-": [ + "_", + " ", + " " + ], + "_": [ + " ", + "__", + " " + ], + "!": [ + "|", + ".", + " " + ], + " ": [ + " ", + " ", + " " + ] +} diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/ascli.js b/javascript/node_modules/protobufjs/node_modules/ascli/ascli.js new file mode 100644 index 0000000..410150e --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/ascli.js @@ -0,0 +1,150 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ascli (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ascli for details + */ +module.exports = (function() { + + var util = require("util"), + path = require("path"), + colour = require("colour"); + + // Enforce one blank before each line + function indent1() { + this.write(" "+util.format.apply(null, arguments).replace(/\n/g, "\n ")+"\n"); + } + console.log = indent1.bind(process.stdout); + console.info = indent1.bind(process.stdout); + console.warn = indent1.bind(process.stderr); + console.error = indent1.bind(process.stderr); + + // Default alphabet + var alphabet = require(path.join(__dirname, "alphabet", "straight.json")); + + /** + * Builds a banner. + * @param {string=} title App name + * @param {string=} appendix Appendix, e.g. version + * @returns {string} + */ + function ascli(title, appendix) { + title = title || ascli.appName; + appendix = appendix || ""; + var lines = ["", "", ""], c, a, j, ac = ""; + for (var i=0; i} alpha File name or alphabet to use + * @returns {Function} ascli + */ + ascli.use = function(alpha) { + if (typeof alpha === 'string') { + alphabet = require(alpha); + } else { + alphabet = alpha; + } + return ascli; + }; + + /** + * Sets the app name. + * @param {string} appName + * @returns {Function} ascli + */ + ascli.app = function(appName) { + ascli.appName = appName; + return ascli; + }; + + /** + * Terminates the application with OK. + * @param {string} msg Message text + * @param {number=} code Exit code, defaults to 0 + */ + ascli.ok = function(msg, code) { + process.stderr.write('\n '+ascli.appName.green.bold+' OK'.white.bold+(msg ? ' '+msg : '')+'\n'); + process.exit(typeof code != 'undefined' ? code : 0); + }; + + /** + * Terminates the application with an ERROR. + * @param {string} msg Message text + * @param {number=} code Exit code + */ + ascli.fail = function(msg, code) { + process.stderr.write('\n '+ascli.appName.red.bold+' ERROR'.white.bold+(msg ? ' '+msg : '')+'\n'); + process.exit(typeof code != 'undefined' ? code : 1); + }; + + /** + * opt.js + * @param {Array.=} argv + * @returns {{node: string, script: string, argv: Array., opt: Object.}} + */ + ascli.optjs = require("optjs"); + + // Pre-run it + var opt = ascli.optjs(); + ascli.node = opt.node; + ascli.script = opt.script; + ascli.argv = opt.argv; + ascli.opt = opt.opt; + + // Expose colour.js + ascli.colour = ascli.colors = colour; + + return ascli; + +})(); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/.npmignore b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/.npmignore new file mode 100644 index 0000000..590fb83 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/.npmignore @@ -0,0 +1,3 @@ +node_modules/ +npm-debug.log +.idea/ diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/LICENSE b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/LICENSE new file mode 100644 index 0000000..483044e --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 Marak Squires, Alexis Sellier (cloudhead) +Copyright (c) 2013 Daniel Wirtz + +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. diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/README.md b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/README.md new file mode 100644 index 0000000..6049776 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/README.md @@ -0,0 +1,101 @@ +![colour.js - ANSI terminal colors](https://raw.github.com/dcodeIO/colour.js/master/colour.png) +=========== +A cored, fixed, documented and optimized version of the popular [colors.js](https://github.com/Marak/colors.js). Can be +used as a drop-in replacement, also works correctly in the browser, provides a CSS mode and has been compiled through +Closure Compiler using advanced optimizations. Additionally, nearly every issue and pull request on the original has +been incorporated. + +Installation +------------ +`npm install colour` + +Usage +----- +This package extends the global String prototype with additional getters that apply terminal colors to your texts. +Available styles are: + +* **Emphasis:** bold, italic, underline, inverse +* **Colors:** yellow, cyan, white, magenta, green, red, grey, blue +* **Sequencers:** rainbow, zebra, random + +#### Example + +```js +var colour = require('colour'); +console.log('hello'.green); // outputs green text +console.log('i like cake and pies'.underline.red) // outputs red underlined text +console.log('inverse the color'.inverse); // inverses the color +console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces) +``` + +#### Or: As a drop-in replacement for `colors` +```js +var /* just name it */ colors = require('colour'); +... +``` + +Custom themes +------------- +Its also possible to define your own themes by creating new getters on the String object. Example: + +```js +var colour = require('colour'); +colour.setTheme({ + silly: 'rainbow', + input: 'grey', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: ['yellow', 'underline'], // Applies two styles at once + debug: 'blue', + error: 'red bold' // Again, two styles +}); + +console.log("this is an error".error); // outputs bold red text +console.log("this is a warning".warn); // outputs underlined yellow text + +console.log(colour.green("this is green")); // Alternatively +``` + +Console, browser and browser-css mode +------------------------------------- +```js +var colour = require('colour'); +... +colour.mode = 'none'; // No colors at all +colour.mode = 'console'; // Adds terminal colors (default on node.js) +colour.mode = 'browser'; // Adds HTML colors (default in browsers) +colour.mode = 'browser-css'; // Adds special CSS (see examples/example.css) +``` + +Uninstalling / reinstalling on the global scope +----------------------------------------------- +If you have a reason to use a fresh String prototype in your application, you may also revert all extensions made. + +```js +var colour = require('colour'); +... +colour.uninstall(); // Removes all custom properties from the String prototype +... +colour.install(); // Re-installs them +... +``` + +More features +------------- +* node.js/CommonJS compatible +* RequireJS/AMD compatible +* Browser/shim compatible +* Closure Compiler [externs included](https://github.com/dcodeIO/colour.js/blob/master/externs/colour.js) +* Zero dependencies + +Credits +------- +Based on work started by Marak (Marak Squires), cloudhead (Alexis Sellier), mmalecki (Maciej Małecki), nicoreed (Nico +Reed), morganrallen (Morgan Allen), JustinCampbell (Justin Campbell) and ded (Dustin Diaz). + +License +------- +The MIT-License (MIT) diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.js new file mode 100644 index 0000000..eabcdc5 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.js @@ -0,0 +1,335 @@ +/* + Copyright (c) 2010 Marak Squires, Alexis Sellier (cloudhead) + Copyright (c) 2013 Daniel Wirtz + + 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. + */ +/** + * @license colour.js (c) 2013 Daniel Wirtz + * Released under the MIT-License + * see: https://github.com/dcodeIO/colour.js for details + */ +(function (global) { // #22 + 'use strict'; + + /** + * colour namespace. + * @namespace + */ + var colour = {}; + + /** + * Colour mode. To generate html in node, use colour.setTheme("html") instead. + * @type {string} May be "console", "browser" or "none". + * @expose + */ + colour.mode = "console"; + + /** + * Whether running in a headless environment like node.js or not. + * @type {boolean} + * @expose + */ + colour.headless = typeof global['window'] === 'undefined'; + + /** + * All themes we know about. Contains only the "default" theme by default. + * @type {!Object.} + * @expose + */ + colour.themes = {}; + + /** + * Terminal colours. + * @type {!Object} Hello Closure + */ + var consoleStyles = { + 'bold': ['\x1B[1m', '\x1B[22m'], + 'italic': ['\x1B[3m', '\x1B[23m'], + 'underline': ['\x1B[4m', '\x1B[24m'], + 'inverse': ['\x1B[7m', '\x1B[27m'], + 'strikethrough': ['\x1B[9m', '\x1B[29m'], + 'white': ['\x1B[37m', '\x1B[39m'], + 'gray': ['\x1B[90m', '\x1B[39m'], + 'grey': ['\x1B[90m', '\x1B[39m'], + 'black': ['\x1B[30m', '\x1B[39m'], + 'blue': ['\x1B[34m', '\x1B[39m'], + 'cyan': ['\x1B[36m', '\x1B[39m'], + 'green': ['\x1B[32m', '\x1B[39m'], + 'magenta': ['\x1B[35m', '\x1B[39m'], + 'red': ['\x1B[31m', '\x1B[39m'], + 'yellow': ['\x1B[33m', '\x1B[39m'] + }; + + /** + * HTML. + * @type {!Object.>} + */ + var browserStyles = { + 'bold' : ['', ''], + 'italic' : ['', ''], + 'underline' : ['', ''], + 'inverse' : ['', ''], + 'strikethrough' : ['', ''], + 'white' : ['', ''], + 'gray' : ['', ''], // #46 + 'grey' : ['', ''], // Let the user decide + 'black' : ['', ''], + 'blue' : ['', ''], + 'cyan' : ['', ''], + 'green' : ['', ''], + 'magenta' : ['', ''], + 'red' : ['', ''], + 'yellow' : ['', ''] + }; + + /** + * CSS. + * @type {!Object.>} + */ + var cssStyles = { // #39 + 'bold' : ['', ''], + 'italic' : ['', ''], + 'underline' : ['', ''], + 'inverse' : ['', ''], + 'strikethrough' : ['', ''], + 'white' : ['', ''], + 'gray' : ['', ''], + 'grey' : ['', ''], + 'black' : ['', ''], + 'blue' : ['', ''], + 'cyan' : ['', ''], + 'green' : ['', ''], + 'magenta' : ['', ''], + 'red' : ['', ''], + 'yellow' : ['', ''] + }; + + /** + * Remember all getters that we defined. + * @type {!Object} + */ + var definedGetters = {}; + + /** + * Prototypes the string object to have additional properties that wraps the current string in colours when accessed. + * @param {string} col Colour / property name + * @param {function(string):string} func Wrapper function + * @private + */ + function addProperty(col, func) { + // Exposed on top of the namespace + colour[col] = function(str) { + return func.apply(str); + }; + // And on top of all strings + try { + String.prototype.__defineGetter__(col, func); + definedGetters[col] = func; + } catch (e) {} // #25 + } + + /** + * Whether colour are currently installed on the global scope. + * @type {boolean} + * @private + **/ + var installed = true; + + /** + * Uninstalls colour from the global scope. + * @returns {boolean} true if successfully uninstalled, false if already uninstalled + * @expose + */ + colour.uninstall = function() { // #41 + if (installed) { + Object.keys(definedGetters).forEach(function(color) { + try { + String.prototype.__defineGetter__(color, null); + } catch (e) { + delete String.prototype[color]; + } + }); + installed = false; + return true; + } + return false; + }; + + /** + * Reinstalls colour on the global scope. + * @returns {boolean} true if successfully reinstalled, false if already installed + * @expose + */ + colour.install = function() { + if (!installed) { + Object.keys(definedGetters).forEach(function(color) { + String.prototype.__defineGetter__(color, definedGetters[color]); + }); + installed = true; + return true; + } + return false; + }; + + /** + * Applies a style to a string. + * @param {string} str String to stylize + * @param {string} style Style to apply + * @returns {string} + * @private + */ + function stylize(str, style) { + if (colour.mode == 'console') { + return consoleStyles[style][0] + str + consoleStyles[style][1]; + } else if (colour.mode == 'browser') { + return browserStyles[style][0] + str + browserStyles[style][1]; + } else if (colour.mode == 'browser-css') { + return cssStyles[style][0] + str + browserStyles[style][1]; + } + return str+''; + } + + /** + * Rainbow colours. + * @type {!Array.} + * @const + * @private + */ + var rainbowColours = ['red', 'yellow', 'green', 'blue', 'magenta']; + + /** + * String properties that should never be overwritten. + * @type {!Array.} + * @const + */ + var prototypeBlacklist = [ + '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', + 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', + 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring', + 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight' + ]; + + /** + * Applies a theme. + * @param {!Object} theme Theme to apply + */ + function applyTheme(theme) { + Object.keys(theme).forEach(function(prop) { + if (prototypeBlacklist.indexOf(prop) >= 0) { + return; + } + if (typeof theme[prop] == 'string') { + // Multiple colours white-space seperated #45, e.g. "red bold", #18 + theme[prop] = theme[prop].split(' '); + } + addProperty(prop, function () { + var ret = this; + for (var t=0; t]*>/g, ''); + } + + addProperty('strip', strip); + addProperty('stripColors', strip); // Compatibility + + if (typeof module !== 'undefined' && module['exports']) { + module.exports = colour; + } else if (typeof define !== 'undefined' && define.amd) { + define("colour", function() { return colour; }); + define("colors", function() { return colour; }); + } else { + colour.mode = 'browser'; + global['colour'] = global['colors'] = colour; + } + +})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.min.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.min.js new file mode 100644 index 0000000..4173c95 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.min.js @@ -0,0 +1,14 @@ +/* + colour.js (c) 2013 Daniel Wirtz + Released under the MIT-License + see: https://github.com/dcodeIO/colour.js for details +*/ +(function(g){function d(a,b){c[a]=function(a){return b.apply(a)};try{String.prototype.__defineGetter__(a,b),e[a]=b}catch(d){}}function m(a,b){return"console"==c.mode?h[b][0]+a+h[b][1]:"browser"==c.mode?k[b][0]+a+k[b][1]:"browser-css"==c.mode?r[b][0]+a+k[b][1]:a+""}function l(a){Object.keys(a).forEach(function(b){0<=s.indexOf(b)||("string"==typeof a[b]&&(a[b]=a[b].split(" ")),d(b,function(){for(var d=this,e=0;e]*>/g,"")}var c={mode:"console"};c.headless="undefined"===typeof g.window;c.themes={};var h={bold:["\u001b[1m","\u001b[22m"],italic:["\u001b[3m","\u001b[23m"],underline:["\u001b[4m","\u001b[24m"],inverse:["\u001b[7m","\u001b[27m"],strikethrough:["\u001b[9m","\u001b[29m"],white:["\u001b[37m","\u001b[39m"],gray:["\u001b[90m","\u001b[39m"],grey:["\u001b[90m", +"\u001b[39m"],black:["\u001b[30m","\u001b[39m"],blue:["\u001b[34m","\u001b[39m"],cyan:["\u001b[36m","\u001b[39m"],green:["\u001b[32m","\u001b[39m"],magenta:["\u001b[35m","\u001b[39m"],red:["\u001b[31m","\u001b[39m"],yellow:["\u001b[33m","\u001b[39m"]},k={bold:["",""],italic:["",""],underline:["",""],inverse:['',""],strikethrough:["",""],white:['',""],gray:['', +""],grey:['',""],black:['',""],blue:['',""],cyan:['',""],green:['',""],magenta:['',""],red:['',""],yellow:['',""]},r={bold:['',""],italic:['', +""],underline:['',""],inverse:['',""],strikethrough:['',""],white:['',""],gray:['',""],grey:['',""],black:['',""],blue:['', +""],cyan:['',""],green:['',""],magenta:['',""],red:['',""],yellow:['',""]},e={},f=!0;c.uninstall=function(){return f?(Object.keys(e).forEach(function(a){try{String.prototype.__defineGetter__(a,null)}catch(b){delete String.prototype[a]}}),f= +!1,!0):!1};c.install=function(){return!f?(Object.keys(e).forEach(function(a){String.prototype.__defineGetter__(a,e[a])}),f=!0):!1};var q=["red","yellow","green","blue","magenta"],s="__defineGetter__ __defineSetter__ __lookupGetter__ __lookupSetter__ charAt constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf charCodeAt indexOf lastIndexof length localeCompare match replace search slice split substring toLocaleLowerCase toLocaleUpperCase toLowerCase toUpperCase trim trimLeft trimRight".split(" "); +c.setTheme=function(a){if("string"===typeof a){if("undefined"!=typeof c.themes[a])return l(c.themes[a]),c.themes[a];try{return c.themes[a]=require(a),l(c.themes[a]),c.themes[a]}catch(b){return b}}else l(a)};c.addSequencer=function(a,b){d(a,n(b))};Object.keys(h).forEach(function(a){d(a,function(){return m(this,a)})});c.addSequencer("rainbow",function(a,b){return" "===a?a:m(a,q[b++%q.length])});c.addSequencer("zebra",n(function(a,b){return 0===b%2?a:a.inverse}));d("strip",p);d("stripColors",p);"undefined"!== +typeof module&&module.exports?module.exports=c:"undefined"!==typeof define&&define.amd?(define("colour",function(){return c}),define("colors",function(){return c})):(c.mode="browser",g.colour=g.colors=c)})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.png b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/colour.png new file mode 100644 index 0000000000000000000000000000000000000000..0fb4a2ffc2cf68ca015e6833dd04c8807e6177f0 GIT binary patch literal 9415 zcmV;&BsklNP)S9$(-?^}|kD?1Oz zA(oO7AS5)RI3Yl=#S8GTMp;H^K19+z1lsyclSHr z`Okm8W4W#i#*7&=X6)%TZ%zdU9gPBqcW^p-JjKf?h4!Lpy7SI=~ zNhmleD7z^DD~(l5J3tIQfjduNffAhnN#Q9xa2gAg+#(7=1p1QEy-4MgmjWa(B5^x@*U^}GY z8Mvf%+Lp%e)cU+5acgZdM7WnUR2W}M|H&*a7 za4cRb%L+f3EJV`V)(71kKZNIB_6WYY5zcA92M-9$UG+fH#e3lERN_L3uUo7%4th-- z$r3J4-(oKU_BMoe50J#mVea66)5~G*u&pjuc6oEB88c?=)PQEIMF2a8bGbVe+~;jW+u_WefIVXiKo_jtiQ7KZ31&_l)??{9Ye#IZO2%GO zSi8>LEpc!U*h~Doow!b+99erfj#86AJ!2Qm{wkKKpa6SV10@y!c#1?x#$NOQot?9I z)w~yfKLsc7@)pm8dxBzHFA?hr5s))x%-ER%>O}!s6jqOwBN%xLVHk$7>3U#y<34^m zZaA)bppMG|0(y-;WaPU6W2b`9GEM~&EErn`(24Jzl+rW^G!G&eJ5?qK?ByV1_uW$1 zy5%u>V(b}61ukekTbE%O2cCi%ENRKyb;gVtTR%`=^n)0TvD*@J8iceXLoyWZPE&wd z0=s~?gdolWL%pRJWA{Tb6k}h;jWt)Yb%m*0At28RQWb^9!Y2`AyKtME76%Or#pp41 zzO3Ls=)fKXa(=X!#@N$Z2u8kYffr}&1necKm^;syF=Oik>a!Xy6R=yQXf__o-j(n+ z83DU%DIKQ->~R%Otsrq$-;0jbWn}D*48>HT9^5UZFf~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git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.css b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.css new file mode 100644 index 0000000..9815c62 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.css @@ -0,0 +1,25 @@ +/* reset */ +span.ansi-escape { + color: #000; + background: transparent; +} + +/* styles */ +span.ansi-escape.ansi-escape-bold { font-weight: bold; } +span.ansi-escape.ansi-escape-italic { font-style: italic; } +span.ansi-escape.ansi-escape-underline { text-decoration: underline; } +span.ansi-escape.ansi-escape-inverse { color: #FFF; background: #000; } +span.ansi-escape.ansi-escape-strikethrough { text-decoration: line-through; } + +/* greyscale */ +span.ansi-escape.ansi-escape-white { color: #FFF; } +span.ansi-escape.ansi-escape-grey { color: #7F7F7F; } +span.ansi-escape.ansi-escape-black { color: #000; } + +/* colors */ +span.ansi-escape.ansi-escape-blue { color: #00F; } +span.ansi-escape.ansi-escape-cyan { color: #0FF; } +span.ansi-escape.ansi-escape-green { color: #0F0; } +span.ansi-escape.ansi-escape-magenta { color: #F0F; } +span.ansi-escape.ansi-escape-red { color: #F00; } +span.ansi-escape.ansi-escape-yellow { color: #FF0; } diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.html b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.html new file mode 100644 index 0000000..72ac1e1 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.html @@ -0,0 +1,91 @@ + + + + + Colors Example + + + + + + + \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.js new file mode 100644 index 0000000..3f14812 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/examples/example.js @@ -0,0 +1,71 @@ +var colors = require('./../colour'); + +//colors.mode = "browser"; + +var test = colors.red("hopefully colorless output"); +console.log('Rainbows are fun!'.rainbow); +console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported +console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported +//console.log('zalgo time!'.zalgo); +console.log(test.stripColors); +console.log("a".grey + " b".black); + +console.log("Zebras are so fun!".zebra); + +// +// Remark: .strikethrough may not work with Mac OS Terminal App +// +console.log("This is " + "not".strikethrough + " fun."); +console.log(colors.rainbow('Rainbows are fun!')); +console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported +console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported +//console.log(colors.zalgo('zalgo time!')); +console.log(colors.stripColors(test)); +// console.log(colors.grey("a") + colors.black(" b")); + +colors.addSequencer("america", function(letter, i, exploded) { + if(letter === " ") return letter; + switch(i%3) { + case 0: return letter.red; + case 1: return letter.white; + case 2: return letter.blue; + } +}); + +colors.addSequencer("random", (function() { + var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta']; + + return function(letter, i, exploded) { + return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]]; + }; +})()); + +console.log("AMERICA! F--K YEAH!".america); +console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random); + +// +// Custom themes +// + +// Load theme with JSON literal +colors.setTheme({ + silly: 'rainbow', + input: 'grey', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: 'yellow', + debug: 'blue', + error: 'red' +}); + +// outputs red text +console.log("this is an error".error); + +// outputs yellow text +console.log("this is a warning".warn); + +// outputs grey text +console.log("this is an input".input); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/colour.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/colour.js new file mode 100644 index 0000000..15bddc4 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/colour.js @@ -0,0 +1,136 @@ +/* + * Copyright 2012 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Definitions for colour.js. + * @externs + * @author Daniel Wirtz + */ +var colour = function() {}; + +/** + * @type {string} + */ +colour.mode; + +/** + * @type {boolean} + */ +colour.headless; + +/** + * @param {string} str + * @returns {function(this:String)} + */ +colour.color = function(str) {}; + +/** + * @type {Object.>} + */ +colour.themes; + +/** + * @param {string} name + * @param {function(string):string} map + */ +colour.addSequencer = function(name, map) {}; + +/** + * @param {Object.} theme + * @returns {Object.|Error|undefined} + */ +colour.setTheme = function (theme) {}; + +/** + * @returns {boolean} + */ +colour.uninstall = function() {}; + +/** + * @returns {boolean} + */ +colour.install = function() {}; + +/** + * @name String.prototype.bold + * @type {string} + */ +// String.prototype.bold; + +/** + * @type {string} + */ +String.prototype.italic; + +/** + * @type {string} + */ +String.prototype.underline; + +/** + * @type {string} + */ +String.prototype.inverse; + +/** + * @type {string} + */ +String.prototype.strikethrough; + +/** + * @type {string} + */ +String.prototype.white; + +/** + * @type {string} + */ +String.prototype.grey; + +/** + * @type {string} + */ +String.prototype.black; + +/** + * @type {string} + */ +String.prototype.blue; + +/** + * @type {string} + */ +String.prototype.cyan; + +/** + * @type {string} + */ +String.prototype.green; + +/** + * @type {string} + */ +String.prototype.magenta; + +/** + * @type {string} + */ +String.prototype.red; + +/** + * @type {string} + */ +String.prototype.yellow; diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/minimal-env.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/minimal-env.js new file mode 100644 index 0000000..9bb20cc --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/externs/minimal-env.js @@ -0,0 +1,37 @@ +/** + * @fileoverview Minimal environment to compile colour.js. + * @externs + */ + +/** + * @param {string} moduleName + * @returns {!Object} + */ +var require = function(moduleName) {}; + +/** + * @type {Module} + */ +var module; + +/** + * @constructor + * @private + */ +var Module = function() {}; + +/** + * @type {*} + */ +Module.prototype.exports; + +/** + * @param {string} name + * @param {function()} contructor + */ +var define = function(name, contructor) {}; + +/** + * @type {boolean} + */ +define.amd; diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/package.json b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/package.json new file mode 100644 index 0000000..109d173 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/package.json @@ -0,0 +1,40 @@ +{ + "name": "colour", + "description": "A cored, fixed, documented and optimized version of the popular `colors.js`: Get colors in your node.js console like what...", + "version": "0.7.1", + "author": { + "name": "Daniel Wirtz", + "email": "dcode@dcode.io" + }, + "keywords": [ + "ansi", + "terminal", + "colors" + ], + "bugs": { + "url": "https://github.com/dcodeIO/colour.js/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/dcodeIO/colour.js.git" + }, + "engines": { + "node": ">=0.8" + }, + "dependencies": {}, + "devDependencies": {}, + "main": "./colour.min.js", + "scripts": { + "test": "node tests/test.js", + "compile": "ccjs colour.js --warning_level=VERBOSE --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs > colour.min.js" + }, + "license": "MIT", + "readme": "![colour.js - ANSI terminal colors](https://raw.github.com/dcodeIO/colour.js/master/colour.png)\r\n===========\r\nA cored, fixed, documented and optimized version of the popular [colors.js](https://github.com/Marak/colors.js). Can be\r\nused as a drop-in replacement, also works correctly in the browser, provides a CSS mode and has been compiled through\r\nClosure Compiler using advanced optimizations. Additionally, nearly every issue and pull request on the original has\r\nbeen incorporated.\r\n\r\nInstallation\r\n------------\r\n`npm install colour`\r\n\r\nUsage\r\n-----\r\nThis package extends the global String prototype with additional getters that apply terminal colors to your texts.\r\nAvailable styles are:\r\n\r\n* **Emphasis:** bold, italic, underline, inverse\r\n* **Colors:** yellow, cyan, white, magenta, green, red, grey, blue\r\n* **Sequencers:** rainbow, zebra, random\r\n\r\n#### Example\r\n\r\n```js\r\nvar colour = require('colour');\r\nconsole.log('hello'.green); // outputs green text\r\nconsole.log('i like cake and pies'.underline.red) // outputs red underlined text\r\nconsole.log('inverse the color'.inverse); // inverses the color\r\nconsole.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)\r\n```\r\n\r\n#### Or: As a drop-in replacement for `colors`\r\n```js\r\nvar /* just name it */ colors = require('colour');\r\n...\r\n```\r\n\r\nCustom themes\r\n-------------\r\nIts also possible to define your own themes by creating new getters on the String object. Example:\r\n\r\n```js\r\nvar colour = require('colour');\r\ncolour.setTheme({\r\n silly: 'rainbow',\r\n input: 'grey',\r\n verbose: 'cyan',\r\n prompt: 'grey',\r\n info: 'green',\r\n data: 'grey',\r\n help: 'cyan',\r\n warn: ['yellow', 'underline'], // Applies two styles at once\r\n debug: 'blue',\r\n error: 'red bold' // Again, two styles\r\n});\r\n\r\nconsole.log(\"this is an error\".error); // outputs bold red text\r\nconsole.log(\"this is a warning\".warn); // outputs underlined yellow text\r\n\r\nconsole.log(colour.green(\"this is green\")); // Alternatively\r\n```\r\n\r\nConsole, browser and browser-css mode\r\n-------------------------------------\r\n```js\r\nvar colour = require('colour');\r\n...\r\ncolour.mode = 'none'; // No colors at all\r\ncolour.mode = 'console'; // Adds terminal colors (default on node.js)\r\ncolour.mode = 'browser'; // Adds HTML colors (default in browsers)\r\ncolour.mode = 'browser-css'; // Adds special CSS (see examples/example.css)\r\n```\r\n\r\nUninstalling / reinstalling on the global scope\r\n-----------------------------------------------\r\nIf you have a reason to use a fresh String prototype in your application, you may also revert all extensions made.\r\n\r\n```js\r\nvar colour = require('colour');\r\n...\r\ncolour.uninstall(); // Removes all custom properties from the String prototype\r\n...\r\ncolour.install(); // Re-installs them\r\n...\r\n```\r\n\r\nMore features\r\n-------------\r\n* node.js/CommonJS compatible\r\n* RequireJS/AMD compatible\r\n* Browser/shim compatible\r\n* Closure Compiler [externs included](https://github.com/dcodeIO/colour.js/blob/master/externs/colour.js)\r\n* Zero dependencies\r\n\r\nCredits\r\n-------\r\nBased on work started by Marak (Marak Squires), cloudhead (Alexis Sellier), mmalecki (Maciej Małecki), nicoreed (Nico\r\nReed), morganrallen (Morgan Allen), JustinCampbell (Justin Campbell) and ded (Dustin Diaz).\r\n\r\nLicense\r\n-------\r\nThe MIT-License (MIT)\r\n", + "readmeFilename": "README.md", + "_id": "colour@0.7.1", + "dist": { + "shasum": "9363cadc824330ca888271688cc95ca0a942cc80" + }, + "_from": "colour@latest", + "_resolved": "https://registry.npmjs.org/colour/-/colour-0.7.1.tgz" +} diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/tests/test.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/tests/test.js new file mode 100644 index 0000000..a7c0935 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/colour/tests/test.js @@ -0,0 +1,80 @@ +var assert = require("assert"), + path = require("path"), + /* let's name it */ colors = require(path.join(__dirname, '..', 'colour.min.js')); + +var s = 'string'; + +function a(s, code) { + return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m'; +} + +function aE(s, color, code) { + assert.equal(s[color], a(s, code)); + assert.equal(colors[color](s), a(s, code)); + assert.equal(s[color], colors[color](s)); + assert.equal(s[color].stripColors, s); + assert.equal(s[color].stripColors, colors.stripColors(s)); +} + +function h(s, color) { + return '' + s + ''; + // that's pretty dumb approach to testing it +} + +var stylesColors = ['white', 'grey', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow']; +var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']); + +colors.mode = 'console'; +assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m'); +assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m'); +assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m'); +assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m'); +assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m'); +assert.ok(s.rainbow); +aE(s, 'white', 37); +aE(s, 'grey', 90); +aE(s, 'black', 30); +aE(s, 'blue', 34); +aE(s, 'cyan', 36); +aE(s, 'green', 32); +aE(s, 'magenta', 35); +aE(s, 'red', 31); +aE(s, 'yellow', 33); +assert.equal(s, 'string'); + +colors.setTheme({error:'red'}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); + +colors.mode = "browser"; +assert.equal(s.bold, '' + s + ''); +assert.equal(s.italic, '' + s + ''); +assert.equal(s.underline, '' + s + ''); +assert.equal(s.strikethrough, '' + s + ''); +assert.equal(s.inverse, '' + s + ''); +assert.ok(s.rainbow); +stylesColors.forEach(function (color) { + assert.equal(s[color], h(s, color)); + assert.equal(colors[color](s), h(s, color)); +}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); + +colors.mode = 'none'; +stylesAll.forEach(function (style) { + assert.equal(s[style], s); + assert.equal(colors[style](s), s); +}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); + +assert.ok(typeof "hello".red !== 'undefined'); +colors.uninstall(); +assert.ok(typeof "hello".red === 'undefined'); +colors.install(); +assert.ok(typeof "hello".red !== 'undefined'); + +console.log("OK"); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/README.md b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/README.md new file mode 100644 index 0000000..66159bf --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/README.md @@ -0,0 +1,44 @@ +![opt.js](https://raw.github.com/dcodeIO/opt.js/master/opt.png) +====== +Probably the sole command line option parser you'll ever need to `npm install optjs` Ctrl+C, Ctrl+V. Proof: + +```js +function opt(argv) { + var opt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(var i=2;i0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true); + return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt}; +} +``` + +Usage +----- +```js +var opt = require("optjs")(); +console.log(opt.node); // Path to node executable +console.log(opt.script); // Path to the current script +console.log(opt.opt); // Command line options as a hash +console.log(opt.argv); // Remaining non-option arguments +``` + +Example +------- +`node somescript.js foo -a=1 -b --c="hello world" bar ----d` + +```js +// Result +opt.node == "/path/to/node[.exe]" +opt.script == "/path/to/somescript.js" +opt.opt == { a: 1, b: true, c: "hello world", d: true } +opt.argv == ["foo", "bar"] +``` + +Full-featured test suite +------------------------ +```js +#!/usr/bin/env node +console.log(require("./opt.js")()); +``` + +License +------- +NASA Open Source Agreement v1.3 diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.js new file mode 100644 index 0000000..5ec682a --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.js @@ -0,0 +1,8 @@ +module.exports = (function() { + function opt(argv) { + var opt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(var i=2;i0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true); + return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt}; + } + return opt.opt = opt; +})(); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.png b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/opt.png new file mode 100644 index 0000000000000000000000000000000000000000..b25cc97a9c3ab8001c85d1ed172f50d9bd19d173 GIT binary patch literal 2912 zcmV-m3!n6fP)H+}JG`59T?e!al@Bsj@?*La90Dxs7Ber646c!%< z0Q(LQJ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u+B;p7@bw~G=`FbzE##{vl);|sy3rV87Z#2LRO)Pn#3NO!3ExWTGScmoXd{`C zUzas!F2?l40-ROQ_@@E+jqL+kkV76Tap?JMDpuS;?d+s*)km+y;Hf9K6OV;DR_-8mz4K+N;ukpd^vHYUoqwQ@AmRCsm%#MQ%wQ2o~LJm>k$L4>9_))PWdj>y4 z{2B2fwL1p#PPt$2V$lK1UCNBg*YQ)wJo7o5Qt1z=ok#2Fk!)I{`=uM3y^nWPAY3E0 zd+V1nEQ^^jujFd{Nlr&@1GMEd_0(0S>X`%77MZ=*n#Jey${%#h`MJ)pNL-)aZgs{` z;k(6A4x4Hx2zn?kklkh{CEM)4a4FwKe5>S{&ysjp?LM^U3N=5^;+cj!_AxczYgz;j zoB5(#^I^G1-mm(Eb^VtSUnBqXp4JM%*1y^Vc zhuVBog#}c@;sXF+rO+q-%@REhsQ$2;$LXDGGIOx_005{Oyp!l=>pk8te7%~7`npm install optjs` Ctrl+C, Ctrl+V. Proof:\r\n\r\n```js\r\nfunction opt(argv) {\r\n var opt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(var i=2;i0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true);\r\n return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt};\r\n}\r\n```\r\n\r\nUsage\r\n-----\r\n```js\r\nvar opt = require(\"optjs\")();\r\nconsole.log(opt.node); // Path to node executable\r\nconsole.log(opt.script); // Path to the current script\r\nconsole.log(opt.opt); // Command line options as a hash\r\nconsole.log(opt.argv); // Remaining non-option arguments\r\n```\r\n\r\nExample\r\n-------\r\n`node somescript.js foo -a=1 -b --c=\"hello world\" bar ----d`\r\n\r\n```js\r\n// Result\r\nopt.node == \"/path/to/node[.exe]\"\r\nopt.script == \"/path/to/somescript.js\"\r\nopt.opt == { a: 1, b: true, c: \"hello world\", d: true }\r\nopt.argv == [\"foo\", \"bar\"]\r\n```\r\n\r\nFull-featured test suite\r\n------------------------\r\n```js\r\n#!/usr/bin/env node\r\nconsole.log(require(\"./opt.js\")());\r\n```\r\n\r\nLicense\r\n-------\r\nNASA Open Source Agreement v1.3\r\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/dcodeIO/opt.js/issues" + }, + "_id": "optjs@3.2.1-boom", + "dist": { + "shasum": "72fd6b030a1d97e27378419b8ca8254442517be3" + }, + "_from": "optjs@latest", + "_resolved": "https://registry.npmjs.org/optjs/-/optjs-3.2.1-boom.tgz" +} diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/test.js b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/test.js new file mode 100644 index 0000000..ce5d298 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/node_modules/optjs/test.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +console.log(require("./opt.js")()); diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/package.json b/javascript/node_modules/protobufjs/node_modules/ascli/package.json new file mode 100644 index 0000000..987d52a --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/package.json @@ -0,0 +1,39 @@ +{ + "name": "ascli", + "description": "A uniform foundation for unobtrusive (ASCII art in) cli apps.", + "version": "0.3.0", + "author": { + "name": "Daniel Wirtz", + "email": "dcode@dcode.io" + }, + "repository": { + "type": "url", + "url": "https://github.com/dcodeIO/ascli.git" + }, + "bugs": { + "url": "https://github.com/dcodeIO/ascli/issues" + }, + "keywords": [ + "ansi", + "terminal", + "colors", + "ascii" + ], + "main": "./ascli.js", + "dependencies": { + "colour": "latest", + "optjs": "latest" + }, + "scripts": { + "test": "node tests/test.js" + }, + "license": "Apache-2.0", + "readme": "![ascli](https://raw.github.com/dcodeIO/ascli/master/ascli.png)\r\n=====\r\n**Why?** Some of us are not only programmers but also part-time artist. So am I. This is good. However, to limit myself\r\na bit to a straight look of my CLI apps, I've created ascli based on the thought of not making things too fancy but\r\nstill looking good. So, basically, this package is meant to be used by me but if you like my interpretation of\r\nunobtrusiveness and ease-of-use ... You are welcome!\r\n\r\n

      \r\n \"example\"\r\n

      \r\n\r\nInstallation\r\n------------\r\n`npm install ascli`\r\n\r\nUsage\r\n-----\r\n```js\r\nvar ascli = require(\"ascli\").app(\"myApp\");\r\nascli.banner(ascli.appName.green.bold, \"v1.0.0 by Foo Bar \");\r\nconsole.log(\"Hello!\");\r\n// If it worked:\r\nascli.ok(\"It worked!\");\r\n// If it didn't:\r\nascli.fail(\"Nope, sorry.\", /* exit code */ 1);\r\n```\r\n\r\n#### Using another alphabet\r\nBy default ascli uses a modified version of the **straight** ASCII alphabet. If you don't like it, you are free to\r\nreplace it:\r\n\r\n```js\r\nascli.use(\"/path/to/my/alphabet.json\");\r\n// or\r\nvar myAlphabet = { ... };\r\nascli.use(myAlphabet);\r\n```\r\n\r\nSee the `alphabet/` directory for an example.\r\n\r\n#### Using colors\r\nascli automatically looks up and translates ANSI terminal colors applied to the title string. For that it depends on\r\n[colour.js](https://github.com/dcodeIO/colour.js) which is also exposed as a property of the ascli namespace:\r\n`ascli.colour` / `ascli.colors`. Also means: You don't need another ANSI terminal colors dependency.\r\n\r\n#### Indentation\r\nascli automatically indents all console output by one space just because it looks better with the banner.\r\n\r\nParsing command line arguments\r\n------------------------------\r\n[opt.js](https://github.com/dcodeIO/opt.js) will be pre-run on the `ascli` namespace and also exposed as `ascli.optjs()`.\r\n```js\r\nascli.node // Node executable\r\nascli.script // Executed script\r\nascli.opt // Options as a hash\r\nascli.argv // Remaining non-option arguments\r\n```\r\n\r\nLicense\r\n-------\r\nApache License, Version 2.0\r\n", + "readmeFilename": "README.md", + "_id": "ascli@0.3.0", + "dist": { + "shasum": "7496300dfba46e964e2c6856ce9d10a42c45b268" + }, + "_from": "ascli@latest", + "_resolved": "https://registry.npmjs.org/ascli/-/ascli-0.3.0.tgz" +} diff --git a/javascript/node_modules/protobufjs/node_modules/ascli/tests/test.js b/javascript/node_modules/protobufjs/node_modules/ascli/tests/test.js new file mode 100644 index 0000000..4baee82 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/ascli/tests/test.js @@ -0,0 +1,9 @@ +var ascli = require("../ascli.js").app("myapp"); + +ascli.banner("staying straight".green.bold, "v1.0.0 through ascli"); +console.log("Hello world!".white.bold); +console.log("...of ascli\n"); +console.log("Command line arguments".white.bold); +console.log(ascli.opt, ascli.argv); +ascli.banner("abcdefghijklmnopqrstuvwxyz 0123456789"); +ascli.ok("yep, that worked."); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/.npmignore b/javascript/node_modules/protobufjs/node_modules/bytebuffer/.npmignore new file mode 100644 index 0000000..81023b6 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/.npmignore @@ -0,0 +1,3 @@ +node_modules/ +npm-debug.log +ByteBuffer.png diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/.travis.yml b/javascript/node_modules/protobufjs/node_modules/bytebuffer/.travis.yml new file mode 100644 index 0000000..a118245 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 + - 0.10 diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.js new file mode 100644 index 0000000..23f0bbc --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.js @@ -0,0 +1,2320 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + * @expose + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + * @expose + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + * @expose + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + * @expose + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + * @expose + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + * @expose + */ + ByteBuffer.VERSION = "2.3.1"; + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + * @expose + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + * @expose + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + * @expose + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @expose + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + * @expose + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + * @expose + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + * @expose + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + * @expose + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + * @expose + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + * @expose + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + * @expose + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + * @expose + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + * @expose + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @expose + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + * @expose + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + * @expose + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + * @expose + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + * @expose + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + * @expose + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + * @expose + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + * @expose + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + * @expose + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + * @expose + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + * @expose + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + * @expose + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + * @expose + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + * @expose + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + * @expose + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + * @expose + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + * @expose + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + * @expose + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + * @expose + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + * @expose + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js new file mode 100644 index 0000000..4bc46b7 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.js @@ -0,0 +1,55 @@ +/* + ByteBuffer.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/ByteBuffer.js for details +*/ +(function(n){function q(l){function c(a,b,d){a="undefined"!==typeof a?parseInt(a,10):c.DEFAULT_CAPACITY;1>a&&(a=c.DEFAULT_CAPACITY);this.array=d?null:new ArrayBuffer(a);this.view=d?null:new DataView(this.array);this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof b?!!b:!1}var p=null;if("function"===typeof require)try{var n=require("buffer"),p=n&&"function"===typeof n.Buffer&&"function"===typeof n.Buffer.isBuffer?n.Buffer:null}catch(q){}c.VERSION="2.3.1";c.DEFAULT_CAPACITY= +16;c.LITTLE_ENDIAN=!0;c.BIG_ENDIAN=!1;c.Long=l||null;c.isByteBuffer=function(a){return a&&(a instanceof c||"object"===typeof a&&(null===a.array||a.array instanceof ArrayBuffer)&&(null===a.view||a.view instanceof DataView)&&"number"===typeof a.offset&&"number"===typeof a.markedOffset&&"number"===typeof a.length&&"boolean"===typeof a.littleEndian)};c.allocate=function(a,b){return new c(a,b)};c.wrap=function(a,b,d){"boolean"===typeof b&&(d=b,b="utf8");if("string"===typeof a)switch(b){case "base64":return c.decode64(a, +d);case "hex":return c.decodeHex(a,d);case "binary":return c.decodeBinary(a,d);default:return(new c(c.DEFAULT_CAPACITY,d)).writeUTF8String(a).flip()}if(p&&p.isBuffer(a)){b=(new Uint8Array(a)).buffer;if(b===a){b=new ArrayBuffer(a.length);for(var e=new Uint8Array(b),f=0,g=a.length;fa)return!1;null===this.array&&(this.array=new ArrayBuffer(a),this.view=new DataView(this.array));if(this.array.byteLengtha||a>this.array.byteLength||1>b||b>this.array.byteLength)throw Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+a+"-"+b+")");d=this.clone();d.offset= +a;d.length=b;return d};c.prototype.ensureCapacity=function(a){return null===this.array?this.resize(a):this.array.byteLength=a?2*this.array.byteLength:a):this};c.prototype.flip=function(){this.length=null==this.array?0:this.offset;this.offset=0;return this};c.prototype.mark=function(a){if(null==this.array)throw Error(this+" cannot be marked: Already destroyed");a="undefined"!==typeof a?parseInt(a,10):this.offset;if(0>a||a>this.array.byteLength)throw Error(this+ +" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+a);this.markedOffset=a;return this};c.prototype.reset=function(){if(null===this.array)throw Error(this+" cannot be reset: Already destroyed");0<=this.markedOffset?(this.offset=this.markedOffset,this.markedOffset=-1):this.length=this.offset=0;return this};c.prototype.clone=function(){var a=new c(-1,this.littleEndian,!0);a.array=this.array;a.view=this.view;a.offset=this.offset;a.markedOffset= +this.markedOffset;a.length=this.length;return a};c.prototype.copy=function(){if(null==this.array)return this.clone();var a=new c(this.array.byteLength,this.littleEndian),b=new Uint8Array(this.array);(new Uint8Array(a.array)).set(b);a.offset=this.offset;a.markedOffset=this.markedOffset;a.length=this.length;return a};c.prototype.remaining=function(){return null===this.array?0:this.length-this.offset};c.prototype.capacity=function(){return null!=this.array?this.array.byteLength:0};c.prototype.compact= +function(){if(null==this.array)throw Error(this+" cannot be compacted: Already destroyed");this.offset>this.length&&this.flip();if(this.offset===this.length)return this.array=new ArrayBuffer(0),this.view=null,this;if(0===this.offset&&this.length===this.array.byteLength)return this;var a=new Uint8Array(this.array),b=new ArrayBuffer(this.length-this.offset);(new Uint8Array(b)).set(a.subarray(this.offset,this.length));this.array=b;this.markedOffset=this.markedOffset>=this.offset?this.markedOffset-this.offset: +-1;this.offset=0;this.length=this.array.byteLength;return this};c.prototype.destroy=function(){null!==this.array&&(this.view=this.array=null,this.offset=0,this.markedOffset=-1,this.length=0);return this};c.prototype.reverse=function(){if(null===this.array)throw Error(this+" cannot be reversed: Already destroyed");Array.prototype.reverse.call(new Uint8Array(this.array));var a=this.offset;this.offset=this.array.byteLength-this.length;this.markedOffset=-1;this.length=this.array.byteLength-a;this.view= +new DataView(this.array);return this};c.prototype.append=function(a,b){a instanceof c||(a=c.wrap(a));if(null===a.array)throw Error(a+" cannot be appended to "+this+": Already destroyed");var d=a.length-a.offset;if(0==d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);b="undefined"!==typeof b?b:(this.offset+=d)-d;this.ensureCapacity(b+d);d=new Uint8Array(a.array);(new Uint8Array(this.array)).set(d.subarray(a.offset,a.length),b);return this};c.prototype.prepend=function(a,b){a instanceof c|| +(a=c.wrap(a));if(null===a.array)throw a+" cannot be prepended to "+this+": Already destroyed";var d=a.length-a.offset;if(0==d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);var e="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=d-b;0=this.array.byteLength)throw Error("Cannot read int8 from "+this+" at "+a+": Capacity overflow");return this.view.getInt8(a)};c.prototype.writeByte=c.prototype.writeInt8;c.prototype.readByte=c.prototype.readInt8;c.prototype.writeUint8=function(a,b){b="undefined"!==typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setUint8(b,a);return this}; +c.prototype.readUint8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a+1>this.array.byteLength)throw Error("Cannot read uint8 from "+this+" at "+a+": Capacity overflow");return this.view.getUint8(a)};c.prototype.writeInt16=function(a,b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setInt16(b,a,this.littleEndian);return this};c.prototype.readInt16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+ +this+" at "+a+": Capacity overflow");return this.view.getInt16(a,this.littleEndian)};c.prototype.writeShort=c.prototype.writeInt16;c.prototype.readShort=c.prototype.readInt16;c.prototype.writeUint16=function(a,b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setUint16(b,a,this.littleEndian);return this};c.prototype.readUint16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+this+" at "+a+ +": Capacity overflow");return this.view.getUint16(a,this.littleEndian)};c.prototype.writeInt32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setInt32(b,a,this.littleEndian);return this};c.prototype.readInt32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read int32 from "+this+" at "+a+": Capacity overflow");return this.view.getInt32(a,this.littleEndian)};c.prototype.writeInt=c.prototype.writeInt32; +c.prototype.readInt=c.prototype.readInt32;c.prototype.writeUint32=function(a,b){b="undefined"!=typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setUint32(b,a,this.littleEndian);return this};c.prototype.readUint32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read uint32 from "+this+" at "+a+": Capacity overflow");return this.view.getUint32(a,this.littleEndian)};c.prototype.writeFloat32=function(a,b){b="undefined"!==typeof b? +b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setFloat32(b,a,this.littleEndian);return this};c.prototype.readFloat32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(null===this.array||a+4>this.array.byteLength)throw Error("Cannot read float32 from "+this+" at "+a+": Capacity overflow");return this.view.getFloat32(a,this.littleEndian)};c.prototype.writeFloat=c.prototype.writeFloat32;c.prototype.readFloat=c.prototype.readFloat32;c.prototype.writeFloat64=function(a,b){b="undefined"!== +typeof b?b:(this.offset+=8)-8;this.ensureCapacity(b+8);this.view.setFloat64(b,a,this.littleEndian);return this};c.prototype.readFloat64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw Error("Cannot read float64 from "+this+" at "+a+": Capacity overflow");return this.view.getFloat64(a,this.littleEndian)};c.prototype.writeDouble=c.prototype.writeFloat64;c.prototype.readDouble=c.prototype.readFloat64;l&&(c.prototype.writeInt64=function(a, +b){b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));this.ensureCapacity(b+8);this.littleEndian?(this.view.setInt32(b,a.getLowBits(),!0),this.view.setInt32(b+4,a.getHighBits(),!0)):(this.view.setInt32(b,a.getHighBits(),!1),this.view.setInt32(b+4,a.getLowBits(),!1));return this},c.prototype.readInt64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+ +this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getInt32(a,!0),this.view.getInt32(a+4,!0),!1):l.fromBits(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!1)},c.prototype.writeUint64=function(a,b){b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!0));this.ensureCapacity(b+8);this.littleEndian?(this.view.setUint32(b,a.getLowBitsUnsigned(),!0),this.view.setUint32(b+4,a.getHighBitsUnsigned(),!0)):(this.view.setUint32(b, +a.getHighBitsUnsigned(),!1),this.view.setUint32(b+4,a.getLowBitsUnsigned(),!1));return this},c.prototype.readUint64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null===this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getUint32(a,!0),this.view.getUint32(a+4,!0),!0):l.fromBits(this.view.getUint32(a+4,!1),this.view.getUint32(a,!1),!0)},c.prototype.writeLong=c.prototype.writeInt64, +c.prototype.readLong=c.prototype.readInt64);c.MAX_VARINT32_BYTES=5;c.prototype.writeVarint32=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;a>>>=0;this.ensureCapacity(b+c.calculateVarint32(a));var e=this.view,f=0;e.setUint8(b,a|128);128<=a?(e.setUint8(b+1,a>>7|128),16384<=a?(e.setUint8(b+2,a>>14|128),2097152<=a?(e.setUint8(b+3,a>>21|128),268435456<=a?(e.setUint8(b+4,a>>28&127),f=5):(e.setUint8(b+3,e.getUint8(b+3)&127),f=4)):(e.setUint8(b+2,e.getUint8(b+2)&127),f= +3)):(e.setUint8(b+1,e.getUint8(b+1)&127),f=2)):(e.setUint8(b,e.getUint8(b)&127),f=1);return d?(this.offset+=f,this):f};c.prototype.readVarint32=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d=0,e,f=this.view,g=0;do e=f.getUint8(a+d),d>>0),++d;while(e&128);g|=0;return b?(this.offset+=d,g):{value:g,length:d}};c.prototype.writeZigZagVarint32=function(a,b){return this.writeVarint32(c.zigZagEncode32(a),b)};c.prototype.readZigZagVarint32= +function(a){a=this.readVarint32(a);return"object"===typeof a?(a.value=c.zigZagDecode32(a.value),a):c.zigZagDecode32(a)};c.MAX_VARINT64_BYTES=10;l&&(c.prototype.writeVarint64=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var e=a.toInt()>>>0,f=a.shiftRightUnsigned(28).toInt()>>>0,g=a.shiftRightUnsigned(56).toInt()>>>0,k=c.calculateVarint64(a);this.ensureCapacity(b+k);var h=this.view;switch(k){case 10:h.setUint8(b+ +9,g>>>7|128);case 9:h.setUint8(b+8,g|128);case 8:h.setUint8(b+7,f>>>21|128);case 7:h.setUint8(b+6,f>>>14|128);case 6:h.setUint8(b+5,f>>>7|128);case 5:h.setUint8(b+4,f|128);case 4:h.setUint8(b+3,e>>>21|128);case 3:h.setUint8(b+2,e>>>14|128);case 2:h.setUint8(b+1,e>>>7|128);case 1:h.setUint8(b+0,e|128)}h.setUint8(b+k-1,h.getUint8(b+k-1)&127);return d?(this.offset+=k,this):k},c.prototype.readVarint64=function(a){var b="undefined"===typeof a,d=a="undefined"!==typeof a?a:this.offset,c=this.view,f,g=0, +k=0,h;h=c.getUint8(a++);f=h&127;if(h&128&&(h=c.getUint8(a++),f|=(h&127)<<7,h&128&&(h=c.getUint8(a++),f|=(h&127)<<14,h&128&&(h=c.getUint8(a++),f|=(h&127)<<21,h&128&&(h=c.getUint8(a++),g=h&127,h&128&&(h=c.getUint8(a++),g|=(h&127)<<7,h&128&&(h=c.getUint8(a++),g|=(h&127)<<14,h&128&&(h=c.getUint8(a++),g|=(h&127)<<21,h&128&&(h=c.getUint8(a++),k=h&127,h&128&&(h=c.getUint8(a++),k|=(h&127)<<7,h&128))))))))))throw Error("Data must be corrupt: Buffer overrun");c=l.from28Bits(f,g,k,!1);return b?(this.offset= +a,c):{value:c,length:a-d}},c.prototype.writeZigZagVarint64=function(a,b){return this.writeVarint64(c.zigZagEncode64(a),b)},c.prototype.readZigZagVarint64=function(a){a=this.readVarint64(a);return"object"!==typeof a||a instanceof l?c.zigZagDecode64(a):(a.value=c.zigZagDecode64(a.value),a)});c.prototype.writeVarint=c.prototype.writeVarint32;c.prototype.readVarint=c.prototype.readVarint32;c.prototype.writeZigZagVarint=c.prototype.writeZigZagVarint32;c.prototype.readZigZagVarint=c.prototype.readZigZagVarint32; +c.calculateVarint32=function(a){a>>>=0;return 128>a?1:16384>a?2:2097152>a?3:268435456>a?4:5};l&&(c.calculateVarint64=function(a){"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var b=a.toInt()>>>0,d=a.shiftRightUnsigned(28).toInt()>>>0;a=a.shiftRightUnsigned(56).toInt()>>>0;return 0==a?0==d?16384>b?128>b?1:2:2097152>b?3:4:16384>d?128>d?5:6:2097152>d?7:8:128>a?9:10});c.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0};c.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};l&&(c.zigZagEncode64= +function(a){"object"===typeof a&&a instanceof l?a.unsigned&&(a=a.toSigned()):a=l.fromNumber(a,!1);return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()},c.zigZagDecode64=function(a){"object"===typeof a&&a instanceof l?a.unsigned||(a=a.toUnsigned()):a=l.fromNumber(a,!0);return a.shiftRightUnsigned(1).xor(a.and(l.ONE).toSigned().negate()).toSigned()});c.decodeUTF8Char=function(a,b){var d=a.readUint8(b),c,f,g,k,h,l=b;if(0==(d&128))b+=1;else if(192==(d&224))c=a.readUint8(b+1),d=(d&31)<<6|c&63,b+=2; +else if(224==(d&240))c=a.readUint8(b+1),f=a.readUint8(b+2),d=(d&15)<<12|(c&63)<<6|f&63,b+=3;else if(240==(d&248))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),d=(d&7)<<18|(c&63)<<12|(f&63)<<6|g&63,b+=4;else if(248==(d&252))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),d=(d&3)<<24|(c&63)<<18|(f&63)<<12|(g&63)<<6|k&63,b+=5;else if(252==(d&254))c=a.readUint8(b+1),f=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),h=a.readUint8(b+5),d=(d&1)<<30|(c&63)<<24| +(f&63)<<18|(g&63)<<12|(k&63)<<6|h&63,b+=6;else throw Error("Cannot decode UTF8 character at offset "+b+": charCode (0x"+d.toString(16)+") is invalid");return{"char":d,length:b-l}};c.encodeUTF8Char=function(a,b,c){var e=c;if(0>a)throw Error("Cannot encode UTF8 character: charCode ("+a+") is negative");if(128>a)b.writeUint8(a&127,c),c+=1;else if(2048>a)b.writeUint8(a>>6&31|192,c).writeUint8(a&63|128,c+1),c+=2;else if(65536>a)b.writeUint8(a>>12&15|224,c).writeUint8(a>>6&63|128,c+1).writeUint8(a&63|128, +c+2),c+=3;else if(2097152>a)b.writeUint8(a>>18&7|240,c).writeUint8(a>>12&63|128,c+1).writeUint8(a>>6&63|128,c+2).writeUint8(a&63|128,c+3),c+=4;else if(67108864>a)b.writeUint8(a>>24&3|248,c).writeUint8(a>>18&63|128,c+1).writeUint8(a>>12&63|128,c+2).writeUint8(a>>6&63|128,c+3).writeUint8(a&63|128,c+4),c+=5;else if(2147483648>a)b.writeUint8(a>>30&1|252,c).writeUint8(a>>24&63|128,c+1).writeUint8(a>>18&63|128,c+2).writeUint8(a>>12&63|128,c+3).writeUint8(a>>6&63|128,c+4).writeUint8(a&63|128,c+5),c+=6;else throw Error("Cannot encode UTF8 character: charCode (0x"+ +a.toString(16)+") is too large (>= 0x80000000)");return c-e};c.calculateUTF8Char=function(a){if(0>a)throw Error("Cannot calculate length of UTF8 character: charCode ("+a+") is negative");if(128>a)return 1;if(2048>a)return 2;if(65536>a)return 3;if(2097152>a)return 4;if(67108864>a)return 5;if(2147483648>a)return 6;throw Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");};c.a=function(a){a=""+a;for(var b=0,d=0,e=a.length;dg?a.readUint8(g++):0,e=a.length>g?a.readUint8(g++):0,f=b<<16|d<<8|e,b=f>>18&63,d=f>>12&63,e=f>>6&63,f&=63,h[k++]=m.charAt(b)+m.charAt(d)+m.charAt(e)+m.charAt(f);while(gd||0>e||0>g||0>k)throw Error("Illegal argument: Not a valid base64 encoded string");f=d<<18|e<<12|g<<6|k;d=f>>16&255;e=f>>8&255;f&=255;64==g?l.writeUint8(d):64==k?l.writeUint8(d).writeUint8(e):l.writeUint8(d).writeUint8(e).writeUint8(f)}while(h< +a.length);return l.flip()};c.encodeHex=function(a){a instanceof c?a.lengthb.length&&(b="0"+b),d.push(b);return d.join("")};c.decodeHex=function(a,b){if("string"!==typeof a)throw Error("Illegal argument: Not a string");if(0!==a.length%2)throw Error("Illegal argument: Not a hex encoded string");for(var d=new c(a.length/2,b),e=0,f=a.length;e< +f;e+=2)d.writeUint8(parseInt(a.substring(e,e+2),16));return d.flip()};c.encodeBinary=function(a){a instanceof c?a.lengtha?"+":"")+b-a)+" bytes");return d?(this.offset=b,f):{string:f,length:b-g}};c.prototype.writeLString=function(a,b){a= +""+a;var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var e=c.encodeUTF8Char(a.length,this,b),e=e+this.writeUTF8String(a,b+e);return d?(this.offset+=e,this):e};c.prototype.readLString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d=c.decodeUTF8Char(this,a);a=this.readUTF8String(d["char"],a+d.length);return b?(this.offset+=d.length+a.length,a.string):{string:a.string,length:d.length+a.length}};c.prototype.writeVString=function(a,b){a=""+a;var d= +"undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var e=this.writeVarint32(c.a(a),b),e=e+this.writeUTF8String(a,b+e);return d?(this.offset+=e,this):e};c.prototype.readVString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var c=this.readVarint32(a);a=this.readUTF8StringBytes(c.value,a+c.length);return b?(this.offset+=c.length+a.length,a.string):{string:a.string,length:c.length+a.length}};c.prototype.writeCString=function(a,b){var c="undefined"===typeof b; +b="undefined"!==typeof b?b:this.offset;var e=this.writeUTF8String(""+a,b);this.writeUint8(0,b+e);return c?(this.offset+=e+1,this):e+1};c.prototype.readCString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d,e="",f=a;do d=c.decodeUTF8Char(this,a),a+=d.length,0!=d["char"]&&(e+=String.fromCharCode(d["char"]));while(0!=d["char"]);return b?(this.offset=a,e):{string:e,length:a-f}};c.prototype.writeJSON=function(a,b,c){c="function"===typeof c?c:JSON.stringify;return this.writeLString(c(a), +b)};c.prototype.readJSON=function(a,b){b="function"===typeof b?b:JSON.parse;var c=this.readLString(a);return"string"===typeof c?b(c):{data:b(c.string),length:c.length}};c.prototype.toColumns=function(a){if(null===this.array)return"DESTROYED";a="undefined"!==typeof a?parseInt(a,10):16;1>a&&(a=16);for(var b="",c=[],e,f=this.view,b=0==this.offset&&0==this.length?b+"|":0==this.length?b+">":0==this.offset?b+"<":b+" ",g=0,k=this.array.byteLength;ge.length&&(e="0"+e);b+=e;b=g+1==this.offset&&g+1==this.length?b+"|":g+1==this.offset?b+"<":g+1==this.length?b+">":b+" "}" "!=b&&c.push(b);g=0;for(k=c.length;ge?String.fromCharCode(e):".";""!=b&&(c[h]+=" "+b);return c.join("\n")};c.prototype.printDebug=function(a){"function"!==typeof a&&(a= +console.log.bind(console));a((null!=this.array?"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n"+this.toColumns()+"\n")};c.prototype.toHex=function(a){var b="",d=this.view,e,f;if(a){if(null===this.array)return"DESTROYED";b=0==this.offset&&0==this.length?b+"|":0==this.length?b+">":0==this.offset?b+"<":b+" ";e=0;for(f=this.array.byteLength;e< +f;++e)a=d.getUint8(e).toString(16).toUpperCase(),2>a.length&&(a="0"+a),b+=a,b=e+1===this.offset&&e+1===this.length?b+"|":e+1==this.offset?b+"<":e+1==this.length?b+">":b+" ";return b}return c.encodeHex(this)};c.prototype.toBinary=function(){return c.encodeBinary(this)};c.prototype.toBase64=function(){return null===this.array||this.offset>=this.length?"":c.encode64(this)};c.prototype.toUTF8=function(){return null===this.array||this.offset>=this.length?"":this.readUTF8StringBytes(this.length-this.offset, +this.offset).string};c.prototype.toString=function(a){switch(a||""){case "utf8":return this.toUTF8();case "base64":return this.toBase64();case "hex":return this.toHex();case "binary":return this.toBinary();case "debug":return this.toHex(!0);default:return null===this.array?"ByteBuffer(DESTROYED)":"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"}};c.prototype.toArrayBuffer=function(a){if(null===this.array)return null; +var b=this.clone();b.offset>b.length&&b.flip();var c=!1;if(0b)var c=a,a=b,b=c;return new p((new Uint8Array(this.array)).subarray(a,b))});return c}"undefined"!==typeof module&&module.exports?module.exports=q(require("long")):"undefined"!==typeof define&&define.amd?define("ByteBuffer",["Math/Long"],function(l){return q(l)}): +(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ByteBuffer=q(n.dcodeIO.Long))})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.map b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.map new file mode 100644 index 0000000..80f5d4a --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.min.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"", +"lineCount":55, +"mappings":"A;;;;;AAqBC,SAAQ,CAACA,CAAD,CAAS,CAYdC,QAASA,EAAc,CAACC,CAAD,CAAO,CAuBTC,QAAQ,EAAA,CAACC,CAAD,CAAWC,CAAX,CAAyBC,CAAzB,CAAiC,CACtDF,CAAA,CAA+B,WAApB,GAAA,MAAOA,EAAP,CAAkCG,QAAA,CAASH,CAAT,CAAmB,EAAnB,CAAlC,CAA2DD,CAAAK,iBACvD,EAAf,CAAIJ,CAAJ,GAAkBA,CAAlB,CAA6BD,CAAAK,iBAA7B,CAOA,KAAAC,MAAA,CAAaH,CAAA,CAAS,IAAT,CAAgB,IAAII,WAAJ,CAAgBN,CAAhB,CAO7B,KAAAO,KAAA,CAAYL,CAAA,CAAS,IAAT,CAAgB,IAAIM,QAAJ,CAAa,IAAAH,MAAb,CAS5B,KAAAI,OAAA,CAAc,CAOd,KAAAC,aAAA,CAAqB,EASrB,KAAAC,OAAA,CAAc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IA,MAAA,QADJ,CACwB5U,CAAA,CAAegB,OAAA,CAAQ,MAAR,CAAf,CADxB,CAE6B,WAAtB,GAAI,MAAO6T,OAAX,EAAqCA,MAAA,IAArC,CACHA,MAAA,CAAO,YAAP,CAAqB,CAAC,WAAD,CAArB,CAAoC,QAAQ,CAAC5U,CAAD,CAAO,CAAE,MAAOD,EAAA,CAAeC,CAAf,CAAT,CAAnD,CADG;CAGEF,CAAA,QACL,GADwBA,CAAA,QACxB,CAD4C,EAC5C,EAAAA,CAAA,QAAA,WAAA,CAAkCC,CAAA,CAAeD,CAAA,QAAA,KAAf,CAJ/B,CAnvEO,CAAjB,CAAA,CA0vEE,IA1vEF;", +"sources":["ByteBuffer.js"], +"names":["global","loadByteBuffer","Long","ByteBuffer","capacity","littleEndian","sparse","parseInt","DEFAULT_CAPACITY","array","ArrayBuffer","view","DataView","offset","markedOffset","length","Buffer","require","nodeBuffer","e","VERSION","LITTLE_ENDIAN","BIG_ENDIAN","isByteBuffer","ByteBuffer.isByteBuffer","bb","allocate","ByteBuffer.allocate","wrap","ByteBuffer.wrap","buffer","enc","decode64","decodeHex","decodeBinary","writeUTF8String","flip","isBuffer","b","Uint8Array","ab","i","k","Error","prototype","clone","call","constructor","name","byteLength","LE","ByteBuffer.prototype.LE","BE","ByteBuffer.prototype.BE","bigEndian","resize","ByteBuffer.prototype.resize","srcView","dst","set","dstView","slice","ByteBuffer.prototype.slice","begin","end","t","ensureCapacity","ByteBuffer.prototype.ensureCapacity","ByteBuffer.prototype.flip","mark","ByteBuffer.prototype.mark","reset","ByteBuffer.prototype.reset","ByteBuffer.prototype.clone","copy","ByteBuffer.prototype.copy","src","remaining","ByteBuffer.prototype.remaining","ByteBuffer.prototype.capacity","compact","ByteBuffer.prototype.compact","subarray","destroy","ByteBuffer.prototype.destroy","reverse","ByteBuffer.prototype.reverse","Array","o","append","ByteBuffer.prototype.append","n","prepend","ByteBuffer.prototype.prepend","modify","diff","writeInt8","ByteBuffer.prototype.writeInt8","value","setInt8","readInt8","ByteBuffer.prototype.readInt8","getInt8","writeByte","readByte","writeUint8","ByteBuffer.prototype.writeUint8","setUint8","readUint8","ByteBuffer.prototype.readUint8","getUint8","writeInt16","ByteBuffer.prototype.writeInt16","setInt16","readInt16","ByteBuffer.prototype.readInt16","getInt16","writeShort","readShort","writeUint16","ByteBuffer.prototype.writeUint16","setUint16","readUint16","ByteBuffer.prototype.readUint16","getUint16","writeInt32","ByteBuffer.prototype.writeInt32","setInt32","readInt32","ByteBuffer.prototype.readInt32","getInt32","writeInt","readInt","writeUint32","ByteBuffer.prototype.writeUint32","setUint32","readUint32","ByteBuffer.prototype.readUint32","getUint32","writeFloat32","ByteBuffer.prototype.writeFloat32","setFloat32","readFloat32","ByteBuffer.prototype.readFloat32","getFloat32","writeFloat","readFloat","writeFloat64","ByteBuffer.prototype.writeFloat64","setFloat64","readFloat64","ByteBuffer.prototype.readFloat64","getFloat64","writeDouble","readDouble","writeInt64","ByteBuffer.prototype.writeInt64","fromNumber","getLowBits","getHighBits","readInt64","ByteBuffer.prototype.readInt64","fromBits","writeUint64","ByteBuffer.prototype.writeUint64","getLowBitsUnsigned","getHighBitsUnsigned","readUint64","ByteBuffer.prototype.readUint64","writeLong","readLong","MAX_VARINT32_BYTES","writeVarint32","ByteBuffer.prototype.writeVarint32","advance","calculateVarint32","size","readVarint32","ByteBuffer.prototype.readVarint32","count","writeZigZagVarint32","ByteBuffer.prototype.writeZigZagVarint32","zigZagEncode32","readZigZagVarint32","ByteBuffer.prototype.readZigZagVarint32","dec","zigZagDecode32","MAX_VARINT64_BYTES","writeVarint64","ByteBuffer.prototype.writeVarint64","part0","toInt","part1","shiftRightUnsigned","part2","calculateVarint64","readVarint64","ByteBuffer.prototype.readVarint64","start","from28Bits","writeZigZagVarint64","ByteBuffer.prototype.writeZigZagVarint64","zigZagEncode64","readZigZagVarint64","ByteBuffer.prototype.readZigZagVarint64","zigZagDecode64","writeVarint","readVarint","writeZigZagVarint","readZigZagVarint","ByteBuffer.calculateVarint32","TWO_PWR_7_DBL","TWO_PWR_14_DBL","TWO_PWR_21_DBL","TWO_PWR_28_DBL","ByteBuffer.calculateVarint64","ByteBuffer.zigZagEncode32","ByteBuffer.zigZagDecode32","ByteBuffer.zigZagEncode64","unsigned","toSigned","shiftLeft","xor","shiftRight","toUnsigned","ByteBuffer.zigZagDecode64","and","ONE","negate","decodeUTF8Char","ByteBuffer.decodeUTF8Char","a","c","d","f","charCode","toString","encodeUTF8Char","ByteBuffer.encodeUTF8Char","calculateUTF8Char","ByteBuffer.calculateUTF8Char","calculateUTF8String","ByteBuffer.calculateUTF8String","str","bytes","charCodeAt","B64","encode64","ByteBuffer.encode64","o1","o2","o3","h4","oi","out","bits","h1","h2","h3","charAt","join","r","ByteBuffer.decode64","Math","ceil","indexOf","encodeHex","ByteBuffer.encodeHex","val","toUpperCase","push","ByteBuffer.decodeHex","substring","encodeBinary","ByteBuffer.encodeBinary","String","fromCharCode","ByteBuffer.decodeBinary","ByteBuffer.prototype.writeUTF8String","encLen","j","readUTF8String","ByteBuffer.prototype.readUTF8String","chars","result","readUTF8StringBytes","ByteBuffer.prototype.readUTF8StringBytes","writeLString","ByteBuffer.prototype.writeLString","readLString","ByteBuffer.prototype.readLString","lenDec","writeVString","ByteBuffer.prototype.writeVString","readVString","ByteBuffer.prototype.readVString","writeCString","ByteBuffer.prototype.writeCString","readCString","ByteBuffer.prototype.readCString","writeJSON","ByteBuffer.prototype.writeJSON","data","stringify","JSON","readJSON","ByteBuffer.prototype.readJSON","parse","toColumns","ByteBuffer.prototype.toColumns","lines","printDebug","ByteBuffer.prototype.printDebug","console","log","bind","toHex","ByteBuffer.prototype.toHex","debug","toBinary","ByteBuffer.prototype.toBinary","toBase64","ByteBuffer.prototype.toBase64","toUTF8","ByteBuffer.prototype.toUTF8","ByteBuffer.prototype.toString","toArrayBuffer","ByteBuffer.prototype.toArrayBuffer","forceCopy","copied","toBuffer","ByteBuffer.prototype.toBuffer","temp","module","define"] +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.noexpose.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.noexpose.js new file mode 100644 index 0000000..202cbca --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.noexpose.js @@ -0,0 +1,2207 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + */ + ByteBuffer.VERSION = "2.3.1"; + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/LICENSE b/javascript/node_modules/protobufjs/node_modules/bytebuffer/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/NOTICE b/javascript/node_modules/protobufjs/node_modules/bytebuffer/NOTICE new file mode 100644 index 0000000..3eac38f --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) ByteBuffer.js by Daniel 'dcode' Wirtz. +See: https://github.com/dcodeIO/ByteBuffer.js for details diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/README.md b/javascript/node_modules/protobufjs/node_modules/bytebuffer/README.md new file mode 100644 index 0000000..3b0b611 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/README.md @@ -0,0 +1,121 @@ +![ByteBuffer.js - A full-featured ByteBuffer implementation in JavaScript](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png) +====================================== +Provides a full-featured ByteBuffer implementation using typed arrays. It's one of the core components driving +[ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js) and the [PSON](https://github.com/dcodeIO/PSON) reference +implementation. + +*Note:* The API behind #toHex and #toString has changed with ByteBuffer 2, which is a generally revised release, in +favor of making this more intuitive. + +What can it do? +--------------- +* Mimics Java ByteBuffers as close as reasonable while using typed array terms +* Signed and unsigned integers (8, 16, 32, 64 bit through [Long.js](https://github.com/dcodeIO/Long.js)) with endianness support +* 32 and 64 bit floats +* Varints as known from protobuf including zig-zag encoding +* Includes an UTF8 and Base64 en-/decoder +* C-strings, V(arint-prefixed)-strings and UTF8 L(ength-prefixed)-strings +* Rich string toolset (to hex, base64, binary, utf8, debug, columns) +* Relative and absolute zero-copy operations +* Manual and automatic resizing (efficiently doubles capacity) +* Chaining of all operations that do not return a specific value +* Slicing, appending, prepending, reversing, flip, mark, reset, etc. + +And much more... + +Features +-------- +* [CommonJS](http://www.commonjs.org/) compatible +* [RequireJS](http://requirejs.org/)/AMD compatible +* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/bytebuffer) +* Browser compatible +* [Closure Compiler](https://developers.google.com/closure/compiler/) ADVANCED_OPTIMIZATIONS compatible (fully annotated, + `ByteBuffer.min.js` has been compiled this way, `ByteBuffer.min.map` is the source map) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* Well tested through [nodeunit](https://github.com/caolan/nodeunit) +* Zero production dependencies (Long.js is optional) +* Small footprint + +Usage +----- +### Node.js / CommonJS ### +* Install: `npm install bytebuffer` + +```javascript +var ByteBuffer = require("bytebuffer"); +var bb = new ByteBuffer(); +bb.writeLString("Hello world!").flip(); +console.log(bb.readLString()+" from ByteBuffer.js"); +``` + +### Browser ### + +Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long +support, you can skip the Long.js include. + +```html + + +``` + +```javascript +var ByteBuffer = dcodeIO.ByteBuffer; +var bb = new ByteBuffer(); +bb.writeLString("Hello world!").flip(); +alert(bb.readLString()+" from ByteBuffer.js"); +``` + +### Require.js / AMD ### + +Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long +support, you can skip the Long.js config. [Require.js](http://requirejs.org/) example: + +```javascript +require.config({ + "paths": { + "Long": "/path/to/Long.js" + "ByteBuffer": "/path/to/ByteBuffer.js" + } +}); +require(["ByteBuffer"], function(ByteBuffer) { + var bb = new ByteBuffer(); + bb.writeLString("Hello world!"); + bb.flip(); + alert(bb.readLString()+" from ByteBuffer.js"); +}); +``` + +On long (int64) support +----------------------- +As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value +of 2^53. Beyond that, behaviour might be unexpected. However, real long support requires the full 64 bits +with the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support +in ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two +32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth. +On node, long support is available by default through the [long](https://npmjs.org/package/long) dependency. + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/ByteBuffer.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/ByteBuffer.js/tarball/master) + +Documentation +------------- +* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/ByteBuffer.js/master/docs/ByteBuffer.html) + +Tests (& Examples) [![Build Status](https://travis-ci.org/dcodeIO/ByteBuffer.js.png?branch=master)](https://travis-ci.org/dcodeIO/ByteBuffer.js) +------------------ +* [View source](https://github.com/dcodeIO/ByteBuffer.js/blob/master/tests/suite.js) +* [View report](https://travis-ci.org/dcodeIO/ByteBuffer.js) + +Support for IE<10, FF<15, Chrome<9 etc. +--------------------------------------- +* Requires working ArrayBuffer & DataView implementations (i.e. use a [polyfill](https://github.com/inexorabletash/polyfill#typed-arrays-polyfill)) + +Contributors +------------ +[Dretch](https://github.com/Dretch) (IE8 compatibility) + +License +------- +Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/bower.json b/javascript/node_modules/protobufjs/node_modules/bytebuffer/bower.json new file mode 100644 index 0000000..7439693 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/bower.json @@ -0,0 +1,12 @@ +{ + "name": "bytebuffer", + "version": "2.3.1", + "author": "Daniel Wirtz ", + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"], + "dependencies": { + "long": "latest" + }, + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/build.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/build.js new file mode 100644 index 0000000..39013d4 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/build.js @@ -0,0 +1,35 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ByteBuffer.js Build Script (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ + +var Preprocessor = require("preprocessor"), + fs = require("fs"), + pkg = require(__dirname+"/package.json"); + +var pp = new Preprocessor(fs.readFileSync(__dirname+"/src/ByteBuffer.js"), __dirname+"/src"); +fs.writeFileSync(__dirname+"/ByteBuffer.js", pp.process({ + "VERSION": pkg.version +})); + +pp = new Preprocessor(fs.readFileSync(__dirname+"/src/bower.json"), __dirname+"/src"); +fs.writeFileSync(__dirname+"/bower.json", pp.process({ + "VERSION": pkg.version +})); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.Long.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.Long.html new file mode 100644 index 0000000..85c2e5e --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.Long.html @@ -0,0 +1,4269 @@ + + + + + Class: Long + + + + + + + + + + +
      + +

      Class: Long

      + + + + + +
      + +
      +

      + ByteBuffer. + + Long +

      + +
      + +
      +
      + + + + +
      +

      new Long(low, high)

      + + +
      +
      + + +
      +

      Constructs a 64-bit two's-complement integer, given its low and high 32-bit +values as signed integers. See the from* functions below for more +convenient ways of constructing Longs.

      + +

      The internal representation of a long is the two given signed, 32-bit values. +We use 32-bit pieces because these are the size of integers on which +Javascript performs bit-operations. For operations like addition and +multiplication, we split each number into 16-bit pieces, which can easily be +multiplied within Javascript's floating-point representation without overflow +or change in sign.

      + +

      In the algorithms below, we frequently reduce the negative case to the +positive case by negating the input(s) and then post-processing the result. +Note that we must ALWAYS check specially whether those values are MINVALUE +(-2^63) because -MINVALUE == MIN_VALUE (since 2^63 cannot be represented as +a positive number, it overflows back into a negative). Not handling this +case would often result in infinite recursion.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      low + + +number + + + +

      The low (signed) 32 bits of the long.

      high + + +number + + + +

      The high (signed) 32 bits of the long.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + +
      + + +
      + + + + + + + + + + + + +

      Members

      + +
      + +
      +

      <static> MAX_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MIN_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> NEG_ONE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> ONE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> ZERO :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + +
      + + + +

      Methods

      + +
      + +
      +

      <static> fromBits(lowBits, highBits) → {Long}

      + + +
      +
      + + +
      +

      Returns a Long representing the 64-bit integer that comes by concatenating +the given high and low bits. Each is assumed to use 32 bits.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      lowBits + + +number + + + +

      The low 32-bits.

      highBits + + +number + + + +

      The high 32-bits.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The corresponding Long value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromInt(value) → {Long}

      + + +
      +
      + + +
      +

      Returns a Long representing the given (32-bit) integer value.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number + + + +

      The 32-bit integer in question.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The corresponding Long value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromNumber(value) → {Long}

      + + +
      +
      + + +
      +

      Returns a Long representing the given value, provided that it is a finite +number. Otherwise, zero is returned.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number + + + +

      The number in question.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The corresponding Long value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromString(str, opt_radix) → {Long}

      + + +
      +
      + + +
      +

      Returns a Long representation of the given string, written using the given +radix.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      The textual representation of the Long.

      opt_radix + + +number + + + + + + <optional>
      + + + +

      The radix in which the text is written.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The corresponding Long value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      add(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the sum of this and the given Long.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to add to this one.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The sum of this and the given Long.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      and(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the bitwise-AND of this Long and the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      The Long with which to AND.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The bitwise-AND of this and the other.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      compare(other) → {number}

      + + +
      +
      + + +
      +

      Compares this Long with the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      0 if they are the same, 1 if the this is greater, and -1 + if the given one is greater.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      div(other) → {Long}

      + + +
      +
      + + +
      +

      Returns this Long divided by the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long by which to divide.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      This Long divided by the given one.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      equals(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long equals the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      getHighBits() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The high 32-bits as a signed value.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getLowBits() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The low 32-bits as a signed value.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getLowBitsUnsigned() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The low 32-bits as an unsigned value.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getNumBitsAbs() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Returns the number of bits needed to represent the absolute + value of this Long.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      greaterThan(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long is greater than the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      greaterThanOrEqual(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long is greater than or equal to the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isNegative() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this value is negative.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isOdd() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this value is odd.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isZero() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this value is zero.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      lessThan(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long is less than the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      lessThanOrEqual(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long is less than or equal to the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      modulo(other) → {Long}

      + + +
      +
      + + +
      +

      Returns this Long modulo the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long by which to mod.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      This Long modulo the given one.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      multiply(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the product of this and the given long.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to multiply with this.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The product of this and the other.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      negate() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The negation of this value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      not() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The bitwise-NOT of this value.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      notEquals(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to compare against.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Whether this Long does not equal the other.

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      or(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the bitwise-OR of this Long and the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      The Long with which to OR.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The bitwise-OR of this and the other.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftLeft(numBits) → {Long}

      + + +
      +
      + + +
      +

      Returns this Long with bits shifted to the left by the given amount.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + +

      The number of bits by which to shift.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      This shifted to the left by the given amount.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftRight(numBits) → {Long}

      + + +
      +
      + + +
      +

      Returns this Long with bits shifted to the right by the given amount.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + +

      The number of bits by which to shift.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      This shifted to the right by the given amount.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftRightUnsigned(numBits) → {Long}

      + + +
      +
      + + +
      +

      Returns this Long with bits shifted to the right by the given amount, with +the new top bits matching the current sign bit.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + +

      The number of bits by which to shift.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      This shifted to the right by the given amount, with + zeros placed into the new leading bits.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      subtract(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the difference of this and the given Long.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      Long to subtract from this.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The difference of this and the given Long.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      toInt() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The value, assuming it is a 32-bit integer.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      toNumber() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The closest floating-point representation to this value.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      toString(opt_radix) → {string}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      opt_radix + + +number + + + + + + <optional>
      + + + +

      The radix in which the text should be written.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The textual representation of this value.

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      xor(other) → {Long}

      + + +
      +
      + + +
      +

      Returns the bitwise-XOR of this Long and the given one.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + +

      The Long with which to XOR.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The bitwise-XOR of this and the other.

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + +
      + + + + + +
      + +
      + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.html new file mode 100644 index 0000000..2bc98f2 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/ByteBuffer.html @@ -0,0 +1,15285 @@ + + + + + Class: ByteBuffer + + + + + + + + + + +
      + +

      Class: ByteBuffer

      + + + + + +
      + +
      +

      + ByteBuffer +

      + +

      A full-featured ByteBuffer implementation in JavaScript using typed arrays.

      + +
      + +
      +
      + + + + +
      +

      new ByteBuffer(capacity, littleEndian)

      + + +
      +
      + + +
      +

      Constructs a new ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      capacity + + +number + + + + + + <optional>
      + + + +

      Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian multi byte values, defaults to false for big + endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + +
      + + +
      + + + + + + + + + + + + +

      Members

      + +
      + +
      +

      <static, constant> BIG_ENDIAN :boolean

      + + +
      +
      + +
      +

      Big endian constant for usage in constructors instead of a boolean value. Evaluates to false.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> DEFAULT_CAPACITY :number

      + + +
      +
      + +
      +

      Default buffer capacity of 16. The ByteBuffer will be automatically resized by a factor of 2 if required.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> LITTLE_ENDIAN :boolean

      + + +
      +
      + +
      +

      Little endian constant for usage in constructors instead of a boolean value. Evaluates to true.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> Long :Long|undefined

      + + +
      +
      + +
      +

      Long class for int64 support. May be undefined if the Long class has not been loaded and int64 support is + not available.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> MAX_VARINT32_BYTES :number

      + + +
      +
      + +
      +

      Maximum number of bytes used by 32bit base 128 variable-length integer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> MAX_VARINT64_BYTES :number

      + + +
      +
      + +
      +

      Maximum number of bytes used by a 64bit base 128 variable-length integer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> VERSION :string

      + + +
      +
      + +
      +

      Version string.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      array :ArrayBuffer

      + + +
      +
      + +
      +

      Backing ArrayBuffer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      length :number

      + + +
      +
      + +
      +

      Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + offset and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      littleEndian :boolean

      + + +
      +
      + +
      +

      Whether to use little endian multi byte values, defaults to false for big endian.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      markedOffset :number

      + + +
      +
      + +
      +

      Marked offset set through ByteBuffer#mark. Defaults to -1 (no marked offset).

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      offset :number

      + + +
      +
      + +
      +

      Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      view :DataView

      + + +
      +
      + +
      +

      DataView to mess with the ArrayBuffer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + +
      + + + +

      Methods

      + +
      + +
      +

      <static> allocate(capacity, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Allocates a new ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      capacity + + +number + + + + + + <optional>
      + + + +

      Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian multi byte values, defaults to false for big + endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateUTF8Char(charCode) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode the specified char code.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      charCode + + +number + + + +

      Character to encode as char code

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be calculated (too large) +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Number of bytes required to encode the specified char code

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateUTF8String(str) → {number}

      + + +
      +
      + + +
      +

      Calculates the number of bytes required to store an UTF8 encoded string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      str + + +string + + + +

      String to calculate

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateVarint32(value) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number + + + +

      Value to encode

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required. Capped to ByteBuffer.MAX_VARINT32_BYTES

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateVarint64(value) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number +| + +!Long + + + +

      Value to encode

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required. Capped to ByteBuffer.MAX_VARINT64_BYTES

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> decode64(str, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Decodes a base64 encoded string to a ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      Base64 encoded string

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian byte order, defaults to false for big endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid base64 encoded string +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      ByteBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> decodeHex(str, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Decodes a hex encoded string to a ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      Hex encoded string

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian byte order, defaults to false for big endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid hex encoded string +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      ByteBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> decodeUTF8Char(src, offset) → {{char: number, length: number}}

      + + +
      +
      + + +
      +

      Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      src + + +ByteBuffer + + + +
      offset + + +number + + + +

      Offset to read from

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be decoded or there is a capacity overflow +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Decoded char code and the actual number of bytes read

      +
      + + + +
      +
      + Type +
      +
      + +{char: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      <static> encode64(bb) → {string}

      + + +
      +
      + + +
      +

      Encodes a ByteBuffer's contents to a base64 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      bb + + +ByteBuffer + + + +

      ByteBuffer

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is invalid +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Base64 encoded string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      <static> encodeUTF8Char(charCode, dst, offset) → {number}

      + + +
      +
      + + +
      +

      Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      charCode + + +number + + + +

      Character to encode as char code

      dst + + +ByteBuffer + + + +

      ByteBuffer to encode to

      offset + + +number + + + +

      Offset to write to

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be encoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> wrap(buffer, enc, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + ByteBuffer's offset to 0 and its length to the wrapped object's byte length.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      buffer + + +ArrayBuffer +| + +!Buffer +| + +!{array: !ArrayBuffer} +| + +!{buffer: !ArrayBuffer} +| + +string + + + + + + + +

      Anything that can + be wrapped

      enc + + +string +| + +boolean + + + + + + <optional>
      + + + +

      String encoding if a string is provided (hex, utf8, defaults to base64)

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian multi byte values, defaults to false for big + endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified object cannot be wrapped +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagDecode32(n) → {number}

      + + +
      +
      + + +
      +

      Decodes a zigzag encoded signed 32bit integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number + + + +

      Unsigned zigzag encoded 32bit integer

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Signed 32bit integer

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagDecode64(n) → {Long}

      + + +
      +
      + + +
      +

      Decodes a zigzag encoded signed 64bit integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +Long +| + +number + + + +

      Unsigned zigzag encoded long or JavaScript number

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If long support is not available +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Signed long

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagEncode32(n) → {number}

      + + +
      +
      + + +
      +

      Encodes a signed 32bit integer so that it can be effectively used with varint encoding.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number + + + +

      Signed 32bit integer

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Unsigned zigzag encoded 32bit integer

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagEncode64(n) → {Long}

      + + +
      +
      + + +
      +

      Encodes a signed 64bit integer so that it can be effectively used with varint encoding.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number +| + +!Long + + + +

      Signed long

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Unsigned zigzag encoded long

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      append(src, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      src + + +* + + + + + + + +

      ByteBuffer or any object that can be wrapped to append

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to append at. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      BE(bigEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Switches big endian byte order.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      bigEndian + + +boolean + + + + + + <optional>
      + + + +

      Defaults to true, otherwise uses little endian

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      capacity() → {number}

      + + +
      +
      + + +
      +

      Gets the capacity of the backing buffer. This is independent from ByteBuffer#length and returns the + size of the entire backing array.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Capacity of the backing array or 0 if destroyed

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      clone() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + offsets.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Clone

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      compact() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set offset=0 and + length=capacity.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer cannot be compacted +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      copy() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Copy

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      destroy() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + is usually not required but may be useful in limited memory environments. Most successive operations will + rise an error until ByteBuffer#resize or ByteBuffer#ensureCapacity is called to reinitialize + the backing array.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      ensureCapacity(capacity) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + If double the previous capacity is less than the required capacity, the required capacity will be used.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      capacity + + +number + + + +

      Required capacity

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      flip() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Makes the buffer ready for a new sequence of write or relative read operations. Sets length=offset and + offset=0. Always make sure to flip a buffer when all relative writing operations are complete.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      LE(littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Switches little endian byte order.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      Defaults to true, otherwise uses big endian

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      mark(offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Marks an offset to be used with ByteBuffer#reset.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to mark. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + +
      See:
      +
      + +
      + + + +
      + + + + + +
      Throws:
      + + +
      + If the mark cannot be set +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      prepend(src, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      src + + +* + + + + + + + +

      ByteBuffer or any object that can be wrapped to prepend

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to prepend at. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      printDebug(out)

      + + +
      +
      + + +
      +

      Prints debug information about this ByteBuffer's contents.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      out + + +function(string) + + + + + + <optional>
      + + + +

      Output function to call, defaults to console.log

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + +
      + + + +
      +

      readByte(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a byte. This is an alias of ByteBuffer#readInt8.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readCString(offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string followed by a NULL character (Uint8).

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readDouble(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a double. This is an alias of ByteBuffer#readFloat64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a float. This is an alias of ByteBuffer#readFloat32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat64(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 64bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an integer. This is an alias of ByteBuffer#readInt32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt8(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an 8bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt16(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 16bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt64(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a 64bit integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readJSON(offset, parse) → {*|!{data: *, length: number}}

      + + +
      +
      + + +
      +

      Reads a JSON payload and unserializes it.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      parse + + +function(string) + + + + + + <optional>
      + + + +

      Parse implementation to use. Defaults to JSON.parse.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the data cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Data payload if offset is omitted, else the data payload and the + actual number of bytes read

      +
      + + + +
      +
      + Type +
      +
      + +* +| + +!{data: *, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readLong(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a long. This is an alias of ByteBuffer#readInt64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readLString(offset) → {string|{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string with a prepended number of characters, which is also encoded as an UTF8 character.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readShort(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a short value. This is an alias of ByteBuffer#readInt16.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint8(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an 8bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint16(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 16bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint64(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a 64bit unsigned integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readUTF8String(chars, offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads an UTF8 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      chars + + +number + + + + + + + +

      Number of characters to read

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readUTF8StringBytes(length, offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads an UTF8 string with the specified byte length.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      length + + +number + + + + + + + +

      Byte length

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the length did not match or the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint(offset) → {number|{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint32(offset) → {number|!{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +!{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint64(offset) → {Long|!{value: Long, length: number}}

      + + +
      +
      + + +
      +

      Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and + the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +Long +| + +!{value: Long, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVString(offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded or if it is not preceeded by a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint(offset) → {number|{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readZigZagVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint32(offset) → {number|{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint64(offset) → {Long|{value: Long, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +Long +| + +{value: Long, length: number} + + +
      +
      + + + + +
      + + + +
      +

      remaining() → {number}

      + + +
      +
      + + +
      +

      Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + returns length-offset.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Remaining readable bytes. May be negative if offset>length.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      reset() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Resets the ByteBuffer. If an offset has been marked through ByteBuffer#mark before, the offset will + be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + no marked offset, sets offset=0 and length=0.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + +
      See:
      +
      + +
      + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      resize(capacity) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      capacity + + +number + + + +

      New capacity

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      reverse() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00".

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      slice(begin, end) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + ArrayBuffer (use ByteBuffer#compact or ByteBuffer.wrap instead).

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      begin + + +number + + + + + + <optional>
      + + + +

      Begin offset, defaults to ByteBuffer#offset.

      end + + +number + + + + + + <optional>
      + + + +

      End offset, defaults to ByteBuffer#length.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer cannot be sliced +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      toArrayBuffer(forceCopy) → {ArrayBuffer}

      + + +
      +
      + + +
      +

      Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will return a reference to + the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      forceCopy + + +boolean + + + + + + <optional>
      + + + +

      true forces the creation of a copy, defaults to false

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Compacted ArrayBuffer or null if already destroyed

      +
      + + + +
      +
      + Type +
      +
      + +ArrayBuffer + + +
      +
      + + + + +
      + + + +
      +

      toBase64() → {string}

      + + +
      +
      + + +
      +

      Returns the base64 encoded representation of the ByteBuffer's contents.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Base 64 encoded string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toBuffer() → {Buffer}

      + + +
      +
      + + +
      +

      Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will also copy all data (not + a reference).

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Compacted node Buffer or null if already destroyed

      +
      + + + +
      +
      + Type +
      +
      + +Buffer + + +
      +
      + + + + +
      + + + +
      +

      toColumns(wrap) → {string}

      + + +
      +
      + + +
      +

      Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      wrap + + +number + + + + + + <optional>
      + + + +

      Wrap length. Defaults to 16.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toHex(debug) → {string}

      + + +
      +
      + + +
      +

      Returns the ByteBuffer's contents between offset and length as a hex string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      debug + + +boolean + + + + + + <optional>
      + + + +

      true to return the entire backing array with marked offsets, defaults to false

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Hex string or debug string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toString(enc) → {string}

      + + +
      +
      + + +
      +

      Converts the ByteBuffer to a string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      enc + + +string + + + + + + <optional>
      + + + +

      Output encoding. Returns an informative string representation by default but also allows + direct conversion to "utf8", "hex" and "base64" encoding. "debug" returns a hex representation with marked + offsets.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      String representation

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toUTF8() → {string}

      + + +
      +
      + + +
      +

      Returns the ByteBuffer's contents as an UTF8 encoded string.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      writeByte(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a byte. This is an alias of {ByteBuffer#writeInt8}.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeCString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + characters unless this is actually intended. This is not checked. If you have the option it is recommended + to use ByteBuffer#writeLString or ByteBuffer#writeVString with the corresponding reading + methods instead.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeDouble(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a double. This is an alias of ByteBuffer#writeFloat64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a float. This is an alias of ByteBuffer#writeFloat32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an integer. This is an alias of ByteBuffer#writeInt32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt8(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an 8bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if + omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt16(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 16bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeJSON(data, offset, stringify) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Serializes and writes a JSON payload.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      data + + +* + + + + + + + +

      Data payload to serialize

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      stringify + + +function(*) + + + + + + <optional>
      + + + +

      Stringify implementation to use. Defaults to JSON.stringify.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number if bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeLong(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a long. This is an alias of ByteBuffer#writeInt64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeLString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string with prepended number of characters, which is also encoded as an UTF8 character..

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeShort(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a short value. This is an alias of ByteBuffer#writeInt16.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint8(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an 8bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint16(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 16bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit unsigned integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUTF8String(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes an UTF8 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint32(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint64(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a 64bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeZigZagVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint32(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint64(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + +
      + + + + + +
      + +
      + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/index.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/index.html new file mode 100644 index 0000000..0751f84 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
      + +

      Index

      + + + + + + + +

      + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/module-ByteBuffer.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/module-ByteBuffer.html new file mode 100644 index 0000000..868c7a0 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/module-ByteBuffer.html @@ -0,0 +1,15872 @@ + + + + + Module: ByteBuffer + + + + + + + + + + +
      + +

      Module: ByteBuffer

      + + + + + +
      + +
      +

      + ByteBuffer +

      + +

      A full-featured ByteBuffer implementation in JavaScript using typed arrays.

      + +
      + +
      +
      + + + + +

      Constructs a new ByteBuffer.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + +
      + + + + + + + + + + + + +

      Members

      + +
      + +
      +

      <static, constant> BIG_ENDIAN :boolean

      + + +
      +
      + +
      +

      Big endian constant for usage in constructors instead of a boolean value. Evaluates to false.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> DEFAULT_CAPACITY :number

      + + +
      +
      + +
      +

      Default buffer capacity of 16. The ByteBuffer will be automatically resized by a factor of 2 if required.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> LITTLE_ENDIAN :boolean

      + + +
      +
      + +
      +

      Little endian constant for usage in constructors instead of a boolean value. Evaluates to true.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> Long :Long

      + + +
      +
      + +
      +

      Long class for int64 support. May be null if the Long class has not been loaded and int64 support is + not available.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> MAX_VARINT32_BYTES :number

      + + +
      +
      + +
      +

      Maximum number of bytes used by 32bit base 128 variable-length integer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> MAX_VARINT64_BYTES :number

      + + +
      +
      + +
      +

      Maximum number of bytes used by a 64bit base 128 variable-length integer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static, constant> VERSION :string

      + + +
      +
      + +
      +

      Version string.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      array :ArrayBuffer

      + + +
      +
      + +
      +

      Backing ArrayBuffer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      length :number

      + + +
      +
      + +
      +

      Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + offset and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      littleEndian :boolean

      + + +
      +
      + +
      +

      Whether to use little endian multi byte values, defaults to false for big endian.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      markedOffset :number

      + + +
      +
      + +
      +

      Marked offset set through ByteBuffer#mark. Defaults to -1 (no marked offset).

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      offset :number

      + + +
      +
      + +
      +

      Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + and length, which are both absolute indexes. There is no capacity property, use + ByteBuffer#capacity instead.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      view :DataView

      + + +
      +
      + +
      +

      DataView to mess with the ArrayBuffer.

      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + +
      + + + +

      Methods

      + +
      + +
      +

      <static> allocate(capacity, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Allocates a new ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      capacity + + +number + + + + + + <optional>
      + + + +

      Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY.

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian multi byte values, defaults to false for big + endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateUTF8Char(charCode) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode the specified char code.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      charCode + + +number + + + +

      Character to encode as char code

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be calculated (too large) +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Number of bytes required to encode the specified char code

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateUTF8String(str) → {number}

      + + +
      +
      + + +
      +

      Calculates the number of bytes required to store an UTF8 encoded string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      str + + +string + + + +

      String to calculate

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateVarint32(value) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number + + + +

      Value to encode

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required. Capped to ByteBuffer.MAX_VARINT32_BYTES

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> calculateVarint64(value) → {number}

      + + +
      +
      + + +
      +

      Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      value + + +number +| + +!Long + + + +

      Value to encode

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Number of bytes required. Capped to ByteBuffer.MAX_VARINT64_BYTES

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> decode64(str, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Decodes a base64 encoded string to a ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      Base64 encoded string

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian byte order, defaults to false for big endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid base64 encoded string +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      ByteBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> decodeBinary(str, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Decodes a binary string to a ByteBuffer. A binary string in this case is a string composed of 8bit values + as characters with a char code between 0 and 255 inclusive.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      Binary string

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian byte order, defaults to false for big endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid binary string +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      ByteBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> decodeHex(str, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Decodes a hex encoded string to a ByteBuffer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      Hex encoded string

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian byte order, defaults to false for big endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid hex encoded string +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      ByteBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> decodeUTF8Char(src, offset) → {{char: number, length: number}}

      + + +
      +
      + + +
      +

      Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      src + + +ByteBuffer + + + +
      offset + + +number + + + +

      Offset to read from

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be decoded or there is a capacity overflow +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Decoded char code and the actual number of bytes read

      +
      + + + +
      +
      + Type +
      +
      + +{char: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      <static> encode64(bb) → {string}

      + + +
      +
      + + +
      +

      Encodes a ByteBuffer's contents to a base64 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      bb + + +ByteBuffer + + + +

      ByteBuffer to encode. Will be cloned and flipped if length < offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid ByteBuffer +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Base64 encoded string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      <static> encodeBinary(bb) → {string}

      + + +
      +
      + + +
      +

      Encodes a ByteBuffer to a binary string. A binary string in this case is a string composed of 8bit values + as characters with a char code between 0 and 255 inclusive.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      bb + + +ByteBuffer + + + +

      ByteBuffer to encode. Will be cloned and flipped if length < offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid ByteBuffer +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Binary string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      <static> encodeHex(bb) → {string}

      + + +
      +
      + + +
      +

      Encodes a ByteBuffer to a hex encoded string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      bb + + +ByteBuffer + + + +

      ByteBuffer to encode. Will be cloned and flipped if length < offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the argument is not a valid ByteBuffer +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Hex encoded string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      <static> encodeUTF8Char(charCode, dst, offset) → {number}

      + + +
      +
      + + +
      +

      Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      charCode + + +number + + + +

      Character to encode as char code

      dst + + +ByteBuffer + + + +

      ByteBuffer to encode to

      offset + + +number + + + +

      Offset to write to

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the character cannot be encoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> isByteBuffer(bb) → {boolean}

      + + +
      +
      + + +
      +

      Tests if the specified type is a ByteBuffer or ByteBuffer-like.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      bb + + +* + + + +

      ByteBuffer to test

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      true if it is a ByteBuffer or ByteBuffer-like, otherwise false

      +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      <static> wrap(buffer, enc, littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + ByteBuffer's offset to 0 and its length to the wrapped object's byte length.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      buffer + + +ArrayBuffer +| + +!Buffer +| + +!{array: !ArrayBuffer} +| + +!{buffer: !ArrayBuffer} +| + +string + + + + + + + +

      Anything that can + be wrapped

      enc + + +string +| + +boolean + + + + + + <optional>
      + + + +

      String encoding if a string is provided (hex, utf8, binary, defaults to base64)

      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      true to use little endian multi byte values, defaults to false for big + endian.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified object cannot be wrapped +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagDecode32(n) → {number}

      + + +
      +
      + + +
      +

      Decodes a zigzag encoded signed 32bit integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number + + + +

      Unsigned zigzag encoded 32bit integer

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Signed 32bit integer

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagDecode64(n) → {Long}

      + + +
      +
      + + +
      +

      Decodes a zigzag encoded signed 64bit integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +Long +| + +number + + + +

      Unsigned zigzag encoded long or JavaScript number

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If long support is not available +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Signed long

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagEncode32(n) → {number}

      + + +
      +
      + + +
      +

      Encodes a signed 32bit integer so that it can be effectively used with varint encoding.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number + + + +

      Signed 32bit integer

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Unsigned zigzag encoded 32bit integer

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      <static> zigZagEncode64(n) → {Long}

      + + +
      +
      + + +
      +

      Encodes a signed 64bit integer so that it can be effectively used with varint encoding.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      n + + +number +| + +!Long + + + +

      Signed long

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Unsigned zigzag encoded long

      +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      append(src, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      src + + +* + + + + + + + +

      ByteBuffer or any object that can be wrapped to append

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to append at. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      BE(bigEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Switches big endian byte order.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      bigEndian + + +boolean + + + + + + <optional>
      + + + +

      Defaults to true, otherwise uses little endian

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      capacity() → {number}

      + + +
      +
      + + +
      +

      Gets the capacity of the backing buffer. This is independent from ByteBuffer#length and returns the + size of the entire backing array.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Capacity of the backing array or 0 if destroyed

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      clone() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + offsets.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Clone

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      compact() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set offset=0 and + length=capacity.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer cannot be compacted +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      copy() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Copy

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      destroy() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + is usually not required but may be useful in limited memory environments. Most successive operations will + rise an error until ByteBuffer#resize or ByteBuffer#ensureCapacity is called to reinitialize + the backing array.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      ensureCapacity(capacity) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + If double the previous capacity is less than the required capacity, the required capacity will be used.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      capacity + + +number + + + +

      Required capacity

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      flip() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Makes the buffer ready for a new sequence of write or relative read operations. Sets length=offset and + offset=0. Always make sure to flip a buffer when all relative writing operations are complete.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      LE(littleEndian) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Switches little endian byte order.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      littleEndian + + +boolean + + + + + + <optional>
      + + + +

      Defaults to true, otherwise uses big endian

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      mark(offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Marks an offset to be used with ByteBuffer#reset.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to mark. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + +
      See:
      +
      +
        +
      • ByteBuffer#reset
      • +
      +
      + + + +
      + + + + + +
      Throws:
      + + +
      + If the mark cannot be set +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      prepend(src, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      src + + +* + + + + + + + +

      ByteBuffer or any object that can be wrapped to prepend

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to prepend at. Defaults to ByteBuffer#offset.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the specified buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      printDebug(out)

      + + +
      +
      + + +
      +

      Prints debug information about this ByteBuffer's contents.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      out + + +function(string) + + + + + + <optional>
      + + + +

      Output function to call, defaults to console.log

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + +
      + + + +
      +

      readByte(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a byte. This is an alias of ByteBuffer#readInt8.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readCString(offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string followed by a NULL character (Uint8).

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readDouble(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a double. This is an alias of ByteBuffer#readFloat64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a float. This is an alias of ByteBuffer#readFloat32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readFloat64(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 64bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an integer. This is an alias of ByteBuffer#readInt32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt8(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an 8bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt16(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 16bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readInt64(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a 64bit integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readJSON(offset, parse) → {*|!{data: *, length: number}}

      + + +
      +
      + + +
      +

      Reads a JSON payload and unserializes it.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      parse + + +function(string) + + + + + + <optional>
      + + + +

      Parse implementation to use. Defaults to JSON.parse.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the data cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Data payload if offset is omitted, else the data payload and the + actual number of bytes read

      +
      + + + +
      +
      + Type +
      +
      + +* +| + +!{data: *, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readLong(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a long. This is an alias of ByteBuffer#readInt64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readLString(offset) → {string|{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string with a prepended number of characters, which is also encoded as an UTF8 character.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readShort(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a short value. This is an alias of ByteBuffer#readInt16.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint8(offset) → {number}

      + + +
      +
      + + +
      +

      Reads an 8bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint16(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 16bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint32(offset) → {number}

      + + +
      +
      + + +
      +

      Reads a 32bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      readUint64(offset) → {Long}

      + + +
      +
      + + +
      +

      Reads a 64bit unsigned integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If offset is out of bounds +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      readUTF8String(chars, offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads an UTF8 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      chars + + +number + + + + + + + +

      Number of characters to read

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readUTF8StringBytes(length, offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads an UTF8 string with the specified byte length.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      length + + +number + + + + + + + +

      Byte length

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the length did not match or the string cannot be decoded +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint(offset) → {number|{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint32(offset) → {number|!{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +!{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVarint64(offset) → {Long|!{value: Long, length: number}}

      + + +
      +
      + + +
      +

      Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and + the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +Long +| + +!{value: Long, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readVString(offset) → {string|!{string: string, length: number}}

      + + +
      +
      + + +
      +

      Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the string cannot be decoded or if it is not preceeded by a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The string read if offset is omitted, else the string + read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +string +| + +!{string: string, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint(offset) → {number|{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#readZigZagVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint32(offset) → {number|!{value: number, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read + and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +number +| + +!{value: number, length: number} + + +
      +
      + + + + +
      + + + +
      +

      readZigZagVarint64(offset) → {Long|!{value: Long, length: number}}

      + + +
      +
      + + +
      +

      Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      offset + + +number + + + + + + <optional>
      + + + +

      Offset to read from. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If it's not a valid varint +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      The value read if offset is omitted, else the value read and the actual number of bytes read.

      +
      + + + +
      +
      + Type +
      +
      + +Long +| + +!{value: Long, length: number} + + +
      +
      + + + + +
      + + + +
      +

      remaining() → {number}

      + + +
      +
      + + +
      +

      Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + returns length-offset.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Remaining readable bytes. May be negative if offset>length.

      +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      reset() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Resets the ByteBuffer. If an offset has been marked through ByteBuffer#mark before, the offset will + be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + no marked offset, sets offset=0 and length=0.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + +
      See:
      +
      +
        +
      • ByteBuffer#mark
      • +
      +
      + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      resize(capacity) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      capacity + + +number + + + +

      New capacity

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      reverse() → {ByteBuffer}

      + + +
      +
      + + +
      +

      Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + offset.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer is already destroyed +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      slice(begin, end) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + ArrayBuffer (use ByteBuffer#compact or ByteBuffer.wrap instead).

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      begin + + +number + + + + + + <optional>
      + + + +

      Begin offset, defaults to ByteBuffer#offset.

      end + + +number + + + + + + <optional>
      + + + +

      End offset, defaults to ByteBuffer#length.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + +
      Throws:
      + + +
      + If the buffer cannot be sliced +
      + + + +
      +
      + Type +
      +
      + +Error + + +
      +
      + + + + +
      Returns:
      + + +
      +

      Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      toArrayBuffer(forceCopy) → {ArrayBuffer}

      + + +
      +
      + + +
      +

      Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will return a reference to + the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      forceCopy + + +boolean + + + + + + <optional>
      + + + +

      true forces the creation of a copy, defaults to false

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Compacted ArrayBuffer or null if already destroyed

      +
      + + + +
      +
      + Type +
      +
      + +ArrayBuffer + + +
      +
      + + + + +
      + + + +
      +

      toBase64() → {string}

      + + +
      +
      + + +
      +

      Returns the base64 encoded representation of the ByteBuffer's contents.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Base 64 encoded string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toBinary() → {string}

      + + +
      +
      + + +
      +

      Returns the ByteBuffer's contents between offset and length as a binary string. A binary string in this case + is a string composed of 8bit values as characters with a char code between 0 and 255 inclusive.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Binary string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toBuffer() → {Buffer}

      + + +
      +
      + + +
      +

      Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + ByteBuffer#flip the ByteBuffer if its offset is larger than its length. Will also copy all data (not + a reference).

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Compacted node Buffer or null if already destroyed

      +
      + + + +
      +
      + Type +
      +
      + +Buffer + + +
      +
      + + + + +
      + + + +
      +

      toColumns(wrap) → {string}

      + + +
      +
      + + +
      +

      Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      wrap + + +number + + + + + + <optional>
      + + + +

      Wrap length. Defaults to 16.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toHex(debug) → {string}

      + + +
      +
      + + +
      +

      Returns the ByteBuffer's contents between offset and length as a hex string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      debug + + +boolean + + + + + + <optional>
      + + + +

      true to return the entire backing array with marked offsets, defaults to false

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      Hex string or debug string

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toString(enc) → {string}

      + + +
      +
      + + +
      +

      Converts the ByteBuffer to a string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      enc + + +string + + + + + + <optional>
      + + + +

      Output encoding. Returns an informative string representation by default but also allows + direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + marked offsets.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      String representation

      +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toUTF8() → {string}

      + + +
      +
      + + +
      +

      Returns the ByteBuffer's contents as an UTF8 encoded string.

      +
      + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      writeByte(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a byte. This is an alias of {ByteBuffer#writeInt8}.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeCString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + characters unless this is actually intended. This is not checked. If you have the option it is recommended + to use ByteBuffer#writeLString or ByteBuffer#writeVString with the corresponding reading + methods instead.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeDouble(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a double. This is an alias of ByteBuffer#writeFloat64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a float. This is an alias of ByteBuffer#writeFloat32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeFloat64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit float.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an integer. This is an alias of ByteBuffer#writeInt32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt8(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an 8bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if + omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt16(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 16bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit signed integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeInt64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeJSON(data, offset, stringify) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Serializes and writes a JSON payload.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      data + + +* + + + + + + + +

      Data payload to serialize

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      stringify + + +function(*) + + + + + + <optional>
      + + + +

      Stringify implementation to use. Defaults to JSON.stringify.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number if bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeLong(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a long. This is an alias of ByteBuffer#writeInt64.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeLString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string with prepended number of characters, which is also encoded as an UTF8 character..

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeShort(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a short value. This is an alias of ByteBuffer#writeInt16.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint8(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes an 8bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint16(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 16bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint32(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 32bit unsigned integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUint64(value, offset) → {ByteBuffer}

      + + +
      +
      + + +
      +

      Writes a 64bit unsigned integer. Requires Long.js.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +!Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer + + +
      +
      + + + + +
      + + + +
      +

      writeUTF8String(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes an UTF8 string.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a base 128 variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint32(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a 32bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVarint64(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a 64bit base 128 variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number +| + +Long + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeVString(str, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + integer.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + +

      String to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of ByteBuffer#writeZigZagVarint32.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint32(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Will use and advance ByteBuffer#offset if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + + + +
      +

      writeZigZagVarint64(value, offset) → {ByteBuffer|number}

      + + +
      +
      + + +
      +

      Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf.

      +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + +

      Value to write

      offset + + +number + + + + + + <optional>
      + + + +

      Offset to write to. Defaults to ByteBuffer#offset which will be modified only if omitted.

      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      +

      this if offset is omitted, else the actual number of bytes written.

      +
      + + + +
      +
      + Type +
      +
      + +ByteBuffer +| + +number + + +
      +
      + + + + +
      + +
      + + + + + +
      + +
      + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/html5.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/prettify.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p} deps + * @param {function(...[*])} f + */ +function define(name, deps, f) {}; + +/** + * @param {number} size + * @constructor + * @extends Array + */ +function Buffer(size) {}; + +/** + * @param {*} buf + * @return {boolean} + */ +Buffer.isBuffer = function(buf) {}; + +/** + * @type {Object.} + */ +var console = {}; + +/** + * @param {string} s + */ +console.log = function(s) {}; + +/** + * @type {*} + */ +var module = {}; diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/jsdoc.json b/javascript/node_modules/protobufjs/node_modules/bytebuffer/jsdoc.json new file mode 100644 index 0000000..95ab5fc --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/jsdoc.json @@ -0,0 +1,13 @@ +{ + "tags": { + "allowUnknownTags": true + }, + "source": { + "include": ["ByteBuffer.js"] + }, + "opts": { + "template": "templates/esoccer", + "destination": "docs" + }, + "plugins": ["plugins/markdown"] +} \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.npmignore b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.npmignore new file mode 100644 index 0000000..3abe3d4 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.npmignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.travis.yml b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.travis.yml new file mode 100644 index 0000000..3f38c24 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - 0.4 + - 0.6 + - 0.8 + - 0.10 diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/LICENSE b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/LICENSE new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.js new file mode 100644 index 0000000..339e8ad --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.js @@ -0,0 +1,940 @@ +/* + Copyright 2013 Daniel Wirtz + Copyright 2009 The Closure Library Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license Long.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/Long.js for details + * + * Long.js is based on goog.math.Long from the Closure Library. + * Copyright 2009 The Closure Library Authors. All Rights Reserved. + * Released under the Apache License, Version 2.0 + * see: https://code.google.com/p/closure-library/ for details + */ + +/** + * Defines a Long class for representing a 64-bit two's-complement + * integer value, which faithfully simulates the behavior of a Java "long". This + * implementation is derived from LongLib in GWT. + */ +(function(global) { + + /** + * Constructs a 64-bit two's-complement integer, given its low and high 32-bit + * values as *signed* integers. See the from* functions below for more + * convenient ways of constructing Longs. + * + * The internal representation of a long is the two given signed, 32-bit values. + * We use 32-bit pieces because these are the size of integers on which + * Javascript performs bit-operations. For operations like addition and + * multiplication, we split each number into 16-bit pieces, which can easily be + * multiplied within Javascript's floating-point representation without overflow + * or change in sign. + * + * In the algorithms below, we frequently reduce the negative case to the + * positive case by negating the input(s) and then post-processing the result. + * Note that we must ALWAYS check specially whether those values are MIN_VALUE + * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as + * a positive number, it overflows back into a negative). Not handling this + * case would often result in infinite recursion. + * + * @exports Long + * @class A Long class for representing a 64-bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long. + * @param {number} high The high (signed) 32 bits of the long. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed). + * @constructor + */ + var Long = function(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + * @expose + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + * @expose + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + * @expose + */ + this.unsigned = !!unsigned; + }; + + // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* methods on which they depend. + + // NOTE: The following cache variables are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * A cache of the Long representations of small integer values. + * @type {!Object} + */ + var INT_CACHE = {}; + + /** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + */ + var UINT_CACHE = {}; + + /** + * Returns a Long representing the given (32-bit) integer value. + * @param {number} value The 32-bit integer in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromInt = function(value, unsigned) { + var obj, cachedObj; + if (!unsigned) { + value = value | 0; + if (-128 <= value && value < 128) { + cachedObj = INT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, value < 0 ? -1 : 0, false); + if (-128 <= value && value < 128) { + INT_CACHE[value] = obj; + } + return obj; + } else { + value = value >>> 0; + if (0 <= value && value < 256) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) return cachedObj; + } + obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); + if (0 <= value && value < 256) { + UINT_CACHE[value] = obj; + } + return obj; + } + }; + + /** + * Returns a Long representing the given value, provided that it is a finite + * number. Otherwise, zero is returned. + * @param {number} value The number in question. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromNumber = function(value, unsigned) { + unsigned = !!unsigned; + if (isNaN(value) || !isFinite(value)) { + return Long.ZERO; + } else if (!unsigned && value <= -TWO_PWR_63_DBL) { + return Long.MIN_SIGNED_VALUE; + } else if (unsigned && value <= 0) { + return Long.MIN_UNSIGNED_VALUE; + } else if (!unsigned && value + 1 >= TWO_PWR_63_DBL) { + return Long.MAX_SIGNED_VALUE; + } else if (unsigned && value >= TWO_PWR_64_DBL) { + return Long.MAX_UNSIGNED_VALUE; + } else if (value < 0) { + return Long.fromNumber(-value, false).negate(); + } else { + return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); + } + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @param {number} lowBits The low 32 bits. + * @param {number} highBits The high 32 bits. + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromBits = function(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); + }; + + /** + * Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + * Each is assumed to use 28 bits. + * @param {number} part0 The low 28 bits + * @param {number} part1 The middle 28 bits + * @param {number} part2 The high 28 (8) bits + * @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). + * @return {!Long} + * @expose + */ + Long.from28Bits = function(part0, part1, part2, unsigned) { + // 00000000000000000000000000001111 11111111111111111111111122222222 2222222222222 + // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH + return Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, unsigned); + }; + + /** + * Returns a Long representation of the given string, written using the given + * radix. + * @param {string} str The textual representation of the Long. + * @param {(boolean|number)=} unsigned Whether unsigned or not. Defaults to false (signed). + * @param {number=} radix The radix in which the text is written. + * @return {!Long} The corresponding Long value. + * @expose + */ + Long.fromString = function(str, unsigned, radix) { + if (str.length == 0) { + throw(new Error('number format error: empty string')); + } + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") { + return Long.ZERO; + } + if (typeof unsigned === 'number') { // For goog.math.Long compatibility + radix = unsigned; + unsigned = false; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + + if (str.charAt(0) == '-') { + return Long.fromString(str.substring(1), unsigned, radix).negate(); + } else if (str.indexOf('-') >= 0) { + throw(new Error('number format error: interior "-" character: ' + str)); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 8)); + + var result = Long.ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i); + var value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = Long.fromNumber(Math.pow(radix, size)); + result = result.multiply(power).add(Long.fromNumber(value)); + } else { + result = result.multiply(radixToPower); + result = result.add(Long.fromNumber(value)); + } + } + return result; + }; + + // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be + // no runtime penalty for these. + + // NOTE: The following constant values are used internally only and are therefore not exposed as properties of the + // Long class. + + /** + * @type {number} + */ + var TWO_PWR_16_DBL = 1 << 16; + + /** + * @type {number} + */ + var TWO_PWR_24_DBL = 1 << 24; + + /** + * @type {number} + */ + var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_31_DBL = TWO_PWR_32_DBL / 2; + + /** + * @type {number} + */ + var TWO_PWR_48_DBL = TWO_PWR_32_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + */ + var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + + /** + * @type {number} + */ + var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + + /** + * @type {!Long} + */ + var TWO_PWR_24 = Long.fromInt(1 << 24); + + /** + * @type {!Long} + * @expose + */ + Long.ZERO = Long.fromInt(0); + + /** + * @type {!Long} + * @expose + */ + Long.ONE = Long.fromInt(1); + + /** + * @type {!Long} + * @expose + */ + Long.NEG_ONE = Long.fromInt(-1); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_SIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); + + /** + * Alias of {@link Long.MAX_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MAX_VALUE = Long.MAX_SIGNED_VALUE; + + /** + * @type {!Long} + * @expose + */ + Long.MIN_SIGNED_VALUE = Long.fromBits(0, 0x80000000 | 0, false); + + /** + * @type {!Long} + * @expose + */ + Long.MIN_UNSIGNED_VALUE = Long.fromBits(0, 0, true); + + /** + * Alias of {@link Long.MIN_SIGNED_VALUE} for goog.math.Long compatibility. + * @type {!Long} + * @expose + */ + Long.MIN_VALUE = Long.MIN_SIGNED_VALUE; + + /** + * @return {number} The value, assuming it is a 32-bit integer. + * @expose + */ + Long.prototype.toInt = function() { + return this.unsigned ? this.low >>> 0 : this.low; + }; + + /** + * @return {number} The closest floating-point representation to this value. + * @expose + */ + Long.prototype.toNumber = function() { + if (this.unsigned) { + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + } + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); + }; + + /** + * @param {number=} radix The radix in which the text should be written. + * @return {string} The textual representation of this value. + * @override + * @expose + */ + Long.prototype.toString = function(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) { + throw(new Error('radix out of range: ' + radix)); + } + if (this.isZero()) { + return '0'; + } + var rem; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = Long.fromNumber(radix); + var div = this.div(radixLong); + rem = div.multiply(radixLong).subtract(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else { + return '-' + this.negate().toString(radix); + } + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = Long.fromNumber(Math.pow(radix, 6)); + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower); + var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt(); + var digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) { + return digits + result; + } else { + while (digits.length < 6) { + digits = '0' + digits; + } + result = '' + digits + result; + } + } + }; + + /** + * @return {number} The high 32 bits as a signed value. + * @expose + */ + Long.prototype.getHighBits = function() { + return this.high; + }; + + /** + * @return {number} The high 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getHighBitsUnsigned = function() { + return this.high >>> 0; + }; + + /** + * @return {number} The low 32 bits as a signed value. + * @expose + */ + Long.prototype.getLowBits = function() { + return this.low; + }; + + /** + * @return {number} The low 32 bits as an unsigned value. + * @expose + */ + Long.prototype.getLowBitsUnsigned = function() { + return this.low >>> 0; + }; + + /** + * @return {number} Returns the number of bits needed to represent the absolute + * value of this Long. + * @expose + */ + Long.prototype.getNumBitsAbs = function() { + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.equals(Long.MIN_SIGNED_VALUE)) { + return 64; + } else { + return this.negate().getNumBitsAbs(); + } + } else { + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) { + if ((val & (1 << bit)) != 0) { + break; + } + } + return this.high != 0 ? bit + 33 : bit + 1; + } + }; + + /** + * @return {boolean} Whether this value is zero. + * @expose + */ + Long.prototype.isZero = function() { + return this.high == 0 && this.low == 0; + }; + + /** + * @return {boolean} Whether this value is negative. + * @expose + */ + Long.prototype.isNegative = function() { + return !this.unsigned && this.high < 0; + }; + + /** + * @return {boolean} Whether this value is odd. + * @expose + */ + Long.prototype.isOdd = function() { + return (this.low & 1) == 1; + }; + + /** + * @return {boolean} Whether this value is even. + */ + Long.prototype.isEven = function() { + return (this.low & 1) == 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long equals the other. + * @expose + */ + Long.prototype.equals = function(other) { + if (this.unsigned != other.unsigned && (this.high >>> 31) != (other.high >>> 31)) return false; + return (this.high == other.high) && (this.low == other.low); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long does not equal the other. + * @expose + */ + Long.prototype.notEquals = function(other) { + return !this.equals(other); + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than the other. + * @expose + */ + Long.prototype.lessThan = function(other) { + return this.compare(other) < 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is less than or equal to the other. + * @expose + */ + Long.prototype.lessThanOrEqual = function(other) { + return this.compare(other) <= 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than the other. + * @expose + */ + Long.prototype.greaterThan = function(other) { + return this.compare(other) > 0; + }; + + /** + * @param {Long} other Long to compare against. + * @return {boolean} Whether this Long is greater than or equal to the other. + * @expose + */ + Long.prototype.greaterThanOrEqual = function(other) { + return this.compare(other) >= 0; + }; + + /** + * Compares this Long with the given one. + * @param {Long} other Long to compare against. + * @return {number} 0 if they are the same, 1 if the this is greater, and -1 + * if the given one is greater. + * @expose + */ + Long.prototype.compare = function(other) { + if (this.equals(other)) { + return 0; + } + var thisNeg = this.isNegative(); + var otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) return -1; + if (!thisNeg && otherNeg) return 1; + if (!this.unsigned) { + // At this point the signs are the same + return this.subtract(other).isNegative() ? -1 : 1; + } else { + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high == this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; + } + }; + + /** + * @return {!Long} The negation of this value. + * @expose + */ + Long.prototype.negate = function() { + if (!this.unsigned && this.equals(Long.MIN_SIGNED_VALUE)) { + return Long.MIN_SIGNED_VALUE; + } + return this.not().add(Long.ONE); + }; + + /** + * Returns the sum of this and the given Long. + * @param {Long} other Long to add to this one. + * @return {!Long} The sum of this and the given Long. + * @expose + */ + Long.prototype.add = function(other) { + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns the difference of this and the given Long. + * @param {Long} other Long to subtract from this. + * @return {!Long} The difference of this and the given Long. + * @expose + */ + Long.prototype.subtract = function(other) { + return this.add(other.negate()); + }; + + /** + * Returns the product of this and the given long. + * @param {Long} other Long to multiply with this. + * @return {!Long} The product of this and the other. + * @expose + */ + Long.prototype.multiply = function(other) { + if (this.isZero()) { + return Long.ZERO; + } else if (other.isZero()) { + return Long.ZERO; + } + + if (this.equals(Long.MIN_VALUE)) { + return other.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } else if (other.equals(Long.MIN_VALUE)) { + return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; + } + + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().multiply(other.negate()); + } else { + return this.negate().multiply(other).negate(); + } + } else if (other.isNegative()) { + return this.multiply(other.negate()).negate(); + } + // If both longs are small, use float multiplication + if (this.lessThan(TWO_PWR_24) && + other.lessThan(TWO_PWR_24)) { + return Long.fromNumber(this.toNumber() * other.toNumber(), this.unsigned); + } + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = other.high >>> 16; + var b32 = other.high & 0xFFFF; + var b16 = other.low >>> 16; + var b00 = other.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns this Long divided by the given one. + * @param {Long} other Long by which to divide. + * @return {!Long} This Long divided by the given one. + * @expose + */ + Long.prototype.div = function(other) { + if (other.isZero()) { + throw(new Error('division by zero')); + } else if (this.isZero()) { + return Long.ZERO; + } + if (this.equals(Long.MIN_SIGNED_VALUE)) { + if (other.equals(Long.ONE) || other.equals(Long.NEG_ONE)) { + return min; // recall that -MIN_VALUE == MIN_VALUE + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ONE; + } else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shiftRight(1); + var approx = halfThis.div(other).shiftLeft(1); + if (approx.equals(Long.ZERO)) { + return other.isNegative() ? Long.ONE : Long.NEG_ONE; + } else { + var rem = this.subtract(other.multiply(approx)); + var result = approx.add(rem.div(other)); + return result; + } + } + } else if (other.equals(Long.MIN_VALUE)) { + return Long.ZERO; + } + if (this.isNegative()) { + if (other.isNegative()) { + return this.negate().div(other.negate()); + } else { + return this.negate().div(other).negate(); + } + } else if (other.isNegative()) { + return this.div(other.negate()).negate(); + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + var res = Long.ZERO; + var rem = this; + while (rem.greaterThanOrEqual(other)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2); + var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48); + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + var approxRes = Long.fromNumber(approx, this.unsigned); + var approxRem = approxRes.multiply(other); + while (approxRem.isNegative() || approxRem.greaterThan(rem)) { + approx -= delta; + approxRes = Long.fromNumber(approx, this.unsigned); + approxRem = approxRes.multiply(other); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) { + approxRes = Long.ONE; + } + + res = res.add(approxRes); + rem = rem.subtract(approxRem); + } + return res; + }; + + /** + * Returns this Long modulo the given one. + * @param {Long} other Long by which to mod. + * @return {!Long} This Long modulo the given one. + * @expose + */ + Long.prototype.modulo = function(other) { + return this.subtract(this.div(other).multiply(other)); + }; + + /** + * @return {!Long} The bitwise-NOT of this value. + * @expose + */ + Long.prototype.not = function() { + return Long.fromBits(~this.low, ~this.high, this.unsigned); + }; + + /** + * Returns the bitwise-AND of this Long and the given one. + * @param {Long} other The Long with which to AND. + * @return {!Long} The bitwise-AND of this and the other. + * @expose + */ + Long.prototype.and = function(other) { + return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned); + }; + + /** + * Returns the bitwise-OR of this Long and the given one. + * @param {Long} other The Long with which to OR. + * @return {!Long} The bitwise-OR of this and the other. + * @expose + */ + Long.prototype.or = function(other) { + return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned); + }; + + /** + * Returns the bitwise-XOR of this Long and the given one. + * @param {Long} other The Long with which to XOR. + * @return {!Long} The bitwise-XOR of this and the other. + * @expose + */ + Long.prototype.xor = function(other) { + return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); + }; + + /** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the left by the given amount. + * @expose + */ + Long.prototype.shiftLeft = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var low = this.low; + if (numBits < 32) { + var high = this.high; + return Long.fromBits(low << numBits, (high << numBits) | (low >>> (32 - numBits)), this.unsigned); + } else { + return Long.fromBits(0, low << (numBits - 32), this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount. + * @expose + */ + Long.prototype.shiftRight = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >> numBits, this.unsigned); + } else { + return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1, this.unsigned); + } + } + }; + + /** + * Returns this Long with bits shifted to the right by the given amount, with + * the new top bits matching the current sign bit. + * @param {number} numBits The number of bits by which to shift. + * @return {!Long} This shifted to the right by the given amount, with + * zeros placed into the new leading bits. + * @expose + */ + Long.prototype.shiftRightUnsigned = function(numBits) { + numBits &= 63; + if (numBits == 0) { + return this; + } else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits == 32) { + return Long.fromBits(high, 0, this.unsigned); + } else { + return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned); + } + } + }; + + /** + * @return {!Long} Signed long + * @expose + */ + Long.prototype.toSigned = function() { + var l = this.clone(); + l.unsigned = false; + return l; + }; + + /** + * @return {!Long} Unsigned long + * @expose + */ + Long.prototype.toUnsigned = function() { + var l = this.clone(); + l.unsigned = true; + return l; + }; + + /** + * @return {Long} Cloned instance with the same low/high bits and unsigned flag. + * @expose + */ + Long.prototype.clone = function() { + return new Long(this.low, this.high, this.unsigned); + }; + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = Long; + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("Math/Long", [], function() { return Long; }); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["Long"] = Long; + } + +})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.min.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.min.js new file mode 100644 index 0000000..a1be1ab --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/Long.min.js @@ -0,0 +1,26 @@ +/* + Long.js (c) 2013 Daniel Wirtz + Released under the Apache License, Version 2.0 + see: https://github.com/dcodeIO/Long.js for details + + Long.js is based on goog.math.Long from the Closure Library. + Copyright 2009 The Closure Library Authors. All Rights Reserved. + Released under the Apache License, Version 2.0 + see: https://code.google.com/p/closure-library/ for details +*/ +var p=!1; +(function(r){function b(a,b,d){this.low=a|0;this.high=b|0;this.unsigned=!!d}var s={},t={};b.fromInt=function(a,c){var d;if(c){a>>>=0;if(0<=a&&256>a&&(d=t[a]))return d;d=new b(a,0>(a|0)?-1:0,!0);0<=a&&256>a&&(t[a]=d)}else{a|=0;if(-128<=a&&128>a&&(d=s[a]))return d;d=new b(a,0>a?-1:0,p);-128<=a&&128>a&&(s[a]=d)}return d};b.fromNumber=function(a,c){c=!!c;return isNaN(a)||!isFinite(a)?b.ZERO:!c&&a<=-u?b.MIN_SIGNED_VALUE:c&&0>=a?b.MIN_UNSIGNED_VALUE:!c&&a+1>=u?b.MAX_SIGNED_VALUE:c&&a>=v?b.MAX_UNSIGNED_VALUE:0> +a?b.fromNumber(-a,p).negate():new b(a%l|0,a/l|0,c)};b.fromBits=function(a,c,d){return new b(a,c,d)};b.from28Bits=function(a,c,d,e){return b.fromBits(a|c<<28,c>>>4|d<<24,e)};b.fromString=function(a,c,d){if(0==a.length)throw Error("number format error: empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return b.ZERO;"number"===typeof c&&(d=c,c=p);d=d||10;if(2>d||36f?(f=b.fromNumber(Math.pow(d,f)),e=e.multiply(f).add(b.fromNumber(k))):(e=e.multiply(c),e=e.add(b.fromNumber(k)))}return e};var l=4294967296,v=l*l,u=v/2,w=b.fromInt(16777216);b.ZERO=b.fromInt(0);b.ONE=b.fromInt(1);b.NEG_ONE=b.fromInt(-1);b.MAX_SIGNED_VALUE=b.fromBits(-1,2147483647,p); +b.MAX_UNSIGNED_VALUE=b.fromBits(-1,-1,!0);b.MAX_VALUE=b.MAX_SIGNED_VALUE;b.MIN_SIGNED_VALUE=b.fromBits(0,-2147483648,p);b.MIN_UNSIGNED_VALUE=b.fromBits(0,0,!0);b.MIN_VALUE=b.MIN_SIGNED_VALUE;b.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low};b.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)};b.prototype.toString=function(a){a=a||10;if(2>a||36f.length;)f="0"+f;e=""+f+e}};b.prototype.getHighBits=function(){return this.high};b.prototype.getHighBitsUnsigned=function(){return this.high>>>0}; +b.prototype.getLowBits=function(){return this.low};b.prototype.getLowBitsUnsigned=function(){return this.low>>>0};b.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(b.MIN_SIGNED_VALUE)?64:this.negate().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,c=31;0this.high};b.prototype.isOdd=function(){return 1== +(this.low&1)};b.prototype.equals=function(a){return this.unsigned!=a.unsigned&&this.high>>>31!=a.high>>>31?p:this.high==a.high&&this.low==a.low};b.prototype.notEquals=function(a){return!this.equals(a)};b.prototype.lessThan=function(a){return 0>this.compare(a)};b.prototype.lessThanOrEqual=function(a){return 0>=this.compare(a)};b.prototype.greaterThan=function(a){return 0>>0>this.high>>>0||a.high==this.high&&a.low>>>0>this.low>>>0?-1:1:this.subtract(a).isNegative()?-1:1};b.prototype.negate=function(){return!this.unsigned&&this.equals(b.MIN_SIGNED_VALUE)?b.MIN_SIGNED_VALUE:this.not().add(b.ONE)};b.prototype.add=function(a){var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=a.high>>>16,f=a.high&65535,k=a.low>>>16,q;q=0+((this.low&65535)+(a.low&65535));a=0+(q>>>16);a+=e+k;e=0+ +(a>>>16);e+=d+f;d=0+(e>>>16);d=d+(c+g)&65535;return b.fromBits((a&65535)<<16|q&65535,d<<16|e&65535,this.unsigned)};b.prototype.subtract=function(a){return this.add(a.negate())};b.prototype.multiply=function(a){if(this.isZero()||a.isZero())return b.ZERO;if(this.equals(b.MIN_VALUE))return a.isOdd()?b.MIN_VALUE:b.ZERO;if(a.equals(b.MIN_VALUE))return this.isOdd()?b.MIN_VALUE:b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().multiply(a.negate()):this.negate().multiply(a).negate();if(a.isNegative())return this.multiply(a.negate()).negate(); +if(this.lessThan(w)&&a.lessThan(w))return b.fromNumber(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=this.low&65535,f=a.high>>>16,k=a.high&65535,q=a.low>>>16;a=a.low&65535;var n,h,m,l;l=0+g*a;m=0+(l>>>16);m+=e*a;h=0+(m>>>16);m=(m&65535)+g*q;h+=m>>>16;m&=65535;h+=d*a;n=0+(h>>>16);h=(h&65535)+e*q;n+=h>>>16;h&=65535;h+=g*k;n+=h>>>16;h&=65535;n=n+(c*a+d*q+e*k+g*f)&65535;return b.fromBits(m<<16|l&65535,n<<16|h,this.unsigned)};b.prototype.div=function(a){if(a.isZero())throw Error("division by zero"); +if(this.isZero())return b.ZERO;if(this.equals(b.MIN_SIGNED_VALUE)){if(a.equals(b.ONE)||a.equals(b.NEG_ONE))return min;if(a.equals(b.MIN_VALUE))return b.ONE;var c=this.shiftRight(1).div(a).shiftLeft(1);if(c.equals(b.ZERO))return a.isNegative()?b.ONE:b.NEG_ONE;var d=this.subtract(a.multiply(c));return c.add(d.div(a))}if(a.equals(b.MIN_VALUE))return b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().div(a.negate()):this.negate().div(a).negate();if(a.isNegative())return this.div(a.negate()).negate(); +for(var e=b.ZERO,d=this;d.greaterThanOrEqual(a);){for(var c=Math.max(1,Math.floor(d.toNumber()/a.toNumber())),g=Math.ceil(Math.log(c)/Math.LN2),g=48>=g?1:Math.pow(2,g-48),f=b.fromNumber(c,this.unsigned),k=f.multiply(a);k.isNegative()||k.greaterThan(d);)c-=g,f=b.fromNumber(c,this.unsigned),k=f.multiply(a);f.isZero()&&(f=b.ONE);e=e.add(f);d=d.subtract(k)}return e};b.prototype.modulo=function(a){return this.subtract(this.div(a).multiply(a))};b.prototype.not=function(){return b.fromBits(~this.low,~this.high, +this.unsigned)};b.prototype.and=function(a){return b.fromBits(this.low&a.low,this.high&a.high,this.unsigned)};b.prototype.or=function(a){return b.fromBits(this.low|a.low,this.high|a.high,this.unsigned)};b.prototype.xor=function(a){return b.fromBits(this.low^a.low,this.high^a.high,this.unsigned)};b.prototype.shiftLeft=function(a){a&=63;if(0==a)return this;var c=this.low;return 32>a?b.fromBits(c<>>32-a,this.unsigned):b.fromBits(0,c<a?b.fromBits(this.low>>>a|c<<32-a,c>>a,this.unsigned):b.fromBits(c>>a-32,0<=c?0:-1,this.unsigned)};b.prototype.shiftRightUnsigned=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>>a,this.unsigned):32==a?b.fromBits(c,0,this.unsigned):b.fromBits(c>>>a-32,0,this.unsigned)};b.prototype.toSigned=function(){var a=this.clone();a.unsigned=p;return a};b.prototype.toUnsigned=function(){var a=this.clone();a.unsigned= +!0;return a};b.prototype.clone=function(){return new b(this.low,this.high,this.unsigned)};"undefined"!=typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("Math/Long",[],function(){return b}):(r.dcodeIO||(r.dcodeIO={}),r.dcodeIO.Long=b)})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/NOTICE b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/NOTICE new file mode 100644 index 0000000..7563caf --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/NOTICE @@ -0,0 +1,2 @@ +This software includes (portions of) Long.js by Daniel 'dcode' Wirtz. +See: https://github.com/dcodeIO/Long.js for details diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/README.md b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/README.md new file mode 100644 index 0000000..2e48bd8 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/README.md @@ -0,0 +1,75 @@ +![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png) +======= +A Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/) +for stand-alone use and extended with unsigned support. + +Why? +---- +As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value +of 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit +numbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations +on the full 64bits. This is where Long.js comes into play. + +Features +-------- +* [CommonJS](http://www.commonjs.org/) compatible +* [RequireJS](http://requirejs.org/)/AMD compatible +* Shim compatible (include the script, then use var Long = dcodeIO.Long;) +* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long) +* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) +* API-compatible to the Closure Library implementation +* Zero production dependencies +* Small footprint + +Usage +----- + +#### node.js / CommonJS #### + +Install: `npm install long` + +```javascript +var Long = require("long"); +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +console.log(longVal.toString()); +... +``` + +#### RequireJS / AMD #### + +````javascript +require.config({ + "paths": { + "Math/Long": "/path/to/Long.js" + } +}); +require(["Math/Long"], function(Long) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + console.log(longVal.toString()); +}); +```` + +### Browser / shim #### + +```html + +``` + +```javascript +var Long = dcodeIO.Long; +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +alert(longVal.toString()); +``` + +Documentation +------------- +* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html) + +Downloads +--------- +* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip) +* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master) + +License +------- +Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/bower.json b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/bower.json new file mode 100644 index 0000000..5627a2d --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/bower.json @@ -0,0 +1,9 @@ +{ + "name": "long", + "version": "1.1.2", + "author": "Daniel Wirtz ", + "description": "Long.js: A Long class for representing a 64-bit two's-complement integer value derived from the Closure Library extended with unsigned support.", + "main": "Long.js", + "keywords": ["math"], + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/Long.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/Long.html new file mode 100644 index 0000000..effa27b --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/Long.html @@ -0,0 +1,5380 @@ + + + + + Class: Long + + + + + + + + + + +
      + +

      Class: Long

      + + + + + +
      + +
      +

      + Long +

      + +
      A Long class for representing a 64-bit two's-complement integer value.
      + +
      + +
      +
      + + + + +
      +

      new Long(low, high, unsigned)

      + + +
      +
      + + +
      + Constructs a 64-bit two's-complement integer, given its low and high 32-bit +values as *signed* integers. See the from* functions below for more +convenient ways of constructing Longs. + +The internal representation of a long is the two given signed, 32-bit values. +We use 32-bit pieces because these are the size of integers on which +Javascript performs bit-operations. For operations like addition and +multiplication, we split each number into 16-bit pieces, which can easily be +multiplied within Javascript's floating-point representation without overflow +or change in sign. + +In the algorithms below, we frequently reduce the negative case to the +positive case by negating the input(s) and then post-processing the result. +Note that we must ALWAYS check specially whether those values are MIN_VALUE +(-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +a positive number, it overflows back into a negative). Not handling this +case would often result in infinite recursion. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      low + + +number + + + + + + + + The low (signed) 32 bits of the long.
      high + + +number + + + + + + + + The high (signed) 32 bits of the long.
      unsigned + + +boolean + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to `false` (signed).
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + +
      + + +
      + + + + + + + + + + + + +

      Members

      + +
      + +
      +

      <static> MAX_SIGNED_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MAX_UNSIGNED_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MAX_VALUE :Long

      + + +
      +
      + +
      + Alias of Long.MAX_SIGNED_VALUE for goog.math.Long compatibility. +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MIN_SIGNED_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MIN_UNSIGNED_VALUE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> MIN_VALUE :Long

      + + +
      +
      + +
      + Alias of Long.MIN_SIGNED_VALUE for goog.math.Long compatibility. +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> NEG_ONE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> ONE :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      <static> ZERO :Long

      + + +
      +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      high :number

      + + +
      +
      + +
      + The high 32 bits as a signed value. +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      low :number

      + + +
      +
      + +
      + The low 32 bits as a signed value. +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      +

      unsigned :boolean

      + + +
      +
      + +
      + Whether unsigned or not. +
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + +
      + + + +

      Methods

      + +
      + +
      +

      <static> from28Bits(part0, part1, part2, unsigned) → {Long}

      + + +
      +
      + + +
      + Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. + Each is assumed to use 28 bits. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      part0 + + +number + + + + + + + + The low 28 bits
      part1 + + +number + + + + + + + + The middle 28 bits
      part2 + + +number + + + + + + + + The high 28 (8) bits
      unsigned + + +boolean + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to false (signed).
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromBits(lowBits, highBits, unsigned) → {Long}

      + + +
      +
      + + +
      + Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is + assumed to use 32 bits. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      lowBits + + +number + + + + + + + + The low 32 bits.
      highBits + + +number + + + + + + + + The high 32 bits.
      unsigned + + +boolean + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to false (signed).
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The corresponding Long value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromInt(value, unsigned) → {Long}

      + + +
      +
      + + +
      + Returns a Long representing the given (32-bit) integer value. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + + The 32-bit integer in question.
      unsigned + + +boolean + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to false (signed).
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The corresponding Long value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromNumber(value, unsigned) → {Long}

      + + +
      +
      + + +
      + Returns a Long representing the given value, provided that it is a finite +number. Otherwise, zero is returned. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      value + + +number + + + + + + + + The number in question.
      unsigned + + +boolean + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to false (signed).
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The corresponding Long value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      <static> fromString(str, unsigned, radix) → {Long}

      + + +
      +
      + + +
      + Returns a Long representation of the given string, written using the given +radix. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      str + + +string + + + + + + + + The textual representation of the Long.
      unsigned + + +boolean +| + +number + + + + + + <optional>
      + + + +
      Whether unsigned or not. Defaults to false (signed).
      radix + + +number + + + + + + <optional>
      + + + +
      The radix in which the text is written.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The corresponding Long value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      add(other) → {Long}

      + + +
      +
      + + +
      + Returns the sum of this and the given Long. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to add to this one.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The sum of this and the given Long. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      and(other) → {Long}

      + + +
      +
      + + +
      + Returns the bitwise-AND of this Long and the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + The Long with which to AND.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The bitwise-AND of this and the other. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      clone() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Cloned instance with the same low/high bits and unsigned flag. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      compare(other) → {number}

      + + +
      +
      + + +
      + Compares this Long with the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + 0 if they are the same, 1 if the this is greater, and -1 + if the given one is greater. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      div(other) → {Long}

      + + +
      +
      + + +
      + Returns this Long divided by the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long by which to divide.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + This Long divided by the given one. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      equals(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long equals the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      getHighBits() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The high 32 bits as a signed value. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getHighBitsUnsigned() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The high 32 bits as an unsigned value. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getLowBits() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The low 32 bits as a signed value. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getLowBitsUnsigned() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The low 32 bits as an unsigned value. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      getNumBitsAbs() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Returns the number of bits needed to represent the absolute + value of this Long. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      greaterThan(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long is greater than the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      greaterThanOrEqual(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long is greater than or equal to the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isEven() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this value is even. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isNegative() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this value is negative. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isOdd() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this value is odd. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      isZero() → {boolean}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this value is zero. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      lessThan(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long is less than the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      lessThanOrEqual(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long is less than or equal to the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      modulo(other) → {Long}

      + + +
      +
      + + +
      + Returns this Long modulo the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long by which to mod.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + This Long modulo the given one. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      multiply(other) → {Long}

      + + +
      +
      + + +
      + Returns the product of this and the given long. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to multiply with this.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The product of this and the other. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      negate() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The negation of this value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      not() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The bitwise-NOT of this value. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      notEquals(other) → {boolean}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to compare against.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Whether this Long does not equal the other. +
      + + + +
      +
      + Type +
      +
      + +boolean + + +
      +
      + + + + +
      + + + +
      +

      or(other) → {Long}

      + + +
      +
      + + +
      + Returns the bitwise-OR of this Long and the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + The Long with which to OR.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The bitwise-OR of this and the other. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftLeft(numBits) → {Long}

      + + +
      +
      + + +
      + Returns this Long with bits shifted to the left by the given amount. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + + The number of bits by which to shift.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + This shifted to the left by the given amount. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftRight(numBits) → {Long}

      + + +
      +
      + + +
      + Returns this Long with bits shifted to the right by the given amount. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + + The number of bits by which to shift.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + This shifted to the right by the given amount. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      shiftRightUnsigned(numBits) → {Long}

      + + +
      +
      + + +
      + Returns this Long with bits shifted to the right by the given amount, with +the new top bits matching the current sign bit. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      numBits + + +number + + + + The number of bits by which to shift.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + This shifted to the right by the given amount, with + zeros placed into the new leading bits. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      subtract(other) → {Long}

      + + +
      +
      + + +
      + Returns the difference of this and the given Long. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + Long to subtract from this.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The difference of this and the given Long. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      toInt() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The value, assuming it is a 32-bit integer. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      toNumber() → {number}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The closest floating-point representation to this value. +
      + + + +
      +
      + Type +
      +
      + +number + + +
      +
      + + + + +
      + + + +
      +

      toSigned() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Signed long +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      toString(radix) → {string}

      + + +
      +
      + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeArgumentDescription
      radix + + +number + + + + + + <optional>
      + + + +
      The radix in which the text should be written.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The textual representation of this value. +
      + + + +
      +
      + Type +
      +
      + +string + + +
      +
      + + + + +
      + + + +
      +

      toUnsigned() → {Long}

      + + +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + Unsigned long +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + + + +
      +

      xor(other) → {Long}

      + + +
      +
      + + +
      + Returns the bitwise-XOR of this Long and the given one. +
      + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      other + + +Long + + + + The Long with which to XOR.
      + + + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + +
      Returns:
      + + +
      + The bitwise-XOR of this and the other. +
      + + + +
      +
      + Type +
      +
      + +Long + + +
      +
      + + + + +
      + +
      + + + + + +
      + +
      + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/index.html b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/index.html new file mode 100644 index 0000000..49ca749 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/index.html @@ -0,0 +1,60 @@ + + + + + Index + + + + + + + + + + +
      + +

      Index

      + + + + + + + +

      + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + + diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js new file mode 100644 index 0000000..953ab25 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/html5.js @@ -0,0 +1,9 @@ +/* + HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv +*/ +(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); +a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; +c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| +"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); +for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p?H2?rYR{#J&=n4P;F&8?!uthoT)~;-svgOJa$a^0sn^3kl zvO65X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)*MNUS{<(3a=2DXL7Gq_6rgAdSl%f_1PHov7Y$uqw1v~mWScR zYw;3x=IBg5E=)RW*r&L_{qmd$9QS#(38ElOQ!-hk8Krmcy-DV>FH&O7dTP6V11(I6 zk5Cih=QlTpusl0N>PWTnNsJL4^x+f+7A!aA~F7doZ9lSZ~(SjB%TDOYvvGU4;EfMY;Z=WCbb6EO)l+G?_wpOZG`+24O z2=RNb$uD#qu!?<$$bAxGOa|VdgQuqpp|waoLub#%W*oxDCuG}Uc`L(m&D$qLtlZ+@ zJQBKLP3-zZZky}qrj^(c9i61ofB#D68#`#Wy`54QDCs(Nj7s@ADp3m+N^P86J8Bpz z-1Q-JJhS;$NTKRhhxb|3J})A%PQt!w?3Zvg8>3uUQiPiKpO=IEn7pn0=#UG7kNGJo zm)yJ-p?Ah`NzY=B-`Oc%_Tw=dP(xaXxfgMhV6kke4Cs`bd>e*>ctKMx0m8m9IV67 ziRI^C+$VW7zp&@@jD)b)1>A>qB9`oVd8y&E9uU5i&MvjsE8bnj*)sce5)~m{e?3|l zIOdQ8%h^6hQnfK^u641#vE8PLU((7JDZ4`1W$Fr9Nrt+Pm2y$Z zcvpS?b@l%1>atJA!ak{t^i}xlq_kX$V(*^Xdk^X~1KR zI9Sxt0SMi>3r|MeAt9{STg2~_aFv%>d3{*Wa`FBewn79#2OxBSB#h;95BoB<=0.6" + }, + "scripts": { + "make": "npm run-script compile && npm test && npm run-script jsdoc", + "compile": "ccjs Long.js --compilation_level=ADVANCED_OPTIMIZATIONS > Long.min.js", + "test": "node node_modules/testjs/bin/testjs tests/suite.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png)\n=======\nA Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/)\nfor stand-alone use and extended with unsigned support.\n\nWhy?\n----\nAs of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value\nof 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit\nnumbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations\non the full 64bits. This is where Long.js comes into play.\n\nFeatures\n--------\n* [CommonJS](http://www.commonjs.org/) compatible\n* [RequireJS](http://requirejs.org/)/AMD compatible\n* Shim compatible (include the script, then use var Long = dcodeIO.Long;)\n* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/long)\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\n* API-compatible to the Closure Library implementation\n* Zero production dependencies\n* Small footprint\n\nUsage\n-----\n\n#### node.js / CommonJS ####\n\nInstall: `npm install long`\n\n```javascript\nvar Long = require(\"long\");\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nconsole.log(longVal.toString());\n...\n```\n\n#### RequireJS / AMD ####\n\n````javascript\nrequire.config({\n \"paths\": {\n \"Math/Long\": \"/path/to/Long.js\"\n }\n});\nrequire([\"Math/Long\"], function(Long) {\n var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\n console.log(longVal.toString());\n});\n````\n\n### Browser / shim ####\n\n```html\n\n```\n\n```javascript\nvar Long = dcodeIO.Long;\nvar longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);\nalert(longVal.toString());\n```\n\nDocumentation\n-------------\n* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html)\n\nDownloads\n---------\n* [ZIP-Archive](https://github.com/dcodeIO/Long.js/archive/master.zip)\n* [Tarball](https://github.com/dcodeIO/Long.js/tarball/master)\n\nLicense\n-------\nApache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/dcodeIO/Long.js/issues" + }, + "_id": "long@1.1.2", + "dist": { + "shasum": "5ad87eb1ddaa6b1c89f80b3e7bf620b5f34160dc" + }, + "_from": "long@latest", + "_resolved": "https://registry.npmjs.org/long/-/long-1.1.2.tgz" +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/tests/suite.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/tests/suite.js new file mode 100644 index 0000000..e71a512 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/tests/suite.js @@ -0,0 +1,156 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS-IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * Long.js Pretty Simple Test Suite. + */ +var Long = require(__dirname+"/../Long.min.js"); + +var suite = { + + "basic": function(test) { + var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); + test.equal(longVal.toNumber(), 9223372036854775807); + test.equal(longVal.toString(), "9223372036854775807"); + test.done(); + }, + + // Let's assume signed goog.math.Long works as expected because the people at Google are pretty smart. + + // So let's focus on my probably not-so-smart extensions: + + "from28Bits": function(test) { + var val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF); + test.equal(val.toString(), "-1"); + test.done(); + }, + + "unsigned": { + + "min/max": function(test) { + test.equal(Long.MIN_SIGNED_VALUE.toString(), "-9223372036854775808"); + test.equal(Long.MAX_SIGNED_VALUE.toString(), "9223372036854775807"); + test.equal(Long.MIN_UNSIGNED_VALUE.toString(), "0"); + test.equal(Long.MAX_UNSIGNED_VALUE.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_negint": function(test) { + var longVal = Long.fromInt(-1, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_highlow": function(test) { + var longVal = new Long(0xFFFFFFFF, 0xFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "construct_number": function(test) { + var longVal = Long.fromNumber(0xFFFFFFFFFFFFFFFF, true); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "toSigned/Unsigned": function(test) { + var longVal = Long.fromNumber(-1, false); + test.equal(longVal.toNumber(), -1); + longVal = longVal.toUnsigned(); + test.equal(longVal.toNumber(), 0xFFFFFFFFFFFFFFFF); + longVal = longVal.toSigned(); + test.equal(longVal.toNumber(), -1); + test.done(); + }, + + "max_unsigned_sub_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_SIGNED_VALUE).subtract(Long.ONE); + test.equal(longVal.toNumber(), Long.MAX_SIGNED_VALUE); + test.equal(longVal.toString(), Long.MAX_SIGNED_VALUE.toString()); + test.done(); + }, + + "max_sub_max": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_UNSIGNED_VALUE); + test.equal(longVal, 0); + test.equal(longVal.low, 0); + test.equal(longVal.high, 0); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 0); + test.equal(longVal.toString(), "0"); + test.done(); + }, + + "zero_sub_signed": function(test) { + var longVal = Long.fromInt(0, true).add(Long.fromInt(-1, false)); + test.equal(longVal.low, -1); + test.equal(longVal.high, -1); + test.equal(longVal.unsigned, true); + test.equal(longVal.toNumber(), 18446744073709551615); + test.equal(longVal.toString(), "18446744073709551615"); + test.done(); + }, + + "max_unsigned_div_max_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.MAX_SIGNED_VALUE); + test.equal(longVal.toNumber(), 2); + test.equal(longVal.toString(), "2"); + test.done(); + }, + + "max_unsigned_div_neg_signed": function(test) { + var longVal = Long.MAX_UNSIGNED_VALUE.div(Long.fromInt(-2)); + test.equal(longVal.toNumber(), -Long.MAX_SIGNED_VALUE); + test.done(); + } + }, + + // FIXME: There is no support for NaN or +/-Infinity + // "NaN": function(test) { + // test.ok(isNan(Long.fromNumber(NaN).toNumber()); + // test.strictEqual(Long.fromNumber(+Infinity).toNumber(), +Infinity); + // test.strictEqual(Long.fromNumber(-Infinity).toNumber(), -Infinity); + // test.done(); + // } + // One option could be to store NaN, Infinity etc. in high and set low to 0, while making sure to convert it in a + // proper way as soon as any math is called upon it. This might be as simple as that each of these values always + // "infects" other values, thus remaining untouched respectively changing the base long to its value. + // + // To clarify that, it all becomes zero atm, which usually is good enough but not perfect: + "NaN": function(test) { + test.strictEqual(Long.fromNumber(NaN), Long.ZERO); + test.strictEqual(Long.fromNumber(+Infinity), Long.ZERO); + test.strictEqual(Long.fromNumber(-Infinity), Long.ZERO); + test.strictEqual(Long.fromString(NaN+""), Long.ZERO); + test.strictEqual(Long.fromString(+Infinity+""), Long.ZERO); + test.strictEqual(Long.fromString(-Infinity+""), Long.ZERO); + test.done(); + } +}; + +module.exports = suite; diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/package.json b/javascript/node_modules/protobufjs/node_modules/bytebuffer/package.json new file mode 100644 index 0000000..3b7a0cb --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/package.json @@ -0,0 +1,57 @@ +{ + "name": "bytebuffer", + "version": "2.3.1", + "author": { + "name": "Daniel Wirtz", + "email": "dcode@dcode.io" + }, + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "repository": { + "type": "git", + "url": "https://github.com/dcodeIO/ByteBuffer.js.git" + }, + "bugs": { + "url": "https://github.com/dcodeIO/ByteBuffer.js/issues" + }, + "keywords": [ + "net", + "array", + "buffer", + "arraybuffer", + "typed array", + "bytebuffer", + "json", + "websocket", + "webrtc" + ], + "dependencies": { + "long": "latest" + }, + "devDependencies": { + "testjs": "latest", + "preprocessor": "latest", + "closurecompiler": "latest" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=0.8" + }, + "scripts": { + "prepublish": "npm test", + "test": "node node_modules/testjs/bin/testjs tests/suite.js", + "make": "npm run-script build && npm run-script compile && npm run-script noexpose && npm test && npm run-script jsdoc", + "build": "node build.js", + "compile": "ccjs ByteBuffer.js --create_source_map=ByteBuffer.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --externs=externs/Long.js > ByteBuffer.min.js", + "noexpose": "cat ByteBuffer.js | grep -v @expose > ByteBuffer.noexpose.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![ByteBuffer.js - A full-featured ByteBuffer implementation in JavaScript](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png)\r\n======================================\r\nProvides a full-featured ByteBuffer implementation using typed arrays. It's one of the core components driving\r\n[ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js) and the [PSON](https://github.com/dcodeIO/PSON) reference\r\nimplementation.\r\n\r\n*Note:* The API behind #toHex and #toString has changed with ByteBuffer 2, which is a generally revised release, in\r\nfavor of making this more intuitive.\r\n\r\nWhat can it do?\r\n---------------\r\n* Mimics Java ByteBuffers as close as reasonable while using typed array terms\r\n* Signed and unsigned integers (8, 16, 32, 64 bit through [Long.js](https://github.com/dcodeIO/Long.js)) with endianness support\r\n* 32 and 64 bit floats\r\n* Varints as known from protobuf including zig-zag encoding\r\n* Includes an UTF8 and Base64 en-/decoder\r\n* C-strings, V(arint-prefixed)-strings and UTF8 L(ength-prefixed)-strings \r\n* Rich string toolset (to hex, base64, binary, utf8, debug, columns)\r\n* Relative and absolute zero-copy operations\r\n* Manual and automatic resizing (efficiently doubles capacity)\r\n* Chaining of all operations that do not return a specific value\r\n* Slicing, appending, prepending, reversing, flip, mark, reset, etc.\r\n\r\nAnd much more...\r\n\r\nFeatures\r\n--------\r\n* [CommonJS](http://www.commonjs.org/) compatible\r\n* [RequireJS](http://requirejs.org/)/AMD compatible\r\n* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/bytebuffer)\r\n* Browser compatible\r\n* [Closure Compiler](https://developers.google.com/closure/compiler/) ADVANCED_OPTIMIZATIONS compatible (fully annotated,\r\n `ByteBuffer.min.js` has been compiled this way, `ByteBuffer.min.map` is the source map)\r\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\r\n* Well tested through [nodeunit](https://github.com/caolan/nodeunit)\r\n* Zero production dependencies (Long.js is optional)\r\n* Small footprint\r\n\r\nUsage\r\n-----\r\n### Node.js / CommonJS ###\r\n* Install: `npm install bytebuffer`\r\n\r\n```javascript\r\nvar ByteBuffer = require(\"bytebuffer\");\r\nvar bb = new ByteBuffer();\r\nbb.writeLString(\"Hello world!\").flip();\r\nconsole.log(bb.readLString()+\" from ByteBuffer.js\");\r\n```\r\n\r\n### Browser ###\r\n\r\nOptionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long\r\nsupport, you can skip the Long.js include.\r\n\r\n```html\r\n\r\n\r\n```\r\n\r\n```javascript\r\nvar ByteBuffer = dcodeIO.ByteBuffer;\r\nvar bb = new ByteBuffer();\r\nbb.writeLString(\"Hello world!\").flip();\r\nalert(bb.readLString()+\" from ByteBuffer.js\");\r\n```\r\n\r\n### Require.js / AMD ###\r\n\r\nOptionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long\r\nsupport, you can skip the Long.js config. [Require.js](http://requirejs.org/) example:\r\n\r\n```javascript\r\nrequire.config({\r\n \"paths\": {\r\n \"Long\": \"/path/to/Long.js\"\r\n \"ByteBuffer\": \"/path/to/ByteBuffer.js\"\r\n }\r\n});\r\nrequire([\"ByteBuffer\"], function(ByteBuffer) {\r\n var bb = new ByteBuffer();\r\n bb.writeLString(\"Hello world!\");\r\n bb.flip();\r\n alert(bb.readLString()+\" from ByteBuffer.js\");\r\n});\r\n```\r\n\r\nOn long (int64) support\r\n-----------------------\r\nAs of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value\r\nof 2^53. Beyond that, behaviour might be unexpected. However, real long support requires the full 64 bits\r\nwith the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support\r\nin ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two\r\n32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth.\r\nOn node, long support is available by default through the [long](https://npmjs.org/package/long) dependency.\r\n\r\nDownloads\r\n---------\r\n* [ZIP-Archive](https://github.com/dcodeIO/ByteBuffer.js/archive/master.zip)\r\n* [Tarball](https://github.com/dcodeIO/ByteBuffer.js/tarball/master)\r\n\r\nDocumentation\r\n-------------\r\n* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/ByteBuffer.js/master/docs/ByteBuffer.html)\r\n\r\nTests (& Examples) [![Build Status](https://travis-ci.org/dcodeIO/ByteBuffer.js.png?branch=master)](https://travis-ci.org/dcodeIO/ByteBuffer.js)\r\n------------------\r\n* [View source](https://github.com/dcodeIO/ByteBuffer.js/blob/master/tests/suite.js)\r\n* [View report](https://travis-ci.org/dcodeIO/ByteBuffer.js)\r\n\r\nSupport for IE<10, FF<15, Chrome<9 etc.\r\n---------------------------------------\r\n* Requires working ArrayBuffer & DataView implementations (i.e. use a [polyfill](https://github.com/inexorabletash/polyfill#typed-arrays-polyfill))\r\n\r\nContributors\r\n------------\r\n[Dretch](https://github.com/Dretch) (IE8 compatibility)\r\n\r\nLicense\r\n-------\r\nApache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html\r\n", + "readmeFilename": "README.md", + "_id": "bytebuffer@2.3.1", + "dist": { + "shasum": "16a281a8cfd6c76d6ceb869b32e2cd6abdbe3836" + }, + "_from": "bytebuffer@>=2.2 <3", + "_resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-2.3.1.tgz" +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/ByteBuffer.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/ByteBuffer.js new file mode 100644 index 0000000..cba25b6 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/ByteBuffer.js @@ -0,0 +1,2320 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ByteBuffer.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ByteBuffer.js for details + */ // +(function(global) { + "use strict"; + + // Note that this library carefully avoids using the array access operator + // (i.e. buffer[x]) on ArrayBufferView subclasses (e.g. Uint8Array), and + // uses DataView instead. This is required for IE 8 compatibility. + + /** + * @param {Function=} Long + * @returns {Function} + * @inner + */ + function loadByteBuffer(Long) { + + // Support node's Buffer if available, see http://nodejs.org/api/buffer.html + var Buffer = null; + if (typeof require === 'function') { + try { + var nodeBuffer = require("buffer"); + Buffer = nodeBuffer && typeof nodeBuffer['Buffer'] === 'function' && + typeof nodeBuffer['Buffer']['isBuffer'] === 'function' ? nodeBuffer['Buffer'] : null; + } catch (e) {} + } + + /** + * Constructs a new ByteBuffer. + * @class A full-featured ByteBuffer implementation in JavaScript using typed arrays. + * @exports ByteBuffer + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @param {boolean=} sparse If set to `true`, a ByteBuffer with array=view=null will be created which have to be + * set manually afterwards. Defaults to `false`. + * @expose + */ + var ByteBuffer = function(capacity, littleEndian, sparse) { + capacity = typeof capacity !== 'undefined' ? parseInt(capacity, 10) : ByteBuffer.DEFAULT_CAPACITY; + if (capacity < 1) capacity = ByteBuffer.DEFAULT_CAPACITY; + + /** + * Backing ArrayBuffer. + * @type {?ArrayBuffer} + * @expose + */ + this.array = sparse ? null : new ArrayBuffer(capacity); + + /** + * DataView to mess with the ArrayBuffer. + * @type {?DataView} + * @expose + */ + this.view = sparse ? null : new DataView(this.array); + + /** + * Current read/write offset. Length- and capacity-independent index. Contents are the bytes between offset + * and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.offset = 0; + + /** + * Marked offset set through {@link ByteBuffer#mark}. Defaults to `-1` (no marked offset). + * @type {number} + * @expose + */ + this.markedOffset = -1; + + /** + * Length of the contained data. Offset- and capacity-independent index. Contents are the bytes between + * offset and length, which are both absolute indexes. There is no capacity property, use + * {@link ByteBuffer#capacity} instead. + * @type {number} + * @expose + */ + this.length = 0; + + /** + * Whether to use little endian multi byte values, defaults to `false` for big endian. + * @type {boolean} + * @expose + */ + this.littleEndian = typeof littleEndian != 'undefined' ? !!littleEndian : false; + }; + + /** + * Version string. + * @type {string} + * @const + * @expose + */ + ByteBuffer.VERSION = // #put '"'+VERSION+'";' + + /** + * Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required. + * @type {number} + * @const + * @expose + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Little endian constant for usage in constructors instead of a boolean value. Evaluates to `true`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant for usage in constructors instead of a boolean value. Evaluates to `false`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is + * not available. + * @type {?Long} + * @const + * @expose + */ + ByteBuffer.Long = Long || null; + + /** + * Tests if the specified type is a ByteBuffer or ByteBuffer-like. + * @param {*} bb ByteBuffer to test + * @returns {boolean} true if it is a ByteBuffer or ByteBuffer-like, otherwise false + * @expose + */ + ByteBuffer.isByteBuffer = function(bb) { + return bb && ( + (bb instanceof ByteBuffer) || ( + typeof bb === 'object' && + (bb.array === null || bb.array instanceof ArrayBuffer) && + (bb.view === null || bb.view instanceof DataView) && + typeof bb.offset === 'number' && + typeof bb.markedOffset === 'number' && + typeof bb.length === 'number' && + typeof bb.littleEndian === 'boolean' + ) + ); + }; + + /** + * Allocates a new ByteBuffer. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @expose + */ + ByteBuffer.allocate = function(capacity, littleEndian) { + return new ByteBuffer(capacity, littleEndian); + }; + + /** + * Converts a node.js <= 0.8 Buffer to an ArrayBuffer. + * @param {!Buffer} b Buffer to convert + * @returns {?ArrayBuffer} Converted buffer + * @inner + */ + function b2ab(b) { + var ab = new ArrayBuffer(b.length), + view = new Uint8Array(ab); + for (var i=0, k=b.length; i < k; ++i) view[i] = b[i]; + return ab; + } + + /** + * Wraps an ArrayBuffer, any object containing an ArrayBuffer, a node buffer or a string. Sets the created + * ByteBuffer's offset to 0 and its length to the wrapped object's byte length. + * @param {!ArrayBuffer|!Buffer|!{array: !ArrayBuffer}|!{buffer: !ArrayBuffer}|string} buffer Anything that can + * be wrapped + * @param {(string|boolean)=} enc String encoding if a string is provided (hex, utf8, binary, defaults to base64) + * @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big + * endian. + * @returns {!ByteBuffer} + * @throws {Error} If the specified object cannot be wrapped + * @expose + */ + ByteBuffer.wrap = function(buffer, enc, littleEndian) { + if (typeof enc === 'boolean') { + littleEndian = enc; + enc = "utf8"; + } + // Wrap a string + if (typeof buffer === 'string') { + switch (enc) { + case "base64": + return ByteBuffer.decode64(buffer, littleEndian); + case "hex": + return ByteBuffer.decodeHex(buffer, littleEndian); + case "binary": + return ByteBuffer.decodeBinary(buffer, littleEndian); + default: + return new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, littleEndian).writeUTF8String(buffer).flip(); + } + } + var b; + // Wrap Buffer + if (Buffer && Buffer.isBuffer(buffer)) { + b = new Uint8Array(buffer).buffer; // noop on node <= 0.8 + buffer = (b === buffer) ? b2ab(buffer) : b; + } + // Refuse to wrap anything that's null or not an object + if (buffer === null || typeof buffer !== 'object') { + throw(new Error("Cannot wrap null or non-object")); + } + // Wrap ByteBuffer by cloning (preserve offsets) + if (ByteBuffer.isByteBuffer(buffer)) { + return ByteBuffer.prototype.clone.call(buffer); // Also makes ByteBuffer-like a ByteBuffer + } + // Wrap any object that is or contains an ArrayBuffer + if (!!buffer["array"]) { + buffer = buffer["array"]; + } else if (!!buffer["buffer"]) { + buffer = buffer["buffer"]; + } + if (!(buffer instanceof ArrayBuffer)) { + throw(new Error("Cannot wrap buffer of type "+typeof(buffer)+", "+buffer.constructor.name)); + } + b = new ByteBuffer(0, littleEndian, true); + b.array = buffer; + b.view = b.array.byteLength > 0 ? new DataView(b.array) : null; + b.offset = 0; + b.length = buffer.byteLength; + return b; + }; + + /** + * Switches little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + + /** + * Resizes the ByteBuffer to the given capacity. Will do nothing if already that large or larger. + * @param {number} capacity New capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.resize = function(capacity) { + if (capacity < 1) return false; + if (this.array === null) { // Silently recreate + this.array = new ArrayBuffer(capacity); + this.view = new DataView(this.array); + } + if (this.array.byteLength < capacity) { + var src = this.array; + var srcView = new Uint8Array(src); + var dst = new ArrayBuffer(capacity); + var dstView = new Uint8Array(dst); + dstView.set(srcView); + this.array = dst; + this.view = new DataView(dst); + } + return this; + }; + + /** + * Slices the ByteBuffer. This is independent of the ByteBuffer's actual offsets. Does not compact the underlying + * ArrayBuffer (use {@link ByteBuffer#compact} or {@link ByteBuffer.wrap} instead). + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#length}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same ArrayBuffer + * @throws {Error} If the buffer cannot be sliced + * @expose + */ + ByteBuffer.prototype.slice = function(begin, end) { + if (this.array == null) { + throw(new Error(this+" cannot be sliced: Already destroyed")); + } + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.length; + if (end <= begin) { + var t = end; end = begin; begin = t; + } + if (begin < 0 || begin > this.array.byteLength || end < 1 || end > this.array.byteLength) { + throw(new Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+begin+"-"+end+")")); + } + var b = this.clone(); + b.offset = begin; + b.length = end; + return b; + }; + + /** + * Makes sure that the specified capacity is available. If the current capacity is exceeded, it will be doubled. + * If double the previous capacity is less than the required capacity, the required capacity will be used. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.ensureCapacity = function(capacity) { + if (this.array === null) + return this.resize(capacity); + if (this.array.byteLength < capacity) + return this.resize(this.array.byteLength*2 >= capacity ? this.array.byteLength*2 : capacity); + return this; + }; + + /** + * Makes the buffer ready for a new sequence of write or relative read operations. Sets `length=offset` and + * `offset=0`. Always make sure to flip a buffer when all relative writing operations are complete. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.flip = function() { + this.length = this.array == null ? 0 : this.offset; + this.offset = 0; + return this; + }; + + /** + * Marks an offset to be used with {@link ByteBuffer#reset}. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the mark cannot be set + * @see ByteBuffer#reset + * @expose + */ + ByteBuffer.prototype.mark = function(offset) { + if (this.array == null) { + throw(new Error(this+" cannot be marked: Already destroyed")); + } + offset = typeof offset !== 'undefined' ? parseInt(offset, 10) : this.offset; + if (offset < 0 || offset > this.array.byteLength) { + throw(new Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+offset)); + } + this.markedOffset = offset; + return this; + }; + + /** + * Resets the ByteBuffer. If an offset has been marked through {@link ByteBuffer#mark} before, the offset will + * be set to the marked offset and the marked offset will be discarded. Length will not be altered. If there is + * no marked offset, sets `offset=0` and `length=0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + * @expose + */ + ByteBuffer.prototype.reset = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reset: Already destroyed")); + } + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + this.length = 0; + } + return this; + }; + + /** + * Clones this ByteBuffer. The returned cloned ByteBuffer shares the same backing array but will have its own + * offsets. + * @returns {!ByteBuffer} Clone + * @expose + */ + ByteBuffer.prototype.clone = function() { + var b = new ByteBuffer(-1, this.littleEndian, /* no init, undocumented */ true); + b.array = this.array; + b.view = this.view; + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Copies this ByteBuffer. The copy has its own backing array and uses the same offsets as this one. + * @returns {!ByteBuffer} Copy + * @expose + */ + ByteBuffer.prototype.copy = function() { + if (this.array == null) { + return this.clone(); + } + var b = new ByteBuffer(this.array.byteLength, this.littleEndian); + var src = new Uint8Array(this.array); + var dst = new Uint8Array(b.array); + dst.set(src); + b.offset = this.offset; + b.markedOffset = this.markedOffset; + b.length = this.length; + return b; + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between offset and length, so this + * returns `length-offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset>length`. + * @expose + */ + ByteBuffer.prototype.remaining = function() { + if (this.array === null) return 0; + return this.length - this.offset; + }; + + /** + * Gets the capacity of the backing buffer. This is independent from {@link ByteBuffer#length} and returns the + * size of the entire backing array. + * @returns {number} Capacity of the backing array or 0 if destroyed + * @expose + */ + ByteBuffer.prototype.capacity = function() { + return this.array != null ? this.array.byteLength : 0; + }; + + /** + * Compacts the ByteBuffer to be backed by an ArrayBuffer of its actual length. Will set `offset=0` and + * `length=capacity`. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer cannot be compacted + * @expose + */ + ByteBuffer.prototype.compact = function() { + if (this.array == null) { + throw(new Error(this+" cannot be compacted: Already destroyed")); + } + if (this.offset > this.length) { + this.flip(); + } + if (this.offset === this.length) { + this.array = new ArrayBuffer(0); + this.view = null; // A DataView on a zero-length AB would throw + return this; + } + if (this.offset === 0 && this.length === this.array.byteLength) { + return this; // Already compacted + } + var srcView = new Uint8Array(this.array); + var dst = new ArrayBuffer(this.length-this.offset); + var dstView = new Uint8Array(dst); + dstView.set(srcView.subarray(this.offset, this.length)); + this.array = dst; + if (this.markedOffset >= this.offset) { + this.markedOffset -= this.offset; + } else { + this.markedOffset = -1; + } + this.offset = 0; + this.length = this.array.byteLength; + return this; + }; + + /** + * Manually destroys the ByteBuffer, releasing references to the backing array. Manually destroying a ByteBuffer + * is usually not required but may be useful in limited memory environments. Most successive operations will + * rise an error until {@link ByteBuffer#resize} or {@link ByteBuffer#ensureCapacity} is called to reinitialize + * the backing array. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.destroy = function() { + if (this.array !== null) { + this.array = null; + this.view = null; + this.offset = 0; + this.markedOffset = -1; + this.length = 0; + } + return this; + }; + + /** + * Reverses the backing array and adapts offset and length to retain the same relative position on the reversed + * data in inverse order. Example: "00<01 02>03 04".reverse() = "04 03<02 01>00". Also clears the marked + * offset. + * @returns {!ByteBuffer} this + * @throws {Error} If the buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.reverse = function() { + if (this.array === null) { + throw(new Error(this+" cannot be reversed: Already destroyed")); + } + Array.prototype.reverse.call(new Uint8Array(this.array)); + var o = this.offset; + this.offset = this.array.byteLength - this.length; + this.markedOffset = -1; + this.length = this.array.byteLength - o; + this.view = new DataView(this.array); + return this; + }; + + /** + * Appends another ByteBuffer to this one. Appends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents behind the specified offset up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to append + * @param {number=} offset Offset to append at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.append = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(new Error(src+" cannot be appended to "+this+": Already destroyed")); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to append + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + offset = typeof offset !== 'undefined' ? offset : (this.offset+=n)-n; + this.ensureCapacity(offset+n); // Reinitializes if required + var srcView = new Uint8Array(src.array); + var dstView = new Uint8Array(this.array); + dstView.set(srcView.subarray(src.offset, src.length), offset); + return this; + }; + + /** + * Prepends another ByteBuffer to this one. Prepends only the portion between offset and length of the specified + * ByteBuffer and overwrites any contents before the specified offsets up to the number of bytes contained in + * the specified ByteBuffer. Offset and length of the specified ByteBuffer will remain the same. + * @param {!*} src ByteBuffer or any object that can be wrapped to prepend + * @param {number=} offset Offset to prepend at. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {Error} If the specified buffer is already destroyed + * @expose + */ + ByteBuffer.prototype.prepend = function(src, offset) { + if (!(src instanceof ByteBuffer)) { + src = ByteBuffer.wrap(src); + } + if (src.array === null) { + throw(src+" cannot be prepended to "+this+": Already destroyed"); + } + var n = src.length - src.offset; + if (n == 0) return this; // Nothing to prepend + if (n < 0) { + src = src.clone().flip(); + n = src.length - src.offset; + } + var modify = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var diff = n-offset; + if (diff > 0) { + // Doesn't fit, so maybe resize and move the contents that are already contained + this.ensureCapacity(this.length+diff); + this.append(this, n); + this.offset += diff; + this.length += diff; + this.append(src, 0); + } else { + this.append(src, offset-n); + } + if (modify) { + this.offset -= n; + } + return this; + }; + + /** + * Writes an 8bit signed integer. + * @param {number} value Value + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if + * omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt8 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setInt8(offset, value); + return this; + }; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset >= this.array.byteLength) { + throw(new Error("Cannot read int8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt8(offset); + }; + + /** + * Writes a byte. This is an alias of {ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeByte = ByteBuffer.prototype.writeInt8; + + /** + * Reads a byte. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readByte = ByteBuffer.prototype.readInt8; + + /** + * Writes an 8bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint8 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + this.ensureCapacity(offset+1); + this.view.setUint8(offset, value); + return this; + }; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint8 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=1)-1; + if (offset+1 > this.array.byteLength) { + throw(new Error("Cannot read uint8 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint8(offset); + }; + + /** + * Writes a 16bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setInt16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt16(offset, this.littleEndian); + }; + + /** + * Writes a short value. This is an alias of {@link ByteBuffer#writeInt16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeShort = ByteBuffer.prototype.writeInt16; + + /** + * Reads a short value. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readShort = ByteBuffer.prototype.readInt16; + + /** + * Writes a 16bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint16 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + this.ensureCapacity(offset+2); + this.view.setUint16(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint16 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=2)-2; + if (offset+2 > this.array.byteLength) { + throw(new Error("Cannot read int16 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint16(offset, this.littleEndian); + }; + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setInt32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read int32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getInt32(offset, this.littleEndian); + }; + + /** + * Writes an integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt = ByteBuffer.prototype.writeInt32; + + /** + * Reads an integer. This is an alias of {@link ByteBuffer#readInt32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt = ByteBuffer.prototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint32 = function(value, offset) { + offset = typeof offset != 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setUint32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (offset+4 > this.array.byteLength) { + throw(new Error("Cannot read uint32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getUint32(offset, this.littleEndian); + }; + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat32 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + this.ensureCapacity(offset+4); + this.view.setFloat32(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat32 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=4)-4; + if (this.array === null || offset+4 > this.array.byteLength) { + throw(new Error("Cannot read float32 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat32(offset, this.littleEndian); + }; + + /** + * Writes a float. This is an alias of {@link ByteBuffer#writeFloat32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat = ByteBuffer.prototype.writeFloat32; + + /** + * Reads a float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat = ByteBuffer.prototype.readFloat32; + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeFloat64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + this.ensureCapacity(offset+8); + this.view.setFloat64(offset, value, this.littleEndian); + return this; + }; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readFloat64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + throw(new Error("Cannot read float64 from "+this+" at "+offset+": Capacity overflow")); + } + return this.view.getFloat64(offset, this.littleEndian); + }; + + /** + * Writes a double. This is an alias of {@link ByteBuffer#writeFloat64}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeDouble = ByteBuffer.prototype.writeFloat64; + + /** + * Reads a double. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readDouble = ByteBuffer.prototype.readFloat64; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeInt64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setInt32(offset, value.getLowBits(), true); + this.view.setInt32(offset+4, value.getHighBits(), true); + } else { + this.view.setInt32(offset, value.getHighBits(), false); + this.view.setInt32(offset+4, value.getLowBits(), false); + } + return this; + }; + + /** + * Reads a 64bit integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readInt64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getInt32(offset, true), this.view.getInt32(offset+4, true), false); + } else { + value = Long.fromBits(this.view.getInt32(offset+4, false), this.view.getInt32(offset, false), false); + } + return value; + }; + + /** + * Writes a 64bit unsigned integer. Requires Long.js. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeUint64 = function(value, offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, true); + this.ensureCapacity(offset+8); + if (this.littleEndian) { + this.view.setUint32(offset, value.getLowBitsUnsigned(), true); + this.view.setUint32(offset+4, value.getHighBitsUnsigned(), true); + } else { + this.view.setUint32(offset, value.getHighBitsUnsigned(), false); + this.view.setUint32(offset+4, value.getLowBitsUnsigned(), false); + } + return this; + }; + + /** + * Reads a 64bit unsigned integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readUint64 = function(offset) { + offset = typeof offset !== 'undefined' ? offset : (this.offset+=8)-8; + if (this.array === null || offset+8 > this.array.byteLength) { + this.offset -= 8; + throw(new Error("Cannot read int64 from "+this+" at "+offset+": Capacity overflow")); + } + var value; + if (this.littleEndian) { + value = Long.fromBits(this.view.getUint32(offset, true), this.view.getUint32(offset+4, true), true); + } else { + value = Long.fromBits(this.view.getUint32(offset+4, false), this.view.getUint32(offset, false), true); + } + return value; + }; + + /** + * Writes a long. This is an alias of {@link ByteBuffer#writeInt64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBuffer.prototype.writeLong = ByteBuffer.prototype.writeInt64; + + /** + * Reads a long. This is an alias of {@link ByteBuffer#readInt64}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long} + * @throws {Error} If offset is out of bounds + * @expose + */ + ByteBuffer.prototype.readLong = ByteBuffer.prototype.readInt64; + + } + + /** + * Maximum number of bytes used by 32bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Writes a 32bit base 128 variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint32 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + this.ensureCapacity(offset+ByteBuffer.calculateVarint32(value)); + var dst = this.view, + size = 0; + dst.setUint8(offset, value | 0x80); + if (value >= (1 << 7)) { + dst.setUint8(offset+1, (value >> 7) | 0x80); + if (value >= (1 << 14)) { + dst.setUint8(offset+2, (value >> 14) | 0x80); + if (value >= (1 << 21)) { + dst.setUint8(offset+3, (value >> 21) | 0x80); + if (value >= (1 << 28)) { + dst.setUint8(offset+4, (value >> 28) & 0x7F); + size = 5; + } else { + dst.setUint8(offset+3, dst.getUint8(offset+3) & 0x7F); + size = 4; + } + } else { + dst.setUint8(offset+2, dst.getUint8(offset+2) & 0x7F); + size = 3; + } + } else { + dst.setUint8(offset+1, dst.getUint8(offset+1) & 0x7F); + size = 2; + } + } else { + dst.setUint8(offset, dst.getUint8(offset) & 0x7F); + size = 1; + } + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint32 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var count = 0, b, + src = this.view; + var value = 0 >>> 0; + do { + b = src.getUint8(offset+count); + if (count < ByteBuffer.MAX_VARINT32_BYTES) { + value |= ((b&0x7F)<<(7*count)) >>> 0; + } + ++count; + } while (b & 0x80); + value = value | 0; // Make sure to discard the higher order bits + if (advance) { + this.offset += count; + return value; + } else { + return { + "value": value, + "length": count + }; + } + }; + + /** + * Writes a zigzag encoded 32bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint32 = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read + * and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint32 = function(offset) { + var dec = this.readVarint32(offset); + if (typeof dec === 'object') { + dec['value'] = ByteBuffer.zigZagDecode32(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode32(dec); + }; + + /** + * Maximum number of bytes used by a 64bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_7_DBL = 1 << 7; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL; + + // Available with Long.js only + if (Long) { + + /** + * Writes a 64bit base 128 variable-length integer as used in protobuf. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint64 = function(value, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0, + size = ByteBuffer.calculateVarint64(value); + + this.ensureCapacity(offset+size); + var dst = this.view; + switch (size) { + case 10: dst.setUint8(offset+9, (part2 >>> 7) | 0x80); + case 9 : dst.setUint8(offset+8, (part2 ) | 0x80); + case 8 : dst.setUint8(offset+7, (part1 >>> 21) | 0x80); + case 7 : dst.setUint8(offset+6, (part1 >>> 14) | 0x80); + case 6 : dst.setUint8(offset+5, (part1 >>> 7) | 0x80); + case 5 : dst.setUint8(offset+4, (part1 ) | 0x80); + case 4 : dst.setUint8(offset+3, (part0 >>> 21) | 0x80); + case 3 : dst.setUint8(offset+2, (part0 >>> 14) | 0x80); + case 2 : dst.setUint8(offset+1, (part0 >>> 7) | 0x80); + case 1 : dst.setUint8(offset+0, (part0 ) | 0x80); + } + dst.setUint8(offset+size-1, dst.getUint8(offset+size-1) & 0x7F); + if (advance) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Reads a 32bit base 128 variable-length integer as used in protobuf. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and + * the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readVarint64 = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + // ref: src/google/protobuf/io/coded_stream.cc + + var src = this.view, + part0, part1 = 0, part2 = 0, b; + b = src.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) { + b = src.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) { + b = src.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) { + b = src.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) { + throw(new Error("Data must be corrupt: Buffer overrun")); }}}}}}}}}} + + var value = Long.from28Bits(part0, part1, part2, false); + if (advance) { + this.offset = offset; + return value; + } else { + return { + "value": value, + "length": offset-start + }; + } + }; + + /** + * Writes a zigzag encoded 64bit base 128 encoded variable-length integer as used in protobuf. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint64 = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf. + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint64 = function(offset) { + var dec = this.readVarint64(offset); + if (typeof dec === 'object' && !(dec instanceof Long)) { + dec['value'] = ByteBuffer.zigZagDecode64(dec['value']); + return dec; + } + return ByteBuffer.zigZagDecode64(dec); + }; + + } + + /** + * Writes a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeVarint = ByteBuffer.prototype.writeVarint32; + + /** + * Reads a base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @expose + */ + ByteBuffer.prototype.readVarint = ByteBuffer.prototype.readVarint32; + + /** + * Writes a zigzag encoded base 128 encoded variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#writeZigZagVarint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeZigZagVarint = ByteBuffer.prototype.writeZigZagVarint32; + + /** + * Reads a zigzag encoded base 128 variable-length integer as used in protobuf. This is an alias of {@link ByteBuffer#readZigZagVarint32}. + * @function + * @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted. + * @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read. + * @throws {Error} If it's not a valid varint + * @expose + */ + ByteBuffer.prototype.readZigZagVarint = ByteBuffer.prototype.readZigZagVarint32; + + /** + * Calculates the actual number of bytes required to encode a 32bit base 128 variable-length integer. + * @param {number} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} + * @expose + */ + ByteBuffer.calculateVarint32 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + value = value >>> 0; + if (value < TWO_PWR_7_DBL) { + return 1; + } else if (value < TWO_PWR_14_DBL) { + return 2; + } else if (value < TWO_PWR_21_DBL) { + return 3; + } else if (value < TWO_PWR_28_DBL) { + return 4; + } else { + return 5; + } + }; + + // Available with Long.js only + if (Long) { + + /** + * Calculates the actual number of bytes required to encode a 64bit base 128 variable-length integer. + * @param {number|!Long} value Value to encode + * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} + * @expose + */ + ByteBuffer.calculateVarint64 = function(value) { + // ref: src/google/protobuf/io/coded_stream.cc + if (!(typeof value === 'object' && value instanceof Long)) value = Long.fromNumber(value, false); + + var part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + + if (part2 == 0) { + if (part1 == 0) { + if (part0 < TWO_PWR_14_DBL) { + return part0 < TWO_PWR_7_DBL ? 1 : 2; + } else { + return part0 < TWO_PWR_21_DBL ? 3 : 4; + } + } else { + if (part1 < TWO_PWR_14_DBL) { + return part1 < TWO_PWR_7_DBL ? 5 : 6; + } else { + return part1 < TWO_PWR_21_DBL ? 7 : 8; + } + } + } else { + return part2 < TWO_PWR_7_DBL ? 9 : 10; + } + }; + + } + + /** + * Encodes a signed 32bit integer so that it can be effectively used with varint encoding. + * @param {number} n Signed 32bit integer + * @returns {number} Unsigned zigzag encoded 32bit integer + * @expose + */ + ByteBuffer.zigZagEncode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; + }; + + /** + * Decodes a zigzag encoded signed 32bit integer. + * @param {number} n Unsigned zigzag encoded 32bit integer + * @returns {number} Signed 32bit integer + * @expose + */ + ByteBuffer.zigZagDecode32 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + return ((n >>> 1) ^ -(n & 1)) | 0; + }; + + // Available with Long.js only + if (Long) { + + /** + * Encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} n Signed long + * @returns {!Long} Unsigned zigzag encoded long + * @expose + */ + ByteBuffer.zigZagEncode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (n.unsigned) n = n.toSigned(); + } else { + n = Long.fromNumber(n, false); + } + return n.shiftLeft(1).xor(n.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} n Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @throws {Error} If long support is not available + * @expose + */ + ByteBuffer.zigZagDecode64 = function(n) { + // ref: src/google/protobuf/wire_format_lite.h + if (typeof n === 'object' && n instanceof Long) { + if (!n.unsigned) n = n.toUnsigned(); + } else { + n = Long.fromNumber(n, true); + } + return n.shiftRightUnsigned(1).xor(n.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + } + + /** + * Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {!ByteBuffer} src + * @param {number} offset Offset to read from + * @returns {!{char: number, length: number}} Decoded char code and the actual number of bytes read + * @throws {Error} If the character cannot be decoded or there is a capacity overflow + * @expose + */ + ByteBuffer.decodeUTF8Char = function(src, offset) { + var a = src.readUint8(offset), b, c, d, e, f, start = offset, charCode; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if ((a&0x80)==0) { + charCode = a; + offset += 1; + } else if ((a&0xE0)==0xC0) { + b = src.readUint8(offset+1); + charCode = ((a&0x1F)<<6) | (b&0x3F); + offset += 2; + } else if ((a&0xF0)==0xE0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + charCode = ((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F); + offset += 3; + } else if ((a&0xF8)==0xF0) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + charCode = ((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F); + offset += 4; + } else if ((a&0xFC)==0xF8) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + charCode = ((a&0x03)<<24) | ((b&0x3F)<<18) | ((c&0x3F)<<12) | ((d&0x3F)<<6) | (e&0x3F); + offset += 5; + } else if ((a&0xFE)==0xFC) { + b = src.readUint8(offset+1); + c = src.readUint8(offset+2); + d = src.readUint8(offset+3); + e = src.readUint8(offset+4); + f = src.readUint8(offset+5); + charCode = ((a&0x01)<<30) | ((b&0x3F)<<24) | ((c&0x3F)<<18) | ((d&0x3F)<<12) | ((e&0x3F)<<6) | (f&0x3F); + offset += 6; + } else { + throw(new Error("Cannot decode UTF8 character at offset "+offset+": charCode (0x"+a.toString(16)+") is invalid")); + } + return { + "char": charCode , + "length": offset-start + }; + }; + + /** + * Encodes a single UTF8 character to the specified ByteBuffer. The ByteBuffer's offsets are not modified. + * @param {number} charCode Character to encode as char code + * @param {!ByteBuffer} dst ByteBuffer to encode to + * @param {number} offset Offset to write to + * @returns {number} Actual number of bytes written + * @throws {Error} If the character cannot be encoded + * @expose + */ + ByteBuffer.encodeUTF8Char = function(charCode, dst, offset) { + var start = offset; + // ref: http://en.wikipedia.org/wiki/UTF-8#Description + // It's quite huge but should be pretty fast. + if (charCode < 0) { + throw(new Error("Cannot encode UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + dst.writeUint8(charCode&0x7F, offset); + offset += 1; + } else if (charCode < 0x800) { + dst.writeUint8(((charCode>>6)&0x1F)|0xC0, offset) + .writeUint8((charCode&0x3F)|0x80, offset+1); + offset += 2; + } else if (charCode < 0x10000) { + dst.writeUint8(((charCode>>12)&0x0F)|0xE0, offset) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+1) + .writeUint8((charCode&0x3F)|0x80, offset+2); + offset += 3; + } else if (charCode < 0x200000) { + dst.writeUint8(((charCode>>18)&0x07)|0xF0, offset) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+2) + .writeUint8((charCode&0x3F)|0x80, offset+3); + offset += 4; + } else if (charCode < 0x4000000) { + dst.writeUint8(((charCode>>24)&0x03)|0xF8, offset) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+3) + .writeUint8((charCode&0x3F)|0x80, offset+4); + offset += 5; + } else if (charCode < 0x80000000) { + dst.writeUint8(((charCode>>30)&0x01)|0xFC, offset) + .writeUint8(((charCode>>24)&0x3F)|0x80, offset+1) + .writeUint8(((charCode>>18)&0x3F)|0x80, offset+2) + .writeUint8(((charCode>>12)&0x3F)|0x80, offset+3) + .writeUint8(((charCode>>6)&0x3F)|0x80, offset+4) + .writeUint8((charCode&0x3F)|0x80, offset+5); + offset += 6; + } else { + throw(new Error("Cannot encode UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + return offset-start; + }; + + /** + * Calculates the actual number of bytes required to encode the specified char code. + * @param {number} charCode Character to encode as char code + * @returns {number} Number of bytes required to encode the specified char code + * @throws {Error} If the character cannot be calculated (too large) + * @expose + */ + ByteBuffer.calculateUTF8Char = function(charCode) { + if (charCode < 0) { + throw(new Error("Cannot calculate length of UTF8 character: charCode ("+charCode+") is negative")); + } + if (charCode < 0x80) { + return 1; + } else if (charCode < 0x800) { + return 2; + } else if (charCode < 0x10000) { + return 3; + } else if (charCode < 0x200000) { + return 4; + } else if (charCode < 0x4000000) { + return 5; + } else if (charCode < 0x80000000) { + return 6; + } else { + throw(new Error("Cannot calculate length of UTF8 character: charCode (0x"+charCode.toString(16)+") is too large (>= 0x80000000)")); + } + }; + + /** + * Calculates the number of bytes required to store an UTF8 encoded string. + * @param {string} str String to calculate + * @returns {number} Number of bytes required + */ + ByteBuffer.calculateUTF8String = function(str) { + str = ""+str; + var bytes = 0; + for (var i=0, k=str.length; i i ? bb.readUint8(i++) : 0; + o3 = bb.length > i ? bb.readUint8(i++) : 0; + bits = o1 << 16 | o2 << 8 | o3; + h1 = bits >> 18 & 0x3f; + h2 = bits >> 12 & 0x3f; + h3 = bits >> 6 & 0x3f; + h4 = bits & 0x3f; + out[oi++] = B64.charAt(h1) + B64.charAt(h2) + B64.charAt(h3) + B64.charAt(h4); + } while (i < bb.length); + var enc = out.join(''), + r = (bb.length - bb.offset) % 3; + return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str Base64 encoded string + * @param {boolean=} littleEndian `true` to use little endian byte order, defaults to `false` for big endian. + * @returns {!ByteBuffer} ByteBuffer + * @throws {Error} If the argument is not a valid base64 encoded string + * @expose + */ + ByteBuffer.decode64 = function(str, littleEndian) { + // ref: http://phpjs.org/functions/base64_decode/ + if (typeof str !== 'string') { + throw(new Error("Illegal argument: Not a string")); + } + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, + out = new ByteBuffer(Math.ceil(str.length / 3), littleEndian); + do { + h1 = B64.indexOf(str.charAt(i++)); + h2 = B64.indexOf(str.charAt(i++)); + h3 = B64.indexOf(str.charAt(i++)); + h4 = B64.indexOf(str.charAt(i++)); + if (h1 < 0 || h2 < 0 || h3 < 0 || h4 < 0) { + throw(new Error("Illegal argument: Not a valid base64 encoded string")); + } + bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; + o1 = bits >> 16 & 0xff; + o2 = bits >> 8 & 0xff; + o3 = bits & 0xff; + if (h3 == 64) { + out.writeUint8(o1); + } else if (h4 == 64) { + out.writeUint8(o1) + .writeUint8(o2); + } else { + out.writeUint8(o1) + .writeUint8(o2) + .writeUint8(o3); + } + } while (i < str.length); + return out.flip(); + }; + + /** + * Encodes a ByteBuffer to a hex encoded string. + * @param {!ByteBuffer} bb ByteBuffer to encode. Will be cloned and flipped if length < offset. + * @returns {string} Hex encoded string + * @throws {Error} If the argument is not a valid ByteBuffer + * @expose + */ + ByteBuffer.encodeHex = function(bb) { + if (!(bb instanceof ByteBuffer)) { + bb = ByteBuffer.wrap(bb); + } else if (bb.length < bb.offset) { + bb = bb.clone().flip(); + } + if (bb.array === null) return ""; + var val, out = []; + for (var i=bb.offset, k=bb.length; i 255) throw(new Error("Illegal argument: Not a binary string (char code "+val+")")); + view.setUint8(i, val); + } + var bb = new ByteBuffer(k, littleEndian, true); + bb.array = dst; + bb.view = view; + bb.length = k; + return bb; + }; + + /** + * Writes an UTF8 string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeUTF8String = function(str, offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var start = offset; + var encLen = ByteBuffer.calculateUTF8String(str); // See [1] + this.ensureCapacity(offset+encLen); + for (var i=0, j=str.length; ilength ? "+" : "")+offset-length)+" bytes")); + } + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + } + } + }; + + /** + * Writes a string with prepended number of characters, which is also encoded as an UTF8 character.. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBuffer.prototype.writeLString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = ByteBuffer.encodeUTF8Char(str.length, this, offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with a prepended number of characters, which is also encoded as an UTF8 character. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|{string: string, length: number}} The string read if offset is omitted, else the string read + * and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readLString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = ByteBuffer.decodeUTF8Char(this, offset), + dec = this.readUTF8String(lenDec["char"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeVString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeVarint32(ByteBuffer.calculateUTF8String(str), offset); + encLen += this.writeUTF8String(str, offset+encLen); + if (advance) { + this.offset += encLen; + return this; + } else { + return encLen; + } + }; + + /** + * Reads a string with prepended number of characters, which is encoded as a 32bit base 128 variable-length + * integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded or if it is not preceeded by a valid varint + * @expose + */ + ByteBuffer.prototype.readVString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var lenDec = this.readVarint32(offset); + var dec = this.readUTF8StringBytes(lenDec["value"], offset+lenDec["length"]); + if (advance) { + this.offset += lenDec["length"]+dec["length"]; + return dec["string"]; + } else { + return { + "string": dec["string"], + "length": lenDec["length"]+dec["length"] + }; + } + }; + + /** + * Writes a string followed by a NULL character (Uint8). Beware: The source string must not contain NULL + * characters unless this is actually intended. This is not checked. If you have the option it is recommended + * to use {@link ByteBuffer#writeLString} or {@link ByteBuffer#writeVString} with the corresponding reading + * methods instead. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBuffer.prototype.writeCString = function(str, offset) { + str = ""+str; + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var encLen = this.writeUTF8String(str, offset); + this.writeUint8(0, offset+encLen); + if (advance) { + this.offset += encLen+1; + return this; + } else { + return encLen+1; + } + }; + + /** + * Reads a string followed by a NULL character (Uint8). + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string + * read and the actual number of bytes read. + * @throws {Error} If the string cannot be decoded + * @expose + */ + ByteBuffer.prototype.readCString = function(offset) { + var advance = typeof offset === 'undefined'; + offset = typeof offset !== 'undefined' ? offset : this.offset; + var dec, result = "", start = offset; + do { + dec = ByteBuffer.decodeUTF8Char(this, offset); + offset += dec["length"]; + if (dec["char"] != 0) result += String.fromCharCode(dec["char"]); + } while (dec["char"] != 0); + if (advance) { + this.offset = offset; + return result; + } else { + return { + "string": result, + "length": offset-start + }; + } + }; + + /** + * Serializes and writes a JSON payload. + * @param {*} data Data payload to serialize + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(*)=} stringify Stringify implementation to use. Defaults to {@link JSON.stringify}. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number if bytes written + * @expose + */ + ByteBuffer.prototype.writeJSON = function(data, offset, stringify) { + stringify = typeof stringify === 'function' ? stringify : JSON.stringify; + return this.writeLString(stringify(data), offset); + }; + + /** + * Reads a JSON payload and unserializes it. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted. + * @param {function(string)=} parse Parse implementation to use. Defaults to {@link JSON.parse}. + * @returns {!*|!{data: *, length: number}} Data payload if offset is omitted, else the data payload and the + * actual number of bytes read + * @throws {Error} If the data cannot be decoded + * @expose + */ + ByteBuffer.prototype.readJSON = function(offset, parse) { + parse = typeof parse === 'function' ? parse : JSON.parse; + var result = this.readLString(offset); + if (typeof result === 'string') { + return parse(result); + } else { + return { + "data": parse(result["string"]), + "length": result["length"] + }; + } + }; + + /** + * Returns a textual two columns (hex, ascii) representation of this ByteBuffer's backing array. + * @param {number=} wrap Wrap length. Defaults to 16. + * @returns {string} Hex representation as of " 00<01 02>03... ASCII DATA" with marked offsets + * @expose + */ + ByteBuffer.prototype.toColumns = function(wrap) { + if (this.array === null) return "DESTROYED"; + wrap = typeof wrap !== 'undefined' ? parseInt(wrap, 10) : 16; + if (wrap < 1) wrap = 16; + + // Left colum: hex with offsets + var out = "", + lines = [], + val, + view = this.view; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (var i=0, k=this.array.byteLength; i0 && i%wrap == 0) { + while (out.length < 3*wrap+1) out += " "; // Make it equal to maybe show something on the right + lines.push(out); + out = " "; + } + val = view.getUint8(i).toString(16).toUpperCase(); + if (val.length < 2) val = "0"+val; + out += val; + if (i+1 == this.offset && i+1 == this.length) { + out += "|"; + } else if (i+1 == this.offset) { + out += "<"; + } else if (i+1 == this.length) { + out += ">"; + } else { + out += " "; + } + } + if (out != " ") { + lines.push(out); + } + // Make it equal + for (i=0, k=lines.length; i0 && i%wrap == 0) { + lines[n] += " "+out; + out = ""; n++; + } + val = view.getUint8(i); + out += val > 32 && val < 127 ? String.fromCharCode(val) : "."; + } + if (out != "") { + lines[n] += " "+out; + } + return lines.join("\n"); + }; + + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + * @expose + */ + ByteBuffer.prototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + (this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toColumns()+"\n" + ); + }; + + /** + * Returns the ByteBuffer's contents between offset and length as a hex string. + * @param {boolean=} debug `true` to return the entire backing array with marked offsets, defaults to `false` + * @returns {string} Hex string or debug string + * @expose + */ + ByteBuffer.prototype.toHex = function(debug) { + var out = "", + val, + view = this.view, + i, k; + if (!debug) { + return ByteBuffer.encodeHex(this); + } else { + if (this.array === null) return "DESTROYED"; + if (this.offset == 0 && this.length == 0) { + out += "|"; + } else if (this.length == 0) { + out += ">"; + } else if (this.offset == 0) { + out += "<"; + } else { + out += " "; + } + for (i=0, k=this.array.byteLength; i= this.length) return ""; + return ByteBuffer.encode64(this); + }; + + /** + * Returns the ByteBuffer's contents as an UTF8 encoded string. + * @returns {string} + * @expose + */ + ByteBuffer.prototype.toUTF8 = function() { + if (this.array === null || this.offset >= this.length) return ""; + return this.readUTF8StringBytes(this.length - this.offset, this.offset)["string"]; + }; + + /** + * Converts the ByteBuffer to a string. + * @param {string=} enc Output encoding. Returns an informative string representation by default but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * marked offsets. + * @returns {string} String representation + * @expose + */ + ByteBuffer.prototype.toString = function(enc) { + enc = enc || ""; + switch (enc) { + case "utf8": + return this.toUTF8(); + case "base64": + return this.toBase64(); + case "hex": + return this.toHex(); + case "binary": + return this.toBinary(); + case "debug": + return this.toHex(true); + default: + if (this.array === null) { + return "ByteBuffer(DESTROYED)"; + } + return "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"; + } + }; + + /** + * Returns an ArrayBuffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will return a reference to + * the unmodified backing buffer if offset=0 and length=capacity unless forceCopy is set to true. + * @param {boolean=} forceCopy `true` forces the creation of a copy, defaults to `false` + * @returns {?ArrayBuffer} Compacted ArrayBuffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toArrayBuffer = function(forceCopy) { + if (this.array === null) return null; + var b = this.clone(); + if (b.offset > b.length) { + b.flip(); + } + var copied = false; + if (b.offset > 0 || b.length < b.array.byteLength) { + b.compact(); // Will always create a new backing buffer because of the above condition + copied = true; + } + return forceCopy && !copied ? b.copy().array : b.array; + }; + + // Available with node.js only + if (Buffer) { + + /** + * Returns a node Buffer compacted to contain this ByteBuffer's actual contents. Will transparently + * {@link ByteBuffer#flip} the ByteBuffer if its offset is larger than its length. Will also copy all data (not + * a reference). + * @returns {?Buffer} Compacted node Buffer or null if already destroyed + * @expose + */ + ByteBuffer.prototype.toBuffer = function() { + if (this.array === null) return null; + var offset = this.offset, length = this.length; + if (offset > length) { + var temp = offset; + offset = length; + length = temp; + } + return new Buffer(new Uint8Array(this.array).subarray(offset, length)); + }; + + } + + return ByteBuffer; + } + + // Enable module loading if available + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadByteBuffer(require("long")); + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD + define("ByteBuffer", ["Math/Long"], function(Long) { return loadByteBuffer(Long); }); + } else { // Shim + if (!global["dcodeIO"]) global["dcodeIO"] = {}; + global["dcodeIO"]["ByteBuffer"] = loadByteBuffer(global["dcodeIO"]["Long"]); + } + +})(this); diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/bower.json b/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/bower.json new file mode 100644 index 0000000..ed384f1 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/src/bower.json @@ -0,0 +1,12 @@ +{ + "name": "bytebuffer", + "version": // #put '"'+VERSION+'",' + "author": "Daniel Wirtz ", + "description": "A full-featured ByteBuffer implementation using typed arrays.", + "main": "ByteBuffer.js", + "keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"], + "dependencies": { + "long": "latest" + }, + "license": "Apache-2.0" +} diff --git a/javascript/node_modules/protobufjs/node_modules/bytebuffer/tests/suite.js b/javascript/node_modules/protobufjs/node_modules/bytebuffer/tests/suite.js new file mode 100644 index 0000000..36c4ec9 --- /dev/null +++ b/javascript/node_modules/protobufjs/node_modules/bytebuffer/tests/suite.js @@ -0,0 +1,929 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ByteBuffer.js Test Suite. + * @author Daniel Wirtz + */ + +/** + * File to use. + * @type {string} + */ +var FILE = "ByteBuffer.min.js"; + +/** + * ByteBuffer. + * @type {ByteBuffer} + */ +var ByteBuffer = require(__dirname+"/../"+FILE); + +/** + * Long. + * @type {Long} + */ +var Long = ByteBuffer.Long; + +/** + * Constructs a new Sandbox for module loaders and shim testing. + * @param {Object.} properties Additional properties to set + * @constructor + */ +var Sandbox = function(properties) { + this.Int8Array = function() {}; + this.Uint8Array = function() {}; + this.Int16Array = function() {}; + this.Uint16Array = function() {}; + this.Int32Array = function() {}; + this.Uint32Array = function() {}; + this.Float32Array = function() {}; + this.Float64Array = function() {}; + for (var i in properties) { + this[i] = properties[i]; + } + this.console = { + log: function(s) { + console.log(s); + } + }; +}; + +/** + * Test suite. + * @type {Object.} + */ +var suite = { + + "init": function(test) { + test.ok(typeof ByteBuffer == "function"); + test.ok(typeof ByteBuffer.encodeUTF8Char == "function"); + test.done(); + }, + + "construct/allocate": function(test) { + var bb = new ByteBuffer(); + test.equal(bb.array.byteLength, ByteBuffer.DEFAULT_CAPACITY); + bb = ByteBuffer.allocate(); + test.equal(bb.array.byteLength, ByteBuffer.DEFAULT_CAPACITY); + test.done(); + }, + + "wrap(ArrayBuffer)": function(test) { + var buf = new ArrayBuffer(1); + var bb = ByteBuffer.wrap(buf); + test.strictEqual(bb.array, buf); + test.equal(bb.offset, 0); + test.equal(bb.length, 1); + test.done(); + }, + + "wrap(Uint8Array)": function(test) { + var buf = new Uint8Array(1); + var bb = ByteBuffer.wrap(buf); + test.strictEqual(bb.array, buf.buffer); + test.done(); + }, + + "wrap(ByteBuffer)": function(test) { // clones + var bb2 = new ByteBuffer(4).writeInt32(0x12345678).flip(); + bb2.offset = 1; + var bb = ByteBuffer.wrap(bb2); + test.strictEqual(bb2.toString("debug"), bb.toString("debug")); + test.done(); + }, + + "wrap(String)": function(test) { + var bb = ByteBuffer.wrap("test"); + test.equal(bb.offset, 0); + test.equal(bb.length, 4); + test.equal(bb.readUTF8String(4), "test"); + + bb = ByteBuffer.wrap("6162", "hex"); + test.equal(bb.toHex(true), "<61 62>"); + + bb = ByteBuffer.wrap("YWI=", "base64"); + test.equal(bb.toHex(true), "<61 62>"); + + test.done(); + }, + + "wrap(Buffer)": function(test) { + var b = new Buffer("abc", "utf8"); + var bb = ByteBuffer.wrap(b); + test.equal(bb.toString("debug"), "<61 62 63>"); + test.done(); + }, + + "resize": function(test) { + var bb = new ByteBuffer(1); + bb.resize(2); + test.equal(bb.array.byteLength, 2); + test.equal(bb.toString("debug"), "|00 00 "); + test.done(); + }, + + "slice": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint8(0x12).writeUint8(0x34).writeUint8(0x56); + var bb2 = bb.slice(1,2); + test.strictEqual(bb.array, bb2.array); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + test.equal(bb2.offset, 1); + test.equal(bb2.length, 2); + test.done(); + }, + + "ensureCapacity": function(test) { + var bb = new ByteBuffer(5); + test.equal(bb.array.byteLength, 5); + bb.ensureCapacity(6); + test.equal(bb.array.byteLength, 10); + bb.ensureCapacity(21); + test.equal(bb.array.byteLength, 21); + test.done(); + }, + + "flip": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + test.equal(bb.offset, 4); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.offset, 0); + test.equal(bb.length, 4); + test.done(); + }, + + "reset": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.reset(); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.done(); + }, + + "mark": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint16(0x1234); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.mark(); + test.equal(bb.markedOffset, 2); + bb.writeUint16(0x5678); + test.equal(bb.offset, 4); + test.equal(bb.markedOffset, 2); + bb.reset(); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.reset(); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.equal(bb.markedOffset, -1); + bb.mark(2); + test.equal(bb.markedOffset, 2); + test.done(); + }, + + "clone": function(test) { + var bb = new ByteBuffer(1); + var bb2 = bb.clone(); + test.strictEqual(bb.array, bb2.array); + test.equal(bb.offset, bb2.offset); + test.equal(bb.length, bb2.length); + test.notStrictEqual(bb, bb2); + test.done(); + }, + + "copy": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0x12); + var bb2 = bb.copy(); + test.notStrictEqual(bb, bb2); + test.notStrictEqual(bb.array, bb2.array); + test.equal(bb2.offset, bb.offset); + test.equal(bb2.length, bb.length); + test.done(); + }, + + "compact": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint8(0x12); + var prevArray = bb.array; + bb.compact(); + test.notStrictEqual(bb.array, prevArray); + test.equal(bb.array.byteLength, 1); + test.equal(bb.offset, 0); + test.equal(bb.length, 1); + test.done(); + }, + + "compactEmpty": function(test) { + var bb = new ByteBuffer(2); + bb.compact(); + test.strictEqual(bb.offset, 0); + test.strictEqual(bb.length, 0); + test.strictEqual(bb.view, null); // Special case + test.strictEqual(bb.array.byteLength, 0); + bb.writeInt32(0xFFFFFFFF); + bb.flip(); + test.strictEqual(bb.offset, 0); + test.strictEqual(bb.length, 4); + test.notStrictEqual(bb.view, null); + test.strictEqual(bb.array.byteLength, 4); // Cannot double 0, so it takes 32bits + test.done(); + }, + + "destroy": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0x12); + bb.destroy(); + test.strictEqual(bb.array, null); + test.equal(bb.offset, 0); + test.equal(bb.length, 0); + test.equal(bb.toString("debug"), "DESTROYED"); + test.done(); + }, + + "reverse": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.flip(); + bb.reverse(); + test.equal(bb.toString("debug"), "<78 56 34 12>"); + test.done(); + }, + + "append": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0x1234); + var bb2 = new ByteBuffer(2); + bb2.writeUint16(0x5678); + bb2.flip(); + bb.append(bb2); + test.equal(bb.toString("debug"), ">12 34 56 78<"); + bb.append(bb2, 1); + test.equal(bb.toString("debug"), ">12 56 78 78<"); + test.done(); + }, + + "prepend": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0x1234); + bb.flip(); + var bb2 = new ByteBuffer(2); + bb2.writeUint16(0x5678); + bb2.flip(); + bb.prepend(bb2); + test.equal(bb.toString("debug"), "<56 78 12 34>"); + bb.offset = 4; + bb.prepend(bb2, 3); + test.equal(bb.toString("debug"), " 56 56 78 34|") + test.done(); + }, + + "write/readInt8": function(test) { + var bb = new ByteBuffer(1); + bb.writeInt8(0xFF); + bb.flip(); + test.equal(-1, bb.readInt8()); + test.done(); + }, + + "write/readByte": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt8, bb.readByte); + test.strictEqual(bb.writeInt8, bb.writeByte); + test.done(); + }, + + "write/readUint8": function(test) { + var bb = new ByteBuffer(1); + bb.writeUint8(0xFF); + bb.flip(); + test.equal(0xFF, bb.readUint8()); + test.done(); + }, + + "write/readInt16": function(test) { + var bb = new ByteBuffer(2); + bb.writeInt16(0xFFFF); + bb.flip(); + test.equal(-1, bb.readInt16()); + test.done(); + }, + + "write/readShort": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt16, bb.readShort); + test.strictEqual(bb.writeInt16, bb.writeShort); + test.done(); + }, + + "write/readUint16": function(test) { + var bb = new ByteBuffer(2); + bb.writeUint16(0xFFFF); + bb.flip(); + test.equal(0xFFFF, bb.readUint16()); + test.done(); + }, + + "write/readInt32": function(test) { + var bb = new ByteBuffer(4); + bb.writeInt32(0xFFFFFFFF); + bb.flip(); + test.equal(-1, bb.readInt32()); + test.done(); + }, + + "write/readInt": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt32, bb.readInt); + test.strictEqual(bb.writeInt32, bb.writeInt); + test.done(); + }, + + "write/readUint32": function(test) { + var bb = new ByteBuffer(4); + bb.writeUint32(0x12345678); + bb.flip(); + test.equal(0x12345678, bb.readUint32()); + test.done(); + }, + + "write/readFloat32": function(test) { + var bb = new ByteBuffer(4); + bb.writeFloat32(0.5); + bb.flip(); + test.equal(0.5, bb.readFloat32()); // 0.5 remains 0.5 if Float32 + test.done(); + }, + + "write/readFloat": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readFloat32, bb.readFloat); + test.strictEqual(bb.writeFloat32, bb.writeFloat); + test.done(); + }, + + "write/readFloat64": function(test) { + var bb = new ByteBuffer(8); + bb.writeFloat64(0.1); + bb.flip(); + test.equal(0.1, bb.readFloat64()); // would be 0.10000000149011612 if Float32 + test.done(); + }, + + "write/readDouble": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readFloat64, bb.readDouble); + test.strictEqual(bb.writeFloat64, bb.writeDouble); + test.done(); + }, + + "write/readInt64": function(test) { + var bb = new ByteBuffer(8); + + var max = ByteBuffer.Long.MAX_SIGNED_VALUE.toNumber(); + bb.writeInt64(max).flip(); + test.equal(bb.toString("debug"), "<7F FF FF FF FF FF FF FF>"); + test.equal(bb.readInt64(0), max); + + var min = ByteBuffer.Long.MIN_SIGNED_VALUE.toNumber(); + bb.writeInt64(min).flip(); + test.equal(bb.toString("debug"), "<80 00 00 00 00 00 00 00>"); + test.equal(bb.readInt64(0), min); + + bb.writeInt64(-1).flip(); + test.equal(bb.toString("debug"), ""); + test.equal(bb.readInt64(0), -1); + + bb.reset(); + bb.LE().writeInt64(new ByteBuffer.Long(0x89ABCDEF, 0x01234567)).flip(); + test.equal(bb.toString("debug"), ""); + + test.done(); + }, + + "write/readUint64": function(test) { + var bb = new ByteBuffer(8); + + var max = ByteBuffer.Long.MAX_UNSIGNED_VALUE.toNumber(); + bb.writeUint64(max).flip(); + test.equal(bb.toString("debug"), ""); + test.equal(bb.readUint64(0), max); + + var min = ByteBuffer.Long.MIN_UNSIGNED_VALUE.toNumber(); + bb.writeLong(min).flip(); + test.equal(bb.toString("debug"), "<00 00 00 00 00 00 00 00>"); + test.equal(bb.readUint64(0), min); + + bb.writeUint64(-1).flip(); + test.equal(bb.toString("debug"), "<00 00 00 00 00 00 00 00>"); + test.equal(bb.readUint64(0), 0); + + bb.reset(); + bb.LE().writeUint64(new ByteBuffer.Long(0x89ABCDEF, 0x01234567, true)).flip(); + test.equal(bb.toString("debug"), ""); + + test.done(); + }, + + "write/readLong": function(test) { + var bb = new ByteBuffer(1); + test.strictEqual(bb.readInt64, bb.readLong); + test.strictEqual(bb.writeInt64, bb.writeLong); + test.done(); + }, + + "writeVarint64/readVarint32": function(test) { + var bb = new ByteBuffer(); + bb.writeVarint64(Long.fromNumber(-1)); + bb.flip(); + var n = bb.readVarint32(); + test.equal(n, -1); + test.done(); + }, + + "LE/BE": function(test) { + var bb = new ByteBuffer(8).LE().writeInt(1).BE().writeInt(2).flip(); + test.equal(bb.toString("debug"), "<01 00 00 00 00 00 00 02>"); + test.done(); + }, + + "calculateVarint32/64": function(test) { + test.equal(ByteBuffer.MAX_VARINT32_BYTES, 5); + test.equal(ByteBuffer.MAX_VARINT64_BYTES, 10); + var values = [ + [0, 1], + [-1, 5, 10], + [1<<7, 2], + [1<<14, 3], + [1<<21, 4], + [1<<28, 5], + [0x7FFFFFFF | 0, 5], + [0xFFFFFFFF, 5], + [0xFFFFFFFF | 0, 5, 10] + ]; + for (var i=0; i 2 ? values[i][2] : values[i][1]); + } + var Long = ByteBuffer.Long; + values = [ + [Long.fromNumber(1).shiftLeft(35), 6], + [Long.fromNumber(1).shiftLeft(42), 7], + [Long.fromNumber(1).shiftLeft(49), 8], + [Long.fromNumber(1).shiftLeft(56), 9], + [Long.fromNumber(1).shiftLeft(63), 10], + [Long.fromNumber(1, true).shiftLeft(63), 10] + ]; + for (i=0; i 1 ? values[i][1] : values[i][0]).toString(), dec['value'].toString()); + test.equal(encLen, dec['length']); + } + test.done(); + }, + + "write/readZigZagVarint32": function(test) { + var values = [ + 0, + 1, + 300, + -300, + 2147483647, + -2147483648 + ]; + var bb = new ByteBuffer(10); + for (var i=0; i00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readLString(0)); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.equal("ab", bb.readLString()); + test.equal(bb.toString("debug"), " 02 61 62|00 "); + test.done(); + }, + + "write/readVString": function(test) { + var bb = new ByteBuffer(2); + bb.writeVString("ab"); // resizes to 4 + test.equal(bb.array.byteLength, 4); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readVString(0)); + test.equal(bb.toString("debug"), "<02 61 62>00 "); + test.equal("ab", bb.readLString()); + test.equal(bb.toString("debug"), " 02 61 62|00 "); + test.done(); + }, + + "write/readCString": function(test) { + var bb = new ByteBuffer(2); + bb.writeCString("ab"); // resizes to 4 + test.equal(bb.array.byteLength, 4); + test.equal(bb.offset, 3); + test.equal(bb.length, 0); + bb.flip(); + test.equal(bb.toString("debug"), "<61 62 00>00 "); + test.deepEqual({"string": "ab", "length": 3}, bb.readCString(0)); + test.equal(bb.toString("debug"), "<61 62 00>00 "); + test.equal("ab", bb.readCString()); + test.equal(bb.toString("debug"), " 61 62 00|00 "); + test.done(); + }, + + "write/readJSON": function(test) { + var bb = new ByteBuffer(); + var data = {"x":1}; + bb.writeJSON(data); + bb.flip(); + test.deepEqual(data, bb.readJSON()); + test.done(); + }, + + "toHex": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + test.equal(bb.flip().toHex(), "1234"); + test.done(); + }, + + "toString": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x6162).flip(); + test.equal(bb.toString(), "ByteBuffer(offset=0,markedOffset=-1,length=2,capacity=3)"); + test.equal(bb.toString("hex"), "6162"); + test.equal(bb.toString("base64"), "YWI="); + test.equal(bb.toString("utf8"), "ab"); + test.equal(bb.toString("debug"), "<61 62>00 "); + test.done(); + }, + + "toArrayBuffer": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + var buf = bb.toArrayBuffer(); + test.equal(buf.byteLength, 2); + test.equal(buf[0], 0x12); + test.equal(buf[1], 0x34); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.array.byteLength, 3); + test.done(); + }, + + "toBuffer": function(test) { + var bb = new ByteBuffer(3); + bb.writeUint16(0x1234); + var buf; + try { + buf = bb.toBuffer(); + } catch (e) { + console.trace(e); + } + test.equal(buf.length, 2); + test.equal(buf[0], 0x12); + test.equal(buf[1], 0x34); + test.equal(bb.offset, 2); + test.equal(bb.length, 0); + test.equal(bb.array.byteLength, 3); + test.done(); + }, + + "printDebug": function(test) { + var bb = new ByteBuffer(3); + function callMe() { callMe.called = true; }; + bb.printDebug(callMe); + test.ok(callMe.called); + test.done(); + }, + + "encode/decode/calculateUTF8Char": function(test) { + var bb = new ByteBuffer(6) + , chars = [0x00, 0x7F, 0x80, 0x7FF, 0x800, 0xFFFF, 0x10000, 0x1FFFFF, 0x200000, 0x3FFFFFF, 0x4000000, 0x7FFFFFFF] + , dec; + for (var i=0; i10 02 18 00 20 80 B0 D9 B4 E8 27 28 93 99 8E CD 04<00 "); + test.done(); + }, + + "encode/decode64": function(test) { + var values = [ + ["ProtoBuf.js", "UHJvdG9CdWYuanM="], + ["ProtoBuf.j", "UHJvdG9CdWYuag=="], + ["ProtoBuf.", "UHJvdG9CdWYu"], + ["ProtoBuf", "UHJvdG9CdWY="] + ]; + for (var i=0; i>> 0, 0); + test.strictEqual(NaN | 0, 0); + test.strictEqual(Infinity >>> 0, 0); + test.strictEqual(Infinity | 0, 0); + test.strictEqual(-Infinity >>> 0, 0); + test.strictEqual(-Infinity | 0, 0); + + test.done(); + }, + + "ByteBuffer-like": function(test) { + var bb = new ByteBuffer(4); + var bbLike = { + array: bb.array, + view: bb.view, + offset: bb.offset, + markedOffset: bb.markedOffset, + length: bb.length, + littleEndian: bb.littleEndian + }; + test.ok(ByteBuffer.isByteBuffer(bbLike)); + var bb2 = ByteBuffer.wrap(bbLike); + test.ok(bb2 instanceof ByteBuffer); + test.strictEqual(bbLike.array, bb2.array); + test.strictEqual(bbLike.view, bb2.view); + test.strictEqual(bbLike.offset, bb2.offset); + test.strictEqual(bbLike.markedOffset, bb2.markedOffset); + test.strictEqual(bbLike.length, bb2.length); + test.strictEqual(bbLike.littleEndian, bb2.littleEndian); + test.done(); + }, + + "commonjs": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var Long = ByteBuffer.Long; + var sandbox = new Sandbox({ + require: function(moduleName) { + if (moduleName == 'long') { + return Long; + } + }, + module: { + exports: {} + } + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in CommonJS-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.module.exports == 'function'); + test.ok(sandbox.module.exports.Long && sandbox.module.exports.Long == ByteBuffer.Long); + test.done(); + }, + + "amd": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + require: function() {}, + define: (function() { + function define(moduleName, dependencies, constructor) { + define.called = [moduleName, dependencies]; + } + define.amd = true; + define.called = null; + return define; + })() + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in AMD-VM"); + // console.log(util.inspect(sandbox)); + test.ok(sandbox.define.called && sandbox.define.called[0] == "ByteBuffer" && sandbox.define.called[1][0] == "Math/Long"); + test.done(); + }, + + "shim": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + dcodeIO: { + Long: ByteBuffer.Long + } + }); + vm.runInNewContext(code, sandbox, "ByteBuffer.js in shim-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.dcodeIO != 'undefined' && typeof sandbox.dcodeIO.ByteBuffer != 'undefined'); + test.ok(sandbox.dcodeIO.ByteBuffer.Long && sandbox.dcodeIO.ByteBuffer.Long == ByteBuffer.Long); + test.done(); + }, + + "helloworld": function(test) { + var bb = new ByteBuffer(); + bb.writeUTF8String("Hello world! from ByteBuffer.js. This is just a last visual test of ByteBuffer#printDebug."); + bb.flip(); + console.log(""); + bb.printDebug(console.log); + test.done(); + } +}; + +module.exports = suite; diff --git a/javascript/node_modules/protobufjs/package.json b/javascript/node_modules/protobufjs/package.json new file mode 100644 index 0000000..645c841 --- /dev/null +++ b/javascript/node_modules/protobufjs/package.json @@ -0,0 +1,66 @@ +{ + "name": "protobufjs", + "version": "2.0.5", + "description": "A full-featured protobuf implementation in plain JavaScript.", + "author": { + "name": "Daniel Wirtz", + "email": "dcode@dcode.io" + }, + "contributors": [ + { + "name": "Frank Xu", + "email": "yyfrankyy@gmail.com" + } + ], + "main": "ProtoBuf.js", + "bin": { + "proto2js": "./bin/proto2js" + }, + "repository": { + "type": "git", + "url": "https://github.com/dcodeIO/ProtoBuf.js.git" + }, + "bugs": { + "url": "https://github.com/dcodeIO/ProtoBuf.js/issues" + }, + "keywords": [ + "net", + "buffer", + "protobuf", + "serialization", + "bytebuffer", + "websocket", + "webrtc" + ], + "dependencies": { + "bytebuffer": ">=2.2 <3", + "ascli": "latest" + }, + "devDependencies": { + "testjs": "latest", + "preprocessor": "latest", + "closurecompiler": "latest" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=0.8" + }, + "scripts": { + "prepublish": "npm test", + "test": "node bin/proto2js tests/complex.proto > tests/complex.json && node node_modules/testjs/bin/testjs tests/suite.js", + "make": "npm run-script build && npm run-script compile && dos2unix bin/proto2js && npm test && npm run-script jsdoc", + "build": "node build.js", + "compile": "npm run-script compile-full && npm run-script compile-noparse", + "compile-full": "ccjs ProtoBuf.js --create_source_map=ProtoBuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > ProtoBuf.min.js", + "compile-noparse": "ccjs ProtoBuf.noparse.js --create_source_map=ProtoBuf.noparse.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > ProtoBuf.noparse.min.js", + "jsdoc": "jsdoc -c jsdoc.json" + }, + "readme": "![ProtoBuf.js - protobuf for JavaScript](https://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.png)\r\n=====================================\r\n\r\n**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use\r\nin communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/docs/overview)).\r\n\r\n**ProtoBuf.js** is a pure JavaScript implementation on top of [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js)\r\nincluding a .proto parser, message class building and simple encoding and decoding. There is no compilation step\r\nrequired, it's super easy to use and it works out of the box on .proto files!\r\n\r\nGetting started\r\n---------------\r\n* **Step 1:** Become familar with [Google's Protocol Buffers (protobuf)](https://developers.google.com/protocol-buffers/docs/overview)\r\n* **Step 2:** Head straight to [our wiki for up to date usage information and examples](https://github.com/dcodeIO/ProtoBuf.js/wiki)\r\n* **Step 3:** Build something cool! :-)\r\n\r\nFeatures\r\n--------\r\n* [RequireJS](http://requirejs.org/)/AMD compatible\r\n* [node.js](http://nodejs.org)/CommonJS compatible, also available via [npm](https://npmjs.org/package/protobufjs)\r\n* Browser compatible\r\n* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/ProtoBuf.js/tree/master/externs))\r\n* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)\r\n* Well tested through [test.js](https://github.com/dcodeIO/test.js)\r\n* [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) is the only production dependency\r\n* Fully compatible to the official implementation including advanced features\r\n* Small footprint (even smaller if you use a noparse build)\r\n* proto2js command line utility\r\n\r\nDocumentation\r\n-------------\r\n* [Read the official protobuf guide](https://developers.google.com/protocol-buffers/docs/overview)\r\n* [Read our wiki](https://github.com/dcodeIO/ProtoBuf.js/wiki)\r\n* [Read the API docs](http://htmlpreview.github.com/?http://github.com/dcodeIO/ProtoBuf.js/master/docs/ProtoBuf.html)\r\n* [Check out the examples](https://github.com/dcodeIO/ProtoBuf.js/tree/master/examples)\r\n\r\nTests [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js)\r\n------------------\r\n* [View source](https://github.com/dcodeIO/ProtoBuf.js/blob/master/tests/suite.js)\r\n* [View report](https://travis-ci.org/dcodeIO/ProtoBuf.js)\r\n\r\nDownloads\r\n---------\r\n* [ZIP-Archive](https://github.com/dcodeIO/ProtoBuf.js/archive/master.zip)\r\n* [Tarball](https://github.com/dcodeIO/ProtoBuf.js/tarball/master)\r\n\r\nContributors\r\n------------\r\n[Daniel Wirtz](https://github.com/dcodeIO) (maintainer), [Frank Xu](https://github.com/yyfrankyy),\r\n[Dretch](https://github.com/Dretch), [shirmin](https://github.com/shirmin), [Nikolai Vavilov](https://github.com/seishun)\r\n\r\n**License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) - Logo derived from [W3C HTML5 Logos](http://www.w3.org/html/logo/) (CC A 3.0)\r\n", + "readmeFilename": "README.md", + "_id": "protobufjs@2.0.5", + "dist": { + "shasum": "4a1e01fe75c94c3a0fb14c468762993256c9eeff" + }, + "_from": "protobufjs@", + "_resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-2.0.5.tgz" +} diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf.js b/javascript/node_modules/protobufjs/src/ProtoBuf.js new file mode 100644 index 0000000..d8cbf33 --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf.js @@ -0,0 +1,370 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @license ProtoBuf.js (c) 2013 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/ProtoBuf.js for details + */ +(function(global) { + "use strict"; + + function loadProtoBuf(ByteBuffer) { + + /** + * The ProtoBuf namespace. + * @exports ProtoBuf + * @namespace + * @expose + */ + var ProtoBuf = {}; + + /** + * ProtoBuf.js version. + * @type {string} + * @const + * @expose + */ + ProtoBuf.VERSION = // #put '"'+VERSION+'";' + + /** + * Wire types. + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES = {}; + + /** + * Varint wire type. + * @type {number} + * @expose + */ + ProtoBuf.WIRE_TYPES.VARINT = 0; + + /** + * Fixed 64 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS64 = 1; + + /** + * Length delimited wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.LDELIM = 2; + + /** + * Start group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.STARTGROUP = 3; + + /** + * End group wire type. + * @type {number} + * @const + * @deprecated Not supported. + * @expose + */ + ProtoBuf.WIRE_TYPES.ENDGROUP = 4; + + /** + * Fixed 32 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS32 = 5; + + /** + * Types. + * @dict + * @type {Object.} + * @const + * @expose + */ + ProtoBuf.TYPES = { + // According to the protobuf spec. + "int32": { + name: "int32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint32": { + name: "uint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint32": { + name: "sint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "int64": { + name: "int64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "uint64": { + name: "uint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "sint64": { + name: "sint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "bool": { + name: "bool", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "double": { + name: "double", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "string": { + name: "string", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "bytes": { + name: "bytes", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + }, + "fixed32": { + name: "fixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "sfixed32": { + name: "sfixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "fixed64": { + name: "fixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "sfixed64": { + name: "sfixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64 + }, + "float": { + name: "float", + wireType: ProtoBuf.WIRE_TYPES.BITS32 + }, + "enum": { + name: "enum", + wireType: ProtoBuf.WIRE_TYPES.VARINT + }, + "message": { + name: "message", + wireType: ProtoBuf.WIRE_TYPES.LDELIM + } + }; + + /** + * @type {?Long} + */ + ProtoBuf.Long = ByteBuffer.Long; + + /** + * If set to `true`, field names will be converted from underscore notation to camel case. Defaults to `false`. + * Must be set prior to parsing. + * @type {boolean} + * @expose + */ + ProtoBuf.convertFieldsToCamelCase = false; + + // #include "ProtoBuf/Util.js" + + // #include "ProtoBuf/Lang.js" + + // #ifndef NOPARSE + // #include "ProtoBuf/DotProto.js" + + // #else + // This build of ProtoBuf.js does not include DotProto support. + + // #endif + // #include "ProtoBuf/Reflect.js" + + // #include "ProtoBuf/Builder.js" + + // #ifndef NOPARSE + + /** + * Loads a .proto string and returns the Builder. + * @param {string} proto .proto file contents + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted. + * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports. + * @return {ProtoBuf.Builder} Builder to create new messages + * @throws {Error} If the definition cannot be parsed or built + * @expose + */ + ProtoBuf.loadProto = function(proto, builder, filename) { + if (typeof builder == 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string')) { + filename = builder; + builder = null; + } + return ProtoBuf.loadJson((new ProtoBuf.DotProto.Parser(proto+"")).parse(), builder, filename); + }; + + /** + * Loads a .proto string and returns the Builder. This is an alias of {@link ProtoBuf.loadProto}. + * @function + * @param {string} proto .proto file contents + * @param {(ProtoBuf.Builder|string)=} builder Builder to append to. Will create a new one if omitted. + * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports. + * @return {ProtoBuf.Builder} Builder to create new messages + * @throws {Error} If the definition cannot be parsed or built + * @expose + */ + ProtoBuf.protoFromString = ProtoBuf.loadProto; // Legacy + + /** + * Loads a .proto file and returns the Builder. + * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with + * an overridden 'root' path for all imported files. + * @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. + * If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + * function will return the Builder or NULL if the request has failed. + * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted. + * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the + * request has failed), else undefined + * @expose + */ + ProtoBuf.loadProtoFile = function(filename, callback, builder) { + if (callback && typeof callback === 'object') { + builder = callback; + callback = null; + } else if (!callback || typeof callback !== 'function') { + callback = null; + } + if (callback) { + ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename, function(contents) { + callback(ProtoBuf.loadProto(contents, builder, filename)); + }); + } else { + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents !== null ? ProtoBuf.protoFromString(contents, builder, filename) : null; + } + }; + + /** + * Loads a .proto file and returns the Builder. This is an alias of {@link ProtoBuf.loadProtoFile}. + * @function + * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with + * an overridden 'root' path for all imported files. + * @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. + * If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + * function will return the Builder or NULL if the request has failed. + * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted. + * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the + * request has failed), else undefined + * @expose + */ + ProtoBuf.protoFromFile = ProtoBuf.loadProtoFile; // Legacy + + // #endif + + /** + * Constructs a new Builder with the specified package defined. + * @param {string=} pkg Package name as fully qualified name, e.g. "My.Game". If no package is specified, the + * builder will only contain a global namespace. + * @param {Object.=} options Top level options + * @return {ProtoBuf.Builder} New Builder + * @expose + */ + ProtoBuf.newBuilder = function(pkg, options) { + var builder = new ProtoBuf.Builder(); + if (typeof pkg !== 'undefined' && pkg !== null) { + builder.define(pkg, options); + } + return builder; + }; + + /** + * Loads a .json definition and returns the Builder. + * @param {!*|string} json JSON definition + * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted. + * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports. + * @return {ProtoBuf.Builder} Builder to create new messages + * @throws {Error} If the definition cannot be parsed or built + * @expose + */ + ProtoBuf.loadJson = function(json, builder, filename) { + if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string')) { + filename = builder; + builder = null; + } + if (!builder || typeof builder !== 'object') builder = ProtoBuf.newBuilder(); + if (typeof json === 'string') json = JSON.parse(json); + builder["import"](json, filename); + builder.resolveAll(); + builder.build(); + return builder; + }; + + /** + * Loads a .json file and returns the Builder. + * @param {string|{root: string, file: string}} filename Path to json file or an object specifying 'file' with + * an overridden 'root' path for all imported files. + * @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. + * If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this + * function will return the Builder or NULL if the request has failed. + * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted. + * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the + * request has failed), else undefined + * @expose + */ + ProtoBuf.loadJsonFile = function(filename, callback, builder) { + if (callback && typeof callback === 'object') { + builder = callback; + callback = null; + } else if (!callback || typeof callback !== 'function') { + callback = null; + } + if (callback) { + ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename, function(contents) { + try { + callback(ProtoBuf.loadJson(JSON.parse(contents), builder, filename)); + } catch (err) { + callback(err); + } + }); + } else { + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents !== null ? ProtoBuf.loadJson(JSON.parse(contents), builder, filename) : null; + } + }; + + return ProtoBuf; + } + + // Enable module loading if available + if (typeof module != 'undefined' && module["exports"]) { // CommonJS + module["exports"] = loadProtoBuf(require("bytebuffer")); + } else if (typeof define != 'undefined' && define["amd"]) { // AMD + define("ProtoBuf", ["ByteBuffer"], loadProtoBuf); + } else { // Shim + if (!global["dcodeIO"]) { + global["dcodeIO"] = {}; + } + global["dcodeIO"]["ProtoBuf"] = loadProtoBuf(global["dcodeIO"]["ByteBuffer"]); + } + +})(this); \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/Builder.js b/javascript/node_modules/protobufjs/src/ProtoBuf/Builder.js new file mode 100644 index 0000000..40a8e73 --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/Builder.js @@ -0,0 +1,643 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.Builder + * @expose + */ +ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) { + "use strict"; + + /** + * Constructs a new Builder. + * @exports ProtoBuf.Builder + * @class Provides the functionality to build protocol messages. + * @constructor + */ + var Builder = function() { + + /** + * Namespace. + * @type {ProtoBuf.Reflect.Namespace} + * @expose + */ + this.ns = new Reflect.Namespace(null, ""); // Global namespace + + /** + * Namespace pointer. + * @type {ProtoBuf.Reflect.T} + * @expose + */ + this.ptr = this.ns; + + /** + * Resolved flag. + * @type {boolean} + * @expose + */ + this.resolved = false; + + /** + * The current building result. + * @type {Object.|null} + * @expose + */ + this.result = null; + + /** + * Imported files. + * @type {Array.} + * @expose + */ + this.files = {}; + + /** + * Import root override. + * @type {?string} + * @expose + */ + this.importRoot = null; + }; + + /** + * Resets the pointer to the global namespace. + * @expose + */ + Builder.prototype.reset = function() { + this.ptr = this.ns; + }; + + /** + * Defines a package on top of the current pointer position and places the pointer on it. + * @param {string} pkg + * @param {Object.=} options + * @return {ProtoBuf.Builder} this + * @throws {Error} If the package name is invalid + * @expose + */ + Builder.prototype.define = function(pkg, options) { + if (typeof pkg !== 'string' || !Lang.TYPEREF.test(pkg)) { + throw(new Error("Illegal package name: "+pkg)); + } + var part = pkg.split("."), i; + for (i=0; i} def Definition + * @return {boolean} true if valid, else false + * @expose + */ + Builder.isValidMessage = function(def) { + // Messages require a string name + if (typeof def["name"] !== 'string' || !Lang.NAME.test(def["name"])) { + return false; + } + // Messages must not contain values (that'd be an enum) or methods (that'd be a service) + if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined') { + return false; + } + // Fields, enums and messages are arrays if provided + var i; + if (typeof def["fields"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["fields"])) { + return false; + } + var ids = [], id; // IDs must be unique + for (i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + if (typeof def["enums"] !== 'undefined') { + if (!ProtoBuf.Util.isArray(def["enums"])) { + return false; + } + for (i=0; i + var keys = Object.keys(def["options"]); + for (var i=0; i>} defs Messages, enums or services to create + * @return {ProtoBuf.Builder} this + * @throws {Error} If a message definition is invalid + * @expose + */ + Builder.prototype.create = function(defs) { + if (!defs) return; // Nothing to create + if (!ProtoBuf.Util.isArray(defs)) { + defs = [defs]; + } + if (defs.length == 0) return; + + // It's quite hard to keep track of scopes and memory here, so let's do this iteratively. + var stack = [], def, obj, subObj, i, j; + stack.push(defs); // One level [a, b, c] + while (stack.length > 0) { + defs = stack.pop(); + if (ProtoBuf.Util.isArray(defs)) { // Stack always contains entire namespaces + while (defs.length > 0) { + def = defs.shift(); // Namespace always contains an array of messages, enums and services + if (Builder.isValidMessage(def)) { + obj = new Reflect.Message(this.ptr, def["name"], def["options"]); + // Create fields + if (def["fields"] && def["fields"].length > 0) { + for (i=0; i 0) { + for (i=0; i 0) { + for (i=0; i ProtoBuf.Lang.ID_MAX) { + obj.extensions[1] = ProtoBuf.Lang.ID_MAX; + } + } + this.ptr.addChild(obj); // Add to current namespace + if (subObj.length > 0) { + stack.push(defs); // Push the current level back + defs = subObj; // Continue processing sub level + subObj = null; + this.ptr = obj; // And move the pointer to this namespace + obj = null; + continue; + } + subObj = null; + obj = null; + } else if (Builder.isValidEnum(def)) { + obj = new Reflect.Enum(this.ptr, def["name"], def["options"]); + for (i=0; i obj.extensions[1]) { + throw(new Error("Illegal extended field id in message "+obj.name+": "+def['fields'][i]['id']+" ("+obj.extensions.join(' to ')+" expected)")); + } + obj.addChild(new Reflect.Message.Field(obj, def["fields"][i]["rule"], def["fields"][i]["type"], def["fields"][i]["name"], def["fields"][i]["id"], def["fields"][i]["options"])); + } + /* if (this.ptr instanceof Reflect.Message) { + this.ptr.addChild(obj); // Reference the extended message here to enable proper lookups + } */ + } else { + if (!/\.?google\.protobuf\./.test(def["ref"])) { // Silently skip internal extensions + throw(new Error("Extended message "+def["ref"]+" is not defined")); + } + } + } else { + throw(new Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(def))); + } + def = null; + } + // Break goes here + } else { + throw(new Error("Not a valid namespace definition: "+JSON.stringify(defs))); + } + defs = null; + this.ptr = this.ptr.parent; // This namespace is s done + } + this.resolved = false; // Require re-resolve + this.result = null; // Require re-build + return this; + }; + + /** + * Tests if the specified file is a valid import. + * @param {string} filename + * @returns {boolean} true if valid, false if it should be skipped + * @expose + */ + Builder.isValidImport = function(filename) { + // Ignore google/protobuf/descriptor.proto (for example) as it makes use of low-level + // bootstrapping directives that are not required and therefore cannot be parsed by ProtoBuf.js. + return !(/google\/protobuf\//.test(filename)); + }; + + /** + * Imports another definition into this builder. + * @param {Object.} json Parsed import + * @param {(string|{root: string, file: string})=} filename Imported file name + * @return {ProtoBuf.Builder} this + * @throws {Error} If the definition or file cannot be imported + * @expose + */ + Builder.prototype["import"] = function(json, filename) { + if (typeof filename === 'string') { + if (ProtoBuf.Util.IS_NODE) { + var path = require("path"); + filename = path.resolve(filename); + } + if (!!this.files[filename]) { + this.reset(); + return this; // Skip duplicate imports + } + this.files[filename] = true; + } + if (!!json['imports'] && json['imports'].length > 0) { + var importRoot, delim = '/', resetRoot = false; + if (typeof filename === 'object') { // If an import root is specified, override + this.importRoot = filename["root"]; resetRoot = true; // ... and reset afterwards + importRoot = this.importRoot; + filename = filename["file"]; + if (importRoot.indexOf("\\") >= 0 || filename.indexOf("\\") >= 0) delim = '\\'; + } else if (typeof filename === 'string') { + if (this.importRoot) { // If import root is overridden, use it + importRoot = this.importRoot; + } else { // Otherwise compute from filename + if (filename.indexOf("/") >= 0) { // Unix + importRoot = filename.replace(/\/[^\/]*$/, ""); + if (/* /file.proto */ importRoot === "") importRoot = "/"; + } else if (filename.indexOf("\\") >= 0) { // Windows + importRoot = filename.replace(/\\[^\\]*$/, ""); delim = '\\'; + } else { + importRoot = "."; + } + } + } else { + importRoot = null; + } + + for (var i=0; i= 0) { + return false; + } + ids.push(id); + } + ids = null; + } + return true; + }; + + /** + * Resolves all namespace objects. + * @throws {Error} If a type cannot be resolved + * @expose + */ + Builder.prototype.resolveAll = function() { + // Resolve all reflected objects + var res; + if (this.ptr == null || typeof this.ptr.type === 'object') return; // Done (already resolved) + if (this.ptr instanceof Reflect.Namespace) { + // Build all children + var children = this.ptr.getChildren(); + for (var i=0; i} + * @throws {Error} If a type could not be resolved + * @expose + */ + Builder.prototype.build = function(path) { + this.reset(); + if (!this.resolved) { + this.resolveAll(); + this.resolved = true; + this.result = null; // Require re-build + } + if (this.result == null) { // (Re-)Build + this.result = this.ns.build(); + } + if (!path) { + return this.result; + } else { + var part = path.split("."); + var ptr = this.result; // Build namespace pointer (no hasChild etc.) + for (var i=0; i + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * Utilities to parse .proto files. + * @namespace + * @expose + */ +ProtoBuf.DotProto = {}; // Not present in "noparse" builds + +// #include "ProtoBuf/DotProto/Tokenizer.js" + +// #include "ProtoBuf/DotProto/Parser.js" diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Parser.js b/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Parser.js new file mode 100644 index 0000000..dadae0d --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Parser.js @@ -0,0 +1,743 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.DotProto.Parser + * @expose + */ +ProtoBuf.DotProto.Parser = (function(ProtoBuf, Lang, Tokenizer) { + "use strict"; + + /** + * Constructs a new Parser. + * @exports ProtoBuf.DotProto.Parser + * @class A ProtoBuf .proto parser. + * @param {string} proto Protocol source + * @constructor + */ + var Parser = function(proto) { + + /** + * Tokenizer. + * @type {ProtoBuf.DotProto.Tokenizer} + * @expose + */ + this.tn = new Tokenizer(proto); + }; + + /** + * Runs the parser. + * @return {{package: string|null, messages: Array., enums: Array., imports: Array., options: object}} + * @throws {Error} If the source cannot be parsed + * @expose + */ + Parser.prototype.parse = function() { + var topLevel = { + "name": "[ROOT]", // temporary + "package": null, + "messages": [], + "enums": [], + "imports": [], + "options": {}, + "services": [] + }; + var token, header = true; + do { + token = this.tn.next(); + if (token == null) { + break; // No more messages + } + if (token == 'package') { + if (!header) { + throw(new Error("Illegal package definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + if (topLevel["package"] !== null) { + throw(new Error("Illegal package definition at line "+this.tn.line+": Package already declared")); + } + topLevel["package"] = this._parsePackage(token); + } else if (token == 'import') { + if (!header) { + throw(new Error("Illegal import definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + topLevel.imports.push(this._parseImport(token)); + } else if (token === 'message') { + this._parseMessage(topLevel, token); + header = false; + } else if (token === 'enum') { + this._parseEnum(topLevel, token); + header = false; + } else if (token === 'option') { + if (!header) { + throw(new Error("Illegal option definition at line "+this.tn.line+": Must be declared before the first message or enum")); + } + this._parseOption(topLevel, token); + } else if (token === 'service') { + this._parseService(topLevel, token); + } else if (token === 'extend') { + this._parseExtend(topLevel, token); + } else if (token === 'syntax') { + this._parseIgnoredStatement(topLevel, token); + } else { + throw(new Error("Illegal top level declaration at line "+this.tn.line+": "+token)); + } + } while (true); + delete topLevel["name"]; + return topLevel; + }; + + /** + * Parses a number value. + * @param {string} val Number value to parse + * @return {number} Number + * @throws {Error} If the number value is invalid + * @private + */ + Parser.prototype._parseNumber = function(val) { + var sign = 1; + if (val.charAt(0) == '-') { + sign = -1; val = val.substring(1); + } + if (Lang.NUMBER_DEC.test(val)) { + return sign*parseInt(val, 10); + } else if (Lang.NUMBER_HEX.test(val)) { + return sign*parseInt(val.substring(2), 16); + } else if (Lang.NUMBER_OCT.test(val)) { + return sign*parseInt(val.substring(1), 8); + } else if (Lang.NUMBER_FLT.test(val)) { + return sign*parseFloat(val); + } + throw(new Error("Illegal number value at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + }; + + /** + * Parses an ID value. + * @param {string} val ID value to parse + * @param {boolean=} neg Whether the ID may be negative, defaults to `false` + * @returns {number} ID + * @throws {Error} If the ID value is invalid + * @private + */ + Parser.prototype._parseId = function(val, neg) { + var id = -1; + var sign = 1; + if (val.charAt(0) == '-') { + sign = -1; val = val.substring(1); + } + if (Lang.NUMBER_DEC.test(val)) { + id = parseInt(val); + } else if (Lang.NUMBER_HEX.test(val)) { + id = parseInt(val.substring(2), 16); + } else if (Lang.NUMBER_OCT.test(val)) { + id = parseInt(val.substring(1), 8); + } else { + throw(new Error("Illegal ID value at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + } + id = (sign*id)|0; // Force to 32bit + if (!neg && id < 0) { + throw(new Error("Illegal ID range at line "+this.tn.line+": "+(sign < 0 ? '-' : '')+val)); + } + return id; + }; + + /** + * Parses the package definition. + * @param {string} token Initial token + * @return {string} Package name + * @throws {Error} If the package definition cannot be parsed + * @private + */ + Parser.prototype._parsePackage = function(token) { + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal package name at line "+this.tn.line+": "+token)); + } + var pkg = token; + token = this.tn.next(); + if (token != Lang.END) { + throw(new Error("Illegal end of package definition at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return pkg; + }; + + /** + * Parses an import definition. + * @param {string} token Initial token + * @return {string} Import file name + * @throws {Error} If the import definition cannot be parsed + * @private + */ + Parser.prototype._parseImport = function(token) { + token = this.tn.next(); + if (token === "public") { + token = this.tn.next(); + } + if (token !== Lang.STRINGOPEN) { + throw(new Error("Illegal begin of import value at line "+this.tn.line+": "+token+" ('"+Lang.STRINGOPEN+"' expected)")); + } + var imported = this.tn.next(); + token = this.tn.next(); + if (token !== Lang.STRINGCLOSE) { + throw(new Error("Illegal end of import value at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal end of import definition at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return imported; + }; + + /** + * Parses a namespace option. + * @param {Object} parent Parent definition + * @param {string} token Initial token + * @throws {Error} If the option cannot be parsed + * @private + */ + Parser.prototype._parseOption = function(parent, token) { + token = this.tn.next(); + var custom = false; + if (token == Lang.COPTOPEN) { + custom = true; + token = this.tn.next(); + } + if (!Lang.NAME.test(token)) { + // we can allow options of the form google.protobuf.* since they will just get ignored anyways + if (!/google\.protobuf\./.test(token)) { + throw(new Error("Illegal option name in message "+parent.name+" at line "+this.tn.line+": "+token)); + } + } + var name = token; + token = this.tn.next(); + if (custom) { // (my_method_option).foo, (my_method_option), some_method_option + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal custom option name delimiter in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")); + } + name = '('+name+')'; + token = this.tn.next(); + if (Lang.FQTYPEREF.test(token)) { + name += token; + token = this.tn.next(); + } + } + if (token !== Lang.EQUAL) { + throw(new Error("Illegal option operator in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + var value; + token = this.tn.next(); + if (token === Lang.STRINGOPEN) { + value = this.tn.next(); + token = this.tn.next(); + if (token !== Lang.STRINGCLOSE) { + throw(new Error("Illegal end of option value in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + } else { + if (Lang.NUMBER.test(token)) { + value = this._parseNumber(token, true); + } else if (Lang.TYPEREF.test(token)) { + value = token; + } else { + throw(new Error("Illegal option value in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token)); + } + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal end of option in message "+parent.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + parent["options"][name] = value; + }; + + /** + * Parses an ignored block of the form ['keyword', 'typeref', '{' ... '}']. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the directive cannot be parsed + * @private + */ + Parser.prototype._parseIgnoredBlock = function(parent, keyword) { + var token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal "+keyword+" type in "+parent.name+": "+token)); + } + var name = token; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN in "+parent.name+" after "+keyword+" "+name+" at line "+this.tn.line+": "+token)); + } + var depth = 1; + do { + token = this.tn.next(); + if (token === null) { + throw(new Error("Unexpected EOF in "+parent.name+", "+keyword+" (ignored) at line "+this.tn.line+": "+name)); + } + if (token === Lang.OPEN) { + depth++; + } else if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + depth--; + if (depth === 0) { + break; + } + } + } while(true); + }; + + /** + * Parses an ignored statement of the form ['keyword', ..., ';']. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the directive cannot be parsed + * @private + */ + Parser.prototype._parseIgnoredStatement = function(parent, keyword) { + var token; + do { + token = this.tn.next(); + if (token === null) { + throw(new Error("Unexpected EOF in "+parent.name+", "+keyword+" (ignored) at line "+this.tn.line)); + } + if (token === Lang.END) break; + } while (true); + }; + + /** + * Parses a service definition. + * @param {Object} parent Parent definition + * @param {string} keyword Initial token + * @throws {Error} If the service cannot be parsed + * @private + */ + Parser.prototype._parseService = function(parent, keyword) { + var token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal service name at line "+this.tn.line+": "+token)); + } + var name = token; + var svc = { + "name": name, + "rpc": {}, + "options": {} + }; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN after service "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + do { + token = this.tn.next(); + if (token === "option") { + this._parseOption(svc, token); + } else if (token === 'rpc') { + this._parseServiceRPC(svc, token); + } else if (token !== Lang.CLOSE) { + throw(new Error("Illegal type for service "+name+" at line "+this.tn.line+": "+token)); + } + } while (token !== Lang.CLOSE); + parent["services"].push(svc); + }; + + /** + * Parses a RPC service definition of the form ['rpc', name, (request), 'returns', (response)]. + * @param {Object} svc Parent definition + * @param {string} token Initial token + * @private + */ + Parser.prototype._parseServiceRPC = function(svc, token) { + var type = token; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal RPC method name in service "+svc["name"]+" at line "+this.tn.line+": "+token)); + } + var name = token; + var method = { + "request": null, + "response": null, + "options": {} + }; + token = this.tn.next(); + if (token !== Lang.COPTOPEN) { + throw(new Error("Illegal start of request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTOPEN+"' expected)")); + } + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token)); + } + method["request"] = token; + token = this.tn.next(); + if (token != Lang.COPTCLOSE) { + throw(new Error("Illegal end of request type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")) + } + token = this.tn.next(); + if (token.toLowerCase() !== "returns") { + throw(new Error("Illegal request/response delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('returns' expected)")); + } + token = this.tn.next(); + if (token != Lang.COPTOPEN) { + throw(new Error("Illegal start of response type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTOPEN+"' expected)")); + } + token = this.tn.next(); + method["response"] = token; + token = this.tn.next(); + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal end of response type in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.COPTCLOSE+"' expected)")) + } + token = this.tn.next(); + if (token === Lang.OPEN) { + do { + token = this.tn.next(); + if (token === 'option') { + this._parseOption(method, token); // <- will fail for the custom-options example + } else if (token !== Lang.CLOSE) { + throw(new Error("Illegal start of option in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('option' expected)")); + } + } while (token !== Lang.CLOSE); + } else if (token !== Lang.END) { + throw(new Error("Illegal method delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' or '"+Lang.OPEN+"' expected)")); + } + if (typeof svc[type] === 'undefined') svc[type] = {}; + svc[type][name] = method; + }; + + /** + * Parses a message definition. + * @param {Object} parent Parent definition + * @param {string} token First token + * @return {Object} + * @throws {Error} If the message cannot be parsed + * @private + */ + Parser.prototype._parseMessage = function(parent, token) { + /** @dict */ + var msg = {}; // Note: At some point we might want to exclude the parser, so we need a dict. + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal message name"+(parent ? " in message "+parent["name"] : "")+" at line "+this.tn.line+": "+token)); + } + msg["name"] = token; + token = this.tn.next(); + if (token != Lang.OPEN) { + throw(new Error("Illegal OPEN after message "+msg.name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + msg["fields"] = []; // Note: Using arrays to support also browser that cannot preserve order of object keys. + msg["enums"] = []; + msg["messages"] = []; + msg["options"] = {}; + // msg["extensions"] = undefined + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + break; + } else if (Lang.RULE.test(token)) { + this._parseMessageField(msg, token); + } else if (token === "enum") { + this._parseEnum(msg, token); + } else if (token === "message") { + this._parseMessage(msg, token); + } else if (token === "option") { + this._parseOption(msg, token); + } else if (token === "extensions") { + msg["extensions"] = this._parseExtensions(msg, token); + } else if (token === "extend") { + this._parseExtend(msg, token); + } else { + throw(new Error("Illegal token in message "+msg.name+" at line "+this.tn.line+": "+token+" (type or '"+Lang.CLOSE+"' expected)")); + } + } while (true); + parent["messages"].push(msg); + return msg; + }; + + /** + * Parses a message field. + * @param {Object} msg Message definition + * @param {string} token Initial token + * @throws {Error} If the message field cannot be parsed + * @private + */ + Parser.prototype._parseMessageField = function(msg, token) { + /** @dict */ + var fld = {}; + fld["rule"] = token; + token = this.tn.next(); + if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token)) { + throw(new Error("Illegal field type in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + fld["type"] = token; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal field name in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + fld["name"] = token; + token = this.tn.next(); + if (token !== Lang.EQUAL) { + throw(new Error("Illegal field number operator in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + token = this.tn.next(); + try { + fld["id"] = this._parseId(token); + } catch (e) { + throw(new Error("Illegal field id in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + /** @dict */ + fld["options"] = {}; + token = this.tn.next(); + if (token === Lang.OPTOPEN) { + this._parseFieldOptions(msg, fld, token); + token = this.tn.next(); + } + if (token !== Lang.END) { + throw(new Error("Illegal field delimiter in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + msg["fields"].push(fld); + }; + + /** + * Parses a set of field option definitions. + * @param {Object} msg Message definition + * @param {Object} fld Field definition + * @param {string} token Initial token + * @throws {Error} If the message field options cannot be parsed + * @private + */ + Parser.prototype._parseFieldOptions = function(msg, fld, token) { + var first = true; + do { + token = this.tn.next(); + if (token === Lang.OPTCLOSE) { + break; + } else if (token === Lang.OPTEND) { + if (first) { + throw(new Error("Illegal start of message field options in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + token = this.tn.next(); + } + this._parseFieldOption(msg, fld, token); + first = false; + } while (true); + }; + + /** + * Parses a single field option. + * @param {Object} msg Message definition + * @param {Object} fld Field definition + * @param {string} token Initial token + * @throws {Error} If the mesage field option cannot be parsed + * @private + */ + Parser.prototype._parseFieldOption = function(msg, fld, token) { + var custom = false; + if (token === Lang.COPTOPEN) { + token = this.tn.next(); + custom = true; + } + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal field option in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token)); + } + var name = token; + token = this.tn.next(); + if (custom) { + if (token !== Lang.COPTCLOSE) { + throw(new Error("Illegal custom field option name delimiter in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" (')' expected)")); + } + name = '('+name+')'; + token = this.tn.next(); + if (Lang.FQTYPEREF.test(token)) { + name += token; + token = this.tn.next(); + } + } + if (token !== Lang.EQUAL) { + throw(new Error("Illegal field option operation in message "+msg.name+"#"+fld.name+" at line "+this.tn.line+": "+token+" ('=' expected)")); + } + var value; + token = this.tn.next(); + if (token === Lang.STRINGOPEN) { + value = this.tn.next(); + token = this.tn.next(); + if (token != Lang.STRINGCLOSE) { + throw(new Error("Illegal end of field value in message "+msg.name+"#"+fld.name+", option "+name+" at line "+this.tn.line+": "+token+" ('"+Lang.STRINGCLOSE+"' expected)")); + } + } else if (Lang.NUMBER.test(token, true)) { + value = this._parseNumber(token, true); + } else if (Lang.BOOL.test(token)) { + value = token.toLowerCase() === 'true'; + } else if (Lang.TYPEREF.test(token)) { + value = token; // TODO: Resolve? + } else { + throw(new Error("Illegal field option value in message "+msg.name+"#"+fld.name+", option "+name+" at line "+this.tn.line+": "+token)); + } + fld["options"][name] = value; + }; + + /** + * Parses an enum. + * @param {Object} msg Message definition + * @param {string} token Initial token + * @throws {Error} If the enum cannot be parsed + * @private + */ + Parser.prototype._parseEnum = function(msg, token) { + /** @dict */ + var enm = {}; + token = this.tn.next(); + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal enum name in message "+msg.name+" at line "+this.tn.line+": "+token)); + } + enm["name"] = token; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN after enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + enm["values"] = []; + enm["options"] = {}; + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token === Lang.END) this.tn.next(); + break; + } + if (token == 'option') { + this._parseOption(enm, token); + } else { + if (!Lang.NAME.test(token)) { + throw(new Error("Illegal enum value name in enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + this._parseEnumValue(enm, token); + } + } while (true); + msg["enums"].push(enm); + }; + + /** + * Parses an enum value. + * @param {Object} enm Enum definition + * @param {string} token Initial token + * @throws {Error} If the enum value cannot be parsed + * @private + */ + Parser.prototype._parseEnumValue = function(enm, token) { + /** @dict */ + var val = {}; + val["name"] = token; + token = this.tn.next(); + if (token !== Lang.EQUAL) { + throw(new Error("Illegal enum value operator in enum "+enm.name+" at line "+this.tn.line+": "+token+" ('"+Lang.EQUAL+"' expected)")); + } + token = this.tn.next(); + try { + val["id"] = this._parseId(token, true); + } catch (e) { + throw(new Error("Illegal enum value id in enum "+enm.name+" at line "+this.tn.line+": "+token)); + } + enm["values"].push(val); + token = this.tn.next(); + if (token === Lang.OPTOPEN) { + var opt = { 'options' : {} }; // TODO: Actually expose them somehow. + this._parseFieldOptions(enm, opt, token); + token = this.tn.next(); + } + if (token !== Lang.END) { + throw(new Error("Illegal enum value delimiter in enum "+enm.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + }; + + /** + * Parses an extensions statement. + * @param {Object} msg Message object + * @param {string} token Initial token + * @throws {Error} If the extensions statement cannot be parsed + * @private + */ + Parser.prototype._parseExtensions = function(msg, token) { + /** @type {Array.} */ + var range = []; + token = this.tn.next(); + if (token === "min") { // FIXME: Does the official implementation support this? + range.push(Lang.ID_MIN); + } else if (token === "max") { + range.push(Lang.ID_MAX); + } else { + range.push(this._parseNumber(token)); + } + token = this.tn.next(); + if (token !== 'to') { + throw("Illegal extensions delimiter in message "+msg.name+" at line "+this.tn.line+" ('to' expected)"); + } + token = this.tn.next(); + if (token === "min") { + range.push(Lang.ID_MIN); + } else if (token === "max") { + range.push(Lang.ID_MAX); + } else { + range.push(this._parseNumber(token)); + } + token = this.tn.next(); + if (token !== Lang.END) { + throw(new Error("Illegal extension delimiter in message "+msg.name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' expected)")); + } + return range; + }; + + /** + * Parses an extend block. + * @param {Object} parent Parent object + * @param {string} token Initial token + * @throws {Error} If the extend block cannot be parsed + * @private + */ + Parser.prototype._parseExtend = function(parent, token) { + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) { + throw(new Error("Illegal extended message name at line "+this.tn.line+": "+token)); + } + /** @dict */ + var ext = {}; + ext["ref"] = token; + ext["fields"] = []; + token = this.tn.next(); + if (token !== Lang.OPEN) { + throw(new Error("Illegal OPEN in extend "+ext.name+" at line "+this.tn.line+": "+token+" ('"+Lang.OPEN+"' expected)")); + } + do { + token = this.tn.next(); + if (token === Lang.CLOSE) { + token = this.tn.peek(); + if (token == Lang.END) this.tn.next(); + break; + } else if (Lang.RULE.test(token)) { + this._parseMessageField(ext, token); + } else { + throw(new Error("Illegal token in extend "+ext.name+" at line "+this.tn.line+": "+token+" (rule or '"+Lang.CLOSE+"' expected)")); + } + } while (true); + parent["messages"].push(ext); + return ext; + }; + + /** + * Returns a string representation of this object. + * @returns {string} String representation as of "Parser" + */ + Parser.prototype.toString = function() { + return "Parser"; + }; + + return Parser; + +})(ProtoBuf, ProtoBuf.Lang, ProtoBuf.DotProto.Tokenizer); diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Tokenizer.js b/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Tokenizer.js new file mode 100644 index 0000000..aa21e63 --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/DotProto/Tokenizer.js @@ -0,0 +1,184 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.DotProto.Tokenizer + * @expose + */ +ProtoBuf.DotProto.Tokenizer = (function(Lang) { + + /** + * Constructs a new Tokenizer. + * @exports ProtoBuf.DotProto.Tokenizer + * @class A ProtoBuf .proto Tokenizer. + * @param {string} proto Proto to tokenize + * @constructor + */ + var Tokenizer = function(proto) { + + /** + * Source to parse. + * @type {string} + * @expose + */ + this.source = ""+proto; + + /** + * Current index. + * @type {number} + * @expose + */ + this.index = 0; + + /** + * Current line. + * @type {number} + * @expose + */ + this.line = 1; + + /** + * Stacked values. + * @type {Array} + * @expose + */ + this.stack = []; + + /** + * Whether currently reading a string or not. + * @type {boolean} + * @expose + */ + this.readingString = false; + }; + + /** + * Reads a string beginning at the current index. + * @return {string} The string + * @throws {Error} If it's not a valid string + * @private + */ + Tokenizer.prototype._readString = function() { + Lang.STRING.lastIndex = this.index-1; // Include the open quote + var match; + if ((match = Lang.STRING.exec(this.source)) !== null) { + var s = match[1]; + this.index = Lang.STRING.lastIndex; + this.stack.push(Lang.STRINGCLOSE); + return s; + } + throw(new Error("Illegal string value at line "+this.line+", index "+this.index)); + }; + + /** + * Gets the next token and advances by one. + * @return {?string} Token or `null` on EOF + * @throws {Error} If it's not a valid proto file + * @expose + */ + Tokenizer.prototype.next = function() { + if (this.stack.length > 0) { + return this.stack.shift(); + } + if (this.index >= this.source.length) { + return null; // No more tokens + } + if (this.readingString) { + this.readingString = false; + return this._readString(); + } + var repeat, last; + do { + repeat = false; + // Strip white spaces + while (Lang.WHITESPACE.test(last = this.source.charAt(this.index))) { + this.index++; + if (last === "\n") this.line++; + if (this.index === this.source.length) return null; + } + // Strip comments + if (this.source.charAt(this.index) === '/') { + if (this.source.charAt(++this.index) === '/') { // Single line + while (this.source.charAt(this.index) !== "\n") { + this.index++; + if (this.index == this.source.length) return null; + } + this.index++; + this.line++; + repeat = true; + } else if (this.source.charAt(this.index) === '*') { /* Block */ + last = ''; + while (last+(last=this.source.charAt(this.index)) !== '*/') { + this.index++; + if (last === "\n") this.line++; + if (this.index === this.source.length) return null; + } + this.index++; + repeat = true; + } else { + throw(new Error("Invalid comment at line "+this.line+": /"+this.source.charAt(this.index)+" ('/' or '*' expected)")); + } + } + } while (repeat); + if (this.index === this.source.length) return null; + + // Read the next token + var end = this.index; + Lang.DELIM.lastIndex = 0; + var delim = Lang.DELIM.test(this.source.charAt(end)); + if (!delim) { + end++; + while(end < this.source.length && !Lang.DELIM.test(this.source.charAt(end))) { + end++; + } + } else { + end++; + } + var token = this.source.substring(this.index, this.index = end); + if (token === Lang.STRINGOPEN) { + this.readingString = true; + } + return token; + }; + + /** + * Peeks for the next token. + * @return {?string} Token or `null` on EOF + * @throws {Error} If it's not a valid proto file + * @expose + */ + Tokenizer.prototype.peek = function() { + if (this.stack.length == 0) { + var token = this.next(); + if (token === null) return null; + this.stack.push(token); + } + return this.stack[0]; + }; + + /** + * Returns a string representation of this object. + * @return {string} String representation as of "Tokenizer(index/length)" + * @expose + */ + Tokenizer.prototype.toString = function() { + return "Tokenizer("+this.index+"/"+this.source.length+" at line "+this.line+")"; + }; + + return Tokenizer; + +})(ProtoBuf.Lang); diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/Lang.js b/javascript/node_modules/protobufjs/src/ProtoBuf/Lang.js new file mode 100644 index 0000000..27a9879 --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/Lang.js @@ -0,0 +1,70 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.Lang + * @expose + */ +ProtoBuf.Lang = (function() { + "use strict"; + + /** + * ProtoBuf Language. + * @exports ProtoBuf.Lang + * @type {Object.} + * @namespace + * @expose + */ + var Lang = { // Look, so cute! + OPEN: "{", + CLOSE: "}", + OPTOPEN: "[", + OPTCLOSE: "]", + OPTEND: ",", + EQUAL: "=", + END: ";", + STRINGOPEN: '"', + STRINGCLOSE: '"', + COPTOPEN: '(', + COPTCLOSE: ')', + + DELIM: /[\s\{\}=;\[\],"\(\)]/g, + + KEYWORD: /^(?:package|option|import|message|enum|extend|service|syntax|extensions)$/, + RULE: /^(?:required|optional|repeated)$/, + TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/, + NAME: /^[a-zA-Z][a-zA-Z_0-9]*$/, + OPTNAME: /^(?:[a-zA-Z][a-zA-Z_0-9]*|\([a-zA-Z][a-zA-Z_0-9]*\))$/, + TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/, + TYPEREF: /^(?:\.?[a-zA-Z][a-zA-Z_0-9]*)+$/, + FQTYPEREF: /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/, + NUMBER: /^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+)$/, + NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/, + NUMBER_HEX: /^0x[0-9a-fA-F]+$/, + NUMBER_OCT: /^0[0-7]+$/, + NUMBER_FLT: /^[0-9]*\.[0-9]+$/, + ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, + WHITESPACE: /\s/, + STRING: /"([^"\\]*(\\.[^"\\]*)*)"/g, + BOOL: /^(?:true|false)$/i, + + ID_MIN: 1, + ID_MAX: 0x1FFFFFFF + }; + return Lang; +})(); diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/Reflect.js b/javascript/node_modules/protobufjs/src/ProtoBuf/Reflect.js new file mode 100644 index 0000000..1cf18e3 --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/Reflect.js @@ -0,0 +1,1673 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.Reflect + * @expose + */ +ProtoBuf.Reflect = (function(ProtoBuf) { + "use strict"; + + /** + * @exports ProtoBuf.Reflect + * @namespace + */ + var Reflect = {}; + + /** + * Constructs a Reflect base class. + * @exports ProtoBuf.Reflect.T + * @constructor + * @param {ProtoBuf.Reflect.T} parent Parent object + * @param {string} name Object name + */ + var T = function(parent, name) { + /** + * Parent object. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.parent = parent; + + /** + * Object name in namespace. + * @type {string} + * @expose + */ + this.name = name; + }; + + /** + * Returns the fully qualified name of this object. + * @returns {string} Fully qualified name as of ".PATH.TO.THIS" + * @expose + */ + T.prototype.fqn = function() { + var name = this.name, + ptr = this; + do { + ptr = ptr.parent; + if (ptr == null) break; + name = ptr.name+"."+name; + } while (true); + return name; + }; + + /** + * Returns a string representation of this Reflect object (its fully qualified name). + * @param {boolean=} includeClass Set to true to include the class name. Defaults to false. + * @return String representation + * @expose + */ + T.prototype.toString = function(includeClass) { + var name = this.fqn(); + if (includeClass) { + if (this instanceof Message) { + name = "Message "+name; + } else if (this instanceof Message.Field) { + name = "Message.Field "+name; + } else if (this instanceof Enum) { + name = "Enum "+name; + } else if (this instanceof Enum.Value) { + name = "Enum.Value "+name; + } else if (this instanceof Service) { + name = "Service "+name; + } else if (this instanceof Service.Method) { + if (this instanceof Service.RPCMethod) { + name = "Service.RPCMethod "+name; + } else { + name = "Service.Method "+name; // Should not happen as it is abstract + } + } else if (this instanceof Namespace) { + name = "Namespace "+name; + } + } + return name; + }; + + /** + * Builds this type. + * @throws {Error} If this type cannot be built directly + * @expose + */ + T.prototype.build = function() { + throw(new Error(this.toString(true)+" cannot be built directly")); + }; + + /** + * @alias ProtoBuf.Reflect.T + * @expose + */ + Reflect.T = T; + + /** + * Constructs a new Namespace. + * @exports ProtoBuf.Reflect.Namespace + * @param {ProtoBuf.Reflect.Namespace|null} parent Namespace parent + * @param {string} name Namespace name + * @param {Object.} options Namespace options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Namespace = function(parent, name, options) { + T.call(this, parent, name); + + /** + * Children inside the namespace. + * @type {Array.} + */ + this.children = []; + + /** + * Options. + * @type {Object.} + */ + this.options = options || {}; + }; + + // Extends T + Namespace.prototype = Object.create(T.prototype); + + /** + * Returns an array of the namespace's children. + * @param {ProtoBuf.Reflect.T=} type Filter type (returns instances of this type only). Defaults to null (all children). + * @return {Array.} + * @expose + */ + Namespace.prototype.getChildren = function(type) { + type = type || null; + if (type == null) { + return this.children.slice(); + } + var children = []; + for (var i=0; i} Runtime namespace + * @expose + */ + Namespace.prototype.build = function() { + /** @dict */ + var ns = {}; + var children = this.getChildren(), child; + for (var i=0; i} + */ + Namespace.prototype.buildOpt = function() { + var opt = {}; + var keys = Object.keys(this.options); + for (var i=0; i}null} Option value or NULL if there is no such option + */ + Namespace.prototype.getOption = function(name) { + if (typeof name == 'undefined') { + return this.options; + } + return typeof this.options[name] != 'undefined' ? this.options[name] : null; + }; + + /** + * @alias ProtoBuf.Reflect.Namespace + * @expose + */ + Reflect.Namespace = Namespace; + + /** + * Constructs a new Message. + * @exports ProtoBuf.Reflect.Message + * @param {ProtoBuf.Reflect.Namespace} parent Parent message or namespace + * @param {string} name Message name + * @param {Object.} options Message options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Message = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Extensions range. + * @type {!Array.} + * @expose + */ + this.extensions = [ProtoBuf.Lang.ID_MIN, ProtoBuf.Lang.ID_MAX]; + + /** + * Runtime message class. + * @type {?function(new:ProtoBuf.Builder.Message)} + * @expose + */ + this.clazz = null; + }; + + // Extends Namespace + Message.prototype = Object.create(Namespace.prototype); + + /** + * Builds the message and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Message + * @param {boolean=} rebuild Whether to rebuild or not, defaults to false + * @return {ProtoBuf.Reflect.Message} Message class + * @throws {Error} If the message cannot be built + * @expose + */ + Message.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + + // We need to create a prototyped Message class in an isolated scope + var clazz = (function(ProtoBuf, T) { + var fields = T.getChildren(Reflect.Message.Field); + + /** + * Constructs a new runtime Message. + * @name ProtoBuf.Builder.Message + * @class Barebone of all runtime messages. + * @param {Object.|...[string]} values Preset values + * @constructor + * @throws {Error} If the message cannot be created + */ + var Message = function(values) { + ProtoBuf.Builder.Message.call(this); + var i, field; + + // Create fields on the object itself to allow setting and getting through Message#fieldname + for (i=0; i} + * @expose + */ + var O_o; // for cc + + if (Object.defineProperty) { + Object.defineProperty(Message, '$options', { + 'value': T.buildOpt(), + 'enumerable': false, + 'configurable': false, + 'writable': false + }); + } + + return Message; + + })(ProtoBuf, this); + + // Static enums and prototyped sub-messages + var children = this.getChildren(); + for (var i=0; i 0)) { + var tag = buffer.readVarint32(); + var wireType = tag & 0x07, + id = tag >> 3; + var field = this.getChild(id); // Message.Field only + if (!field) { + // "messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing." + switch (wireType) { + case ProtoBuf.WIRE_TYPES.VARINT: + buffer.readVarint32(); + break; + case ProtoBuf.WIRE_TYPES.BITS32: + buffer.offset += 4; + break; + case ProtoBuf.WIRE_TYPES.BITS64: + buffer.offset += 8; + break; + case ProtoBuf.WIRE_TYPES.LDELIM: + var len = buffer.readVarint32(); + buffer.offset += len; + break; + default: + throw(new Error("Illegal wire type of unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType)); + } + continue; + } + if (field.repeated && !field.options["packed"]) { + msg.add(field.name, field.decode(wireType, buffer)); + } else { + msg.set(field.name, field.decode(wireType, buffer)); + } + } + // Check if all required fields are present + var fields = this.getChildren(ProtoBuf.Reflect.Field); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Field = function(message, rule, type, name, id, options) { + T.call(this, message, name); + + /** + * Message field required flag. + * @type {boolean} + * @expose + */ + this.required = rule == "required"; + + /** + * Message field repeated flag. + * @type {boolean} + * @expose + */ + this.repeated = rule == "repeated"; + + /** + * Message field type. Type reference string if unresolved, protobuf type if resolved. + * @type {string|{name: string, wireType: number} + * @expose + */ + this.type = type; + + /** + * Resolved type reference inside the global namespace. + * @type {ProtoBuf.Reflect.T|null} + * @expose + */ + this.resolvedType = null; + + /** + * Unique message field id. + * @type {number} + * @expose + */ + this.id = id; + + /** + * Message field options. + * @type {!Object.} + * @dict + * @expose + */ + this.options = options || {}; + + /** + * Original field name. + * @type {string} + * @expose + */ + this.originalName = this.name; // Used to revert camelcase transformation on naming collisions + + // Convert field names to camel case notation if the override is set + if (ProtoBuf.convertFieldsToCamelCase) { + this.name = this.name.replace(/_([a-zA-Z])/g, function($0, $1) { + return $1.toUpperCase(); + }); + } + }; + + // Extends T + Field.prototype = Object.create(T.prototype); + + /** + * Checks if the given value can be set for this field. + * @param {*} value Value to check + * @param {boolean=} skipRepeated Whether to skip the repeated value check or not. Defaults to false. + * @return {*} Verified, maybe adjusted, value + * @throws {Error} If the value cannot be set for this field + * @expose + */ + Field.prototype.verifyValue = function(value, skipRepeated) { + skipRepeated = skipRepeated || false; + if (value === null) { // NULL values for optional fields + if (this.required) { + throw(new Error("Illegal value for "+this.toString(true)+": "+value+" (required)")); + } + return null; + } + var i; + if (this.repeated && !skipRepeated) { // Repeated values as arrays + if (!ProtoBuf.Util.isArray(value)) { + value = [value]; + } + var res = []; + for (i=0; i>> 0; // Do not cast NaN as it'd become 0 + } + if (ProtoBuf.Long) { + // Signed 64bit + if (this.type == ProtoBuf.TYPES["int64"] || this.type == ProtoBuf.TYPES["sint64"] || this.type == ProtoBuf.TYPES["sfixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, false); + } + return value.unsigned ? value.toSigned() : value; + } + // Unsigned 64bit + if (this.type == ProtoBuf.TYPES["uint64"] || this.type == ProtoBuf.TYPES["fixed64"]) { + if (!(typeof value == 'object' && value instanceof ProtoBuf.Long)) { + return ProtoBuf.Long.fromNumber(value, true); + } + return value.unsigned ? value : value.toUnsigned(); + } + } + // Bool + if (this.type == ProtoBuf.TYPES["bool"]) { + if (typeof value === 'string') return value === 'true'; + else return !!value; + } + // Float + if (this.type == ProtoBuf.TYPES["float"] || this.type == ProtoBuf.TYPES["double"]) { + return parseFloat(value); // May also become NaN, +Infinity, -Infinity + } + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]) { + return ""+value; + } + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + if (value && value instanceof ByteBuffer) { + return value; + } + return ByteBuffer.wrap(value); + } + // Constant enum value + if (this.type == ProtoBuf.TYPES["enum"]) { + var values = this.resolvedType.getChildren(Enum.Value); + for (i=0; i 1) { // We need to move the contents + var contents = buffer.slice(start, buffer.offset); + start += varintLen-1; + buffer.offset = start; + buffer.append(contents); + } + buffer.writeVarint32(len, start-varintLen); + } else { + // "If your message definition has repeated elements (without the [packed=true] option), the encoded + // message has zero or more key-value pairs with the same tag number" + for (i=0; i value.length) { // Forgot to flip? + buffer = buffer.clone().flip(); + } + buffer.writeVarint32(value.remaining()); + buffer.append(value); + + // Embedded message + } else if (this.type == ProtoBuf.TYPES["message"]) { + var bb = new ByteBuffer().LE(); + this.resolvedType.encode(value, bb); + buffer.writeVarint32(bb.offset); + buffer.append(bb.flip()); + } else { + // We should never end here + throw(new Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)")); + } + return buffer; + }; + + /** + * Decode the field value from the specified buffer. + * @param {number} wireType Leading wire type + * @param {ByteBuffer} buffer ByteBuffer to decode from + * @param {boolean=} skipRepeated Whether to skip the repeated check or not. Defaults to false. + * @return {*} Decoded value + * @throws {Error} If the field cannot be decoded + * @expose + */ + Field.prototype.decode = function(wireType, buffer, skipRepeated) { + var value, nBytes; + if (wireType != this.type.wireType && (skipRepeated || (wireType != ProtoBuf.WIRE_TYPES.LDELIM || !this.repeated))) { + throw(new Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)")); + } + if (wireType == ProtoBuf.WIRE_TYPES.LDELIM && this.repeated && this.options["packed"]) { + if (!skipRepeated) { + nBytes = buffer.readVarint32(); + nBytes = buffer.offset + nBytes; // Limit + var values = []; + while (buffer.offset < nBytes) { + values.push(this.decode(this.type.wireType, buffer, true)); + } + return values; + } + // Read the next value otherwise... + + } + // 32bit signed varint + if (this.type == ProtoBuf.TYPES["int32"]) { + return buffer.readVarint32() | 0; + } + + // 32bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint32"]) { + return buffer.readVarint32() >>> 0; + } + + // 32bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint32"]) { + return buffer.readZigZagVarint32() | 0; + } + + // Fixed 32bit unsigned + if (this.type == ProtoBuf.TYPES["fixed32"]) { + return buffer.readUint32() >>> 0; + } + + // Fixed 32bit signed + if (this.type == ProtoBuf.TYPES["sfixed32"]) { + return buffer.readInt32() | 0; + } + + // 64bit signed varint + if (this.type == ProtoBuf.TYPES["int64"]) { + return buffer.readVarint64(); + } + + // 64bit unsigned varint + if (this.type == ProtoBuf.TYPES["uint64"]) { + return buffer.readVarint64().toUnsigned(); + } + + // 64bit signed varint zig-zag + if (this.type == ProtoBuf.TYPES["sint64"]) { + return buffer.readZigZagVarint64(); + } + + // Fixed 64bit unsigned + if (this.type == ProtoBuf.TYPES["fixed64"]) { + return buffer.readUint64(); + } + + // Fixed 64bit signed + if (this.type == ProtoBuf.TYPES["sfixed64"]) { + return buffer.readInt64(); + } + + // Bool varint + if (this.type == ProtoBuf.TYPES["bool"]) { + return !!buffer.readVarint32(); + } + + // Constant enum value varint) + if (this.type == ProtoBuf.TYPES["enum"]) { + return buffer.readVarint32(); // The following Builder.Message#set will already throw + } + + // 32bit float + if (this.type == ProtoBuf.TYPES["float"]) { + return buffer.readFloat(); + } + // 64bit float + if (this.type == ProtoBuf.TYPES["double"]) { + return buffer.readDouble(); + } + + // Length-delimited string + if (this.type == ProtoBuf.TYPES["string"]){ + return buffer.readVString(); + } + + // Length-delimited bytes + if (this.type == ProtoBuf.TYPES["bytes"]) { + nBytes = buffer.readVarint32(); + if (buffer.remaining() < nBytes) { + throw(new Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining())); + } + value = buffer.clone(); // Offset already set + value.length = value.offset+nBytes; + buffer.offset += nBytes; + return value; + } + + // Length-delimited embedded message + if (this.type == ProtoBuf.TYPES["message"]) { + nBytes = buffer.readVarint32(); + return this.resolvedType.decode(buffer, nBytes); + } + + // We should never end here + throw(new Error("[INTERNAL] Illegal wire type for "+this.toString(true)+": "+wireType)); + }; + + /** + * @alias ProtoBuf.Reflect.Message.Field + * @expose + */ + Reflect.Message.Field = Field; + + /** + * Constructs a new Enum. + * @exports ProtoBuf.Reflect.Enum + * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object + * @param {string} name Enum name + * @param {Object.=} options Enum options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Enum = function(parent, name, options) { + Namespace.call(this, parent, name, options); + + /** + * Runtime enum object. + * @type {Object.|null} + * @expose + */ + this.object = null; + }; + + // Extends Namespace + Enum.prototype = Object.create(Namespace.prototype); + + /** + * Builds this enum and returns the runtime counterpart. + * @return {Object} + * @expose + */ + Enum.prototype.build = function() { + var enm = {}; + var values = this.getChildren(Enum.Value); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Service = function(root, name, options) { + Namespace.call(this, root, name, options); + + /** + * Built runtime service class. + * @type {?function(new:ProtoBuf.Builder.Service)} + */ + this.clazz = null; + }; + + // Extends Namespace + Service.prototype = Object.create(Namespace.prototype); + + /** + * Builds the service and returns the runtime counterpart, which is a fully functional class. + * @see ProtoBuf.Builder.Service + * @param {boolean=} rebuild Whether to rebuild or not + * @return {Function} Service class + * @throws {Error} If the message cannot be built + * @expose + */ + Service.prototype.build = function(rebuild) { + if (this.clazz && !rebuild) return this.clazz; + return this.clazz = (function(ProtoBuf, T) { + + /** + * Constructs a new runtime Service. + * @name ProtoBuf.Builder.Service + * @param {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))=} rpcImpl RPC implementation receiving the method name and the message + * @class Barebone of all runtime services. + * @constructor + * @throws {Error} If the service cannot be created + */ + var Service = function(rpcImpl) { + ProtoBuf.Builder.Service.call(this); + + /** + * Service implementation. + * @name ProtoBuf.Builder.Service#rpcImpl + * @type {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} + * @expose + */ + this.rpcImpl = rpcImpl || function(name, msg, callback) { + // This is what a user has to implement: A function receiving the method name, the actual message to + // send (type checked) and the callback that's either provided with the error as its first + // argument or null and the actual response message. + setTimeout(callback.bind(this, new Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0); // Must be async! + }; + }; + + // Extends ProtoBuf.Builder.Service + Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype); + + if (Object.defineProperty) { + Object.defineProperty(Service, "$options", { + "value": T.buildOpt(), + "enumerable": false, + "configurable": false, + "writable": false + }); + Object.defineProperty(Service.prototype, "$options", { + "value": Service["$options"], + "enumerable": false, + "configurable": false, + "writable": false + }); + } + + /** + * Asynchronously performs an RPC call using the given RPC implementation. + * @name ProtoBuf.Builder.Service.[Method] + * @function + * @param {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} rpcImpl RPC implementation + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + /** + * Asynchronously performs an RPC call using the instance's RPC implementation. + * @name ProtoBuf.Builder.Service#[Method] + * @function + * @param {ProtoBuf.Builder.Message} req Request + * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving + * the error if any and the response either as a pre-parsed message or as its raw bytes + * @abstract + */ + + var rpc = T.getChildren(Reflect.Service.RPCMethod); + for (var i=0; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Method = function(svc, name, options) { + T.call(this, svc, name); + + /** + * Options. + * @type {Object.} + * @expose + */ + this.options = options || {}; + }; + + // Extends T + Method.prototype = Object.create(T.prototype); + + /** + * Builds the method's '$options' property. + * @name ProtoBuf.Reflect.Service.Method#buildOpt + * @function + * @return {Object.} + */ + Method.prototype.buildOpt = Namespace.prototype.buildOpt; + + /** + * @alias ProtoBuf.Reflect.Service.Method + * @expose + */ + Reflect.Service.Method = Method; + + /** + * RPC service method. + * @exports ProtoBuf.Reflect.Service.RPCMethod + * @param {!ProtoBuf.Reflect.Service} svc Service + * @param {string} name Method name + * @param {string} request Request message name + * @param {string} response Response message name + * @param {Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Service.Method + */ + var RPCMethod = function(svc, name, request, response, options) { + Method.call(this, svc, name, options); + + /** + * Request message name. + * @type {string} + * @expose + */ + this.requestName = request; + + /** + * Response message name. + * @type {string} + * @expose + */ + this.responseName = response; + + /** + * Resolved request message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedRequestType = null; + + /** + * Resolved response message type. + * @type {ProtoBuf.Reflect.Message} + * @expose + */ + this.resolvedResponseType = null; + }; + + // Extends Method + RPCMethod.prototype = Object.create(Method.prototype); + + /** + * @alias ProtoBuf.Reflect.Service.RPCMethod + * @expose + */ + Reflect.Service.RPCMethod = RPCMethod; + + return Reflect; +})(ProtoBuf); diff --git a/javascript/node_modules/protobufjs/src/ProtoBuf/Util.js b/javascript/node_modules/protobufjs/src/ProtoBuf/Util.js new file mode 100644 index 0000000..606c35e --- /dev/null +++ b/javascript/node_modules/protobufjs/src/ProtoBuf/Util.js @@ -0,0 +1,145 @@ +// #ifdef UNDEFINED +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +// #endif +/** + * @alias ProtoBuf.Util + * @expose + */ +ProtoBuf.Util = (function() { + "use strict"; + + // Object.create polyfill + // ref: https://developer.mozilla.org/de/docs/JavaScript/Reference/Global_Objects/Object/create + if (!Object.create) { + /** @expose */ + Object.create = function (o) { + if (arguments.length > 1) { + throw new Error('Object.create implementation only accepts the first parameter.'); + } + function F() {} + F.prototype = o; + return new F(); + }; + } + + /** + * ProtoBuf utilities. + * @exports ProtoBuf.Util + * @namespace + */ + var Util = {}; + + /** + * Flag if running in node or not. + * @type {boolean} + * @const + * @expose + */ + Util.IS_NODE = (typeof window === 'undefined' || !window.window) && typeof require === 'function' && typeof process !== 'undefined' && typeof process["nextTick"] === 'function'; + + /** + * Constructs a XMLHttpRequest object. + * @return {XMLHttpRequest} + * @throws {Error} If XMLHttpRequest is not supported + * @expose + */ + Util.XHR = function() { + // No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html + var XMLHttpFactories = [ + function () {return new XMLHttpRequest()}, + function () {return new ActiveXObject("Msxml2.XMLHTTP")}, + function () {return new ActiveXObject("Msxml3.XMLHTTP")}, + function () {return new ActiveXObject("Microsoft.XMLHTTP")} + ]; + /** @type {?XMLHttpRequest} */ + var xhr = null; + for (var i=0;i someField, reverted + required int32 someField = 2; // kept + + // Case 2: Revert 2nd + required int32 aField = 3; // kept + required int32 a_field = 4; // -> aField, reverted + + // No revert + required int32 its_a_field = 5; // -> itsAField + +} diff --git a/javascript/node_modules/protobufjs/tests/comments.proto b/javascript/node_modules/protobufjs/tests/comments.proto new file mode 100644 index 0000000..9f808f7 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/comments.proto @@ -0,0 +1,10 @@ +// single line comment + +/** + * Naranjas. + */ +message TestC { // one more + required /***** uncommon block ****/int32 a = 1; // another more +} + +// the end. \ No newline at end of file diff --git a/javascript/node_modules/protobufjs/tests/complex.json b/javascript/node_modules/protobufjs/tests/complex.json new file mode 100644 index 0000000..8a67a23 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/complex.json @@ -0,0 +1,123 @@ +{ + "package": "Game.Cars", + "messages": [ + { + "name": "Car", + "fields": [ + { + "rule": "required", + "type": "string", + "name": "model", + "id": 1, + "options": {} + }, + { + "rule": "required", + "type": "Vendor", + "name": "vendor", + "id": 2, + "options": {} + }, + { + "rule": "optional", + "type": "Speed", + "name": "speed", + "id": 3, + "options": { + "default": "FAST" + } + } + ], + "enums": [ + { + "name": "Speed", + "values": [ + { + "name": "FAST", + "id": 1 + }, + { + "name": "SUPERFAST", + "id": 2 + } + ], + "options": {} + } + ], + "messages": [ + { + "name": "Vendor", + "fields": [ + { + "rule": "required", + "type": "string", + "name": "name", + "id": 1, + "options": {} + }, + { + "rule": "optional", + "type": "Address", + "name": "address", + "id": 2, + "options": {} + } + ], + "enums": [], + "messages": [ + { + "name": "Address", + "fields": [ + { + "rule": "required", + "type": "string", + "name": "country", + "id": 1, + "options": {} + } + ], + "enums": [], + "messages": [], + "options": {} + } + ], + "options": {} + }, + { + "name": "Holder", + "fields": [ + { + "rule": "optional", + "type": "string", + "name": "first_name", + "id": 1, + "options": {} + }, + { + "rule": "required", + "type": "string", + "name": "last_name", + "id": 2, + "options": {} + }, + { + "rule": "optional", + "type": "Vendor.Address", + "name": "address", + "id": 3, + "options": {} + } + ], + "enums": [], + "messages": [], + "options": {} + } + ], + "options": {} + } + ], + "enums": [], + "imports": [], + "options": {}, + "services": [] +} diff --git a/javascript/node_modules/protobufjs/tests/complex.proto b/javascript/node_modules/protobufjs/tests/complex.proto new file mode 100644 index 0000000..a961bd8 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/complex.proto @@ -0,0 +1,34 @@ +package Game.Cars; + +// Car +message Car { + + // Car Vendor + message Vendor { + required string name = 1; + + // Car Vendor Address + message Address { + required string country = 1; + } + + optional Address address = 2; + } + + required string model = 1; // Model name + required Vendor vendor = 2; // Vendor information + optional Speed speed = 3 [default=FAST]; // Car speed + + // Car speed enum + enum Speed { + FAST = 1; + SUPERFAST = 2; + } + + // Car Holder + message Holder { + optional string first_name = 1; + required string last_name = 2; + optional Vendor.Address address = 3; + } +} diff --git a/javascript/node_modules/protobufjs/tests/custom-options.proto b/javascript/node_modules/protobufjs/tests/custom-options.proto new file mode 100644 index 0000000..01f9773 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/custom-options.proto @@ -0,0 +1,53 @@ +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FileOptions { + optional string my_file_option = 50000; +} +extend google.protobuf.MessageOptions { + optional int32 my_message_option = 50001; +} +extend google.protobuf.FieldOptions { + optional float my_field_option = 50002; +} +extend google.protobuf.EnumOptions { + optional bool my_enum_option = 50003; +} +extend google.protobuf.EnumValueOptions { + optional uint32 my_enum_value_option = 50004; +} +extend google.protobuf.ServiceOptions { + optional MyEnum my_service_option = 50005; +} +extend google.protobuf.MethodOptions { + optional MyMessage my_method_option = 50006; +} + +option (my_file_option) = "Hello world!"; + +message MyMessage { + option (my_message_option) = 1234; + + optional int32 foo = 1 [(my_field_option) = 4.5]; + optional string bar = 2; +} + +enum MyEnum { + option (my_enum_option) = true; + + FOO = 1 [(my_enum_value_option) = 321]; + BAR = 2; +} + +message RequestType {} +message ResponseType {} + +service MyService { + option (my_service_option) = FOO; + + rpc MyMethod(RequestType) returns(ResponseType) { + // Note: my_method_option has type MyMessage. We can set each field + // within it using a separate "option" line. + option (my_method_option).foo = 567; + option (my_method_option).bar = "Some string"; + } +} diff --git a/javascript/node_modules/protobufjs/tests/dupimport/dep1.proto b/javascript/node_modules/protobufjs/tests/dupimport/dep1.proto new file mode 100644 index 0000000..8ec2cee --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/dupimport/dep1.proto @@ -0,0 +1,6 @@ +package My; +import public "dep2.proto"; + +message dep1 { + optional dep2 test1 = 0; +} diff --git a/javascript/node_modules/protobufjs/tests/dupimport/dep2.proto b/javascript/node_modules/protobufjs/tests/dupimport/dep2.proto new file mode 100644 index 0000000..835661b --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/dupimport/dep2.proto @@ -0,0 +1,5 @@ +package My; + +message dep2 { + optional uint64 test1 = 0; +} diff --git a/javascript/node_modules/protobufjs/tests/dupimport/main.proto b/javascript/node_modules/protobufjs/tests/dupimport/main.proto new file mode 100644 index 0000000..69a245b --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/dupimport/main.proto @@ -0,0 +1,8 @@ +package My; +import public "dep1.proto"; +import public "dep2.proto"; + +message main { + optional dep1 test1 = 0; + optional dep2 test2 = 0; +} diff --git a/javascript/node_modules/protobufjs/tests/example1.proto b/javascript/node_modules/protobufjs/tests/example1.proto new file mode 100644 index 0000000..dd3c96e --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/example1.proto @@ -0,0 +1,5 @@ +message Test1 { + required int32 a = 1; +} + +// Test1 should encode to "08 96 01" with Test1#a=150 diff --git a/javascript/node_modules/protobufjs/tests/example1u.proto b/javascript/node_modules/protobufjs/tests/example1u.proto new file mode 100644 index 0000000..2b91e8b --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/example1u.proto @@ -0,0 +1,3 @@ +message Test1u { + required uint32 a = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/example2.proto b/javascript/node_modules/protobufjs/tests/example2.proto new file mode 100644 index 0000000..e00c4d2 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/example2.proto @@ -0,0 +1,5 @@ +message Test2 { + required string b = 2; +} + +// Test2 should encode to "12 07 74 65 73 74 69 6e 67" with Test2#b="testing" diff --git a/javascript/node_modules/protobufjs/tests/example3.proto b/javascript/node_modules/protobufjs/tests/example3.proto new file mode 100644 index 0000000..2ec5a97 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/example3.proto @@ -0,0 +1,9 @@ +message Test1 { + required int32 a = 1; +} + +message Test3 { + required Test1 c = 3; +} + +// Test3 should encode to "1a 03 08 96 01" with Test1#a=150 diff --git a/javascript/node_modules/protobufjs/tests/example4.proto b/javascript/node_modules/protobufjs/tests/example4.proto new file mode 100644 index 0000000..455ae94 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/example4.proto @@ -0,0 +1,5 @@ +message Test4 { + repeated int32 d = 4 [packed=true]; +} + +// Test4 should encode to "<22 06 03 8E 02 9E A7 05>" with d=[3, 270, 86942] diff --git a/javascript/node_modules/protobufjs/tests/extend.proto b/javascript/node_modules/protobufjs/tests/extend.proto new file mode 100644 index 0000000..504bb4f --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/extend.proto @@ -0,0 +1,19 @@ +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.MessageOptions { + optional int32 foo = 123; +} + +message Foo { + extensions 2 to max; +} + +extend Foo { + optional string bar = 2; +} + +message Bar { + extend Foo { + optional Bar bar2 = 3; + } +} diff --git a/javascript/node_modules/protobufjs/tests/google/protobuf/descriptor.proto b/javascript/node_modules/protobufjs/tests/google/protobuf/descriptor.proto new file mode 100644 index 0000000..83fe2e1 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/google/protobuf/descriptor.proto @@ -0,0 +1,620 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// The messages in this file describe the definitions found in .proto files. +// A valid .proto file can be translated directly to a FileDescriptorProto +// without any other information (e.g. without reading its imports). + + + +package google.protobuf; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DescriptorProtos"; + +// descriptor.proto must be optimized for speed because reflection-based +// algorithms don't work during bootstrapping. +option optimize_for = SPEED; + +// The protocol compiler can output a FileDescriptorSet containing the .proto +// files it parses. +message FileDescriptorSet { + repeated FileDescriptorProto file = 1; +} + +// Describes a complete .proto file. +message FileDescriptorProto { + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. + + // Names of files imported by this file. + repeated string dependency = 3; + // Indexes of the public imported files in the dependency list above. + repeated int32 public_dependency = 10; + // Indexes of the weak imported files in the dependency list. + // For Google-internal migration only. Do not use. + repeated int32 weak_dependency = 11; + + // All top-level definitions in this file. + repeated DescriptorProto message_type = 4; + repeated EnumDescriptorProto enum_type = 5; + repeated ServiceDescriptorProto service = 6; + repeated FieldDescriptorProto extension = 7; + + optional FileOptions options = 8; + + // This field contains optional information about the original source code. + // You may safely remove this entire field whithout harming runtime + // functionality of the descriptors -- the information is needed only by + // development tools. + optional SourceCodeInfo source_code_info = 9; +} + +// Describes a message type. +message DescriptorProto { + optional string name = 1; + + repeated FieldDescriptorProto field = 2; + repeated FieldDescriptorProto extension = 6; + + repeated DescriptorProto nested_type = 3; + repeated EnumDescriptorProto enum_type = 4; + + message ExtensionRange { + optional int32 start = 1; + optional int32 end = 2; + } + repeated ExtensionRange extension_range = 5; + + optional MessageOptions options = 7; +} + +// Describes a field within a message. +message FieldDescriptorProto { + enum Type { + // 0 is reserved for errors. + // Order is weird for historical reasons. + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + // negative values are likely. + TYPE_INT64 = 3; + TYPE_UINT64 = 4; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + // negative values are likely. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + TYPE_GROUP = 10; // Tag-delimited aggregate. + TYPE_MESSAGE = 11; // Length-delimited aggregate. + + // New in version 2. + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + }; + + enum Label { + // 0 is reserved for errors + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + // TODO(sanjay): Should we add LABEL_MAP? + }; + + optional string name = 1; + optional int32 number = 3; + optional Label label = 4; + + // If type_name is set, this need not be set. If both this and type_name + // are set, this must be either TYPE_ENUM or TYPE_MESSAGE. + optional Type type = 5; + + // For message and enum types, this is the name of the type. If the name + // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + // rules are used to find the type (i.e. first the nested types within this + // message are searched, then within the parent, on up to the root + // namespace). + optional string type_name = 6; + + // For extensions, this is the name of the type being extended. It is + // resolved in the same manner as type_name. + optional string extendee = 2; + + // For numeric types, contains the original text representation of the value. + // For booleans, "true" or "false". + // For strings, contains the default text contents (not escaped in any way). + // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + // TODO(kenton): Base-64 encode? + optional string default_value = 7; + + optional FieldOptions options = 8; +} + +// Describes an enum type. +message EnumDescriptorProto { + optional string name = 1; + + repeated EnumValueDescriptorProto value = 2; + + optional EnumOptions options = 3; +} + +// Describes a value within an enum. +message EnumValueDescriptorProto { + optional string name = 1; + optional int32 number = 2; + + optional EnumValueOptions options = 3; +} + +// Describes a service. +message ServiceDescriptorProto { + optional string name = 1; + repeated MethodDescriptorProto method = 2; + + optional ServiceOptions options = 3; +} + +// Describes a method of a service. +message MethodDescriptorProto { + optional string name = 1; + + // Input and output type names. These are resolved in the same way as + // FieldDescriptorProto.type_name, but must refer to a message type. + optional string input_type = 2; + optional string output_type = 3; + + optional MethodOptions options = 4; +} + + +// =================================================================== +// Options + +// Each of the definitions above may have "options" attached. These are +// just annotations which may cause code to be generated slightly differently +// or may contain hints for code that manipulates protocol messages. +// +// Clients may define custom options as extensions of the *Options messages. +// These extensions may not yet be known at parsing time, so the parser cannot +// store the values in them. Instead it stores them in a field in the *Options +// message called uninterpreted_option. This field must have the same name +// across all *Options messages. We then use this field to populate the +// extensions when we build a descriptor, at which point all protos have been +// parsed and so all extensions are known. +// +// Extension numbers for custom options may be chosen as follows: +// * For options which will only be used within a single application or +// organization, or for experimental options, use field numbers 50000 +// through 99999. It is up to you to ensure that you do not use the +// same number for multiple options. +// * For options which will be published and used publicly by multiple +// independent entities, e-mail protobuf-global-extension-registry@google.com +// to reserve extension numbers. Simply provide your project name (e.g. +// Object-C plugin) and your porject website (if available) -- there's no need +// to explain how you intend to use them. Usually you only need one extension +// number. You can declare multiple options with only one extension number by +// putting them in a sub-message. See the Custom Options section of the docs +// for examples: +// http://code.google.com/apis/protocolbuffers/docs/proto.html#options +// If this turns out to be popular, a web service will be set up +// to automatically assign option numbers. + + +message FileOptions { + + // Sets the Java package where classes generated from this .proto will be + // placed. By default, the proto package is used, but this is often + // inappropriate because proto packages do not normally start with backwards + // domain names. + optional string java_package = 1; + + + // If set, all the classes from the .proto file are wrapped in a single + // outer class with the given name. This applies to both Proto1 + // (equivalent to the old "--one_java_file" option) and Proto2 (where + // a .proto always translates to a single class, but you may want to + // explicitly choose the class name). + optional string java_outer_classname = 8; + + // If set true, then the Java code generator will generate a separate .java + // file for each top-level message, enum, and service defined in the .proto + // file. Thus, these types will *not* be nested inside the outer class + // named by java_outer_classname. However, the outer class will still be + // generated to contain the file's getDescriptor() method as well as any + // top-level extensions defined in the file. + optional bool java_multiple_files = 10 [default=false]; + + // If set true, then the Java code generator will generate equals() and + // hashCode() methods for all messages defined in the .proto file. This is + // purely a speed optimization, as the AbstractMessage base class includes + // reflection-based implementations of these methods. + optional bool java_generate_equals_and_hash = 20 [default=false]; + + // Generated classes can be optimized for speed or code size. + enum OptimizeMode { + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + } + optional OptimizeMode optimize_for = 9 [default=SPEED]; + + // Sets the Go package where structs generated from this .proto will be + // placed. There is no default. + optional string go_package = 11; + + + + // Should generic services be generated in each language? "Generic" services + // are not specific to any particular RPC system. They are generated by the + // main code generators in each language (without additional plugins). + // Generic services were the only kind of service generation supported by + // early versions of proto2. + // + // Generic services are now considered deprecated in favor of using plugins + // that generate code specific to your particular RPC system. Therefore, + // these default to false. Old code which depends on generic services should + // explicitly set them to true. + optional bool cc_generic_services = 16 [default=false]; + optional bool java_generic_services = 17 [default=false]; + optional bool py_generic_services = 18 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MessageOptions { + // Set true to use the old proto1 MessageSet wire format for extensions. + // This is provided for backwards-compatibility with the MessageSet wire + // format. You should not use this for any other reason: It's less + // efficient, has fewer features, and is more complicated. + // + // The message must be defined exactly as follows: + // message Foo { + // option message_set_wire_format = true; + // extensions 4 to max; + // } + // Note that the message cannot have any defined fields; MessageSets only + // have extensions. + // + // All extensions of your type must be singular messages; e.g. they cannot + // be int32s, enums, or repeated messages. + // + // Because this is an option, the above two restrictions are not enforced by + // the protocol compiler. + optional bool message_set_wire_format = 1 [default=false]; + + // Disables the generation of the standard "descriptor()" accessor, which can + // conflict with a field of the same name. This is meant to make migration + // from proto1 easier; new code should avoid fields named "descriptor". + optional bool no_standard_descriptor_accessor = 2 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message FieldOptions { + // The ctype option instructs the C++ code generator to use a different + // representation of the field than it normally would. See the specific + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; + enum CType { + // Default mode. + STRING = 0; + + CORD = 1; + + STRING_PIECE = 2; + } + // The packed option can be enabled for repeated primitive fields to enable + // a more efficient representation on the wire. Rather than repeatedly + // writing the tag and type for each element, the entire array is encoded as + // a single length-delimited blob. + optional bool packed = 2; + + + + // Should this field be parsed lazily? Lazy applies only to message-type + // fields. It means that when the outer message is initially parsed, the + // inner message's contents will not be parsed but instead stored in encoded + // form. The inner message will actually be parsed when it is first accessed. + // + // This is only a hint. Implementations are free to choose whether to use + // eager or lazy parsing regardless of the value of this option. However, + // setting this option true suggests that the protocol author believes that + // using lazy parsing on this field is worth the additional bookkeeping + // overhead typically needed to implement it. + // + // This option does not affect the public interface of any generated code; + // all method signatures remain the same. Furthermore, thread-safety of the + // interface is not affected by this option; const methods remain safe to + // call from multiple threads concurrently, while non-const methods continue + // to require exclusive access. + // + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outher message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. + optional bool lazy = 5 [default=false]; + + // Is this field deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for accessors, or it will be completely ignored; in the very least, this + // is a formalization for deprecating fields. + optional bool deprecated = 3 [default=false]; + + // EXPERIMENTAL. DO NOT USE. + // For "map" fields, the name of the field in the enclosed type that + // is the key for this map. For example, suppose we have: + // message Item { + // required string name = 1; + // required string value = 2; + // } + // message Config { + // repeated Item items = 1 [experimental_map_key="name"]; + // } + // In this situation, the map key for Item will be set to "name". + // TODO: Fully-implement this, then remove the "experimental_" prefix. + optional string experimental_map_key = 9; + + // For Google-internal migration only. Do not use. + optional bool weak = 10 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumOptions { + + // Set this option to false to disallow mapping different tag names to a same + // value. + optional bool allow_alias = 2 [default=true]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumValueOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message ServiceOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MethodOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + + +// A message representing a option the parser does not recognize. This only +// appears in options protos created by the compiler::Parser class. +// DescriptorPool resolves these when building Descriptor objects. Therefore, +// options protos in descriptor objects (e.g. returned by Descriptor::options(), +// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +// in them. +message UninterpretedOption { + // The name of the uninterpreted option. Each string represents a segment in + // a dot-separated name. is_extension is true iff a segment represents an + // extension (denoted with parentheses in options specs in .proto files). + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". + message NamePart { + required string name_part = 1; + required bool is_extension = 2; + } + repeated NamePart name = 2; + + // The value of the uninterpreted option, in whatever type the tokenizer + // identified it as during parsing. Exactly one of these should be set. + optional string identifier_value = 3; + optional uint64 positive_int_value = 4; + optional int64 negative_int_value = 5; + optional double double_value = 6; + optional bytes string_value = 7; + optional string aggregate_value = 8; +} + +// =================================================================== +// Optional source code info + +// Encapsulates information about the original source file from which a +// FileDescriptorProto was generated. +message SourceCodeInfo { + // A Location identifies a piece of source code in a .proto file which + // corresponds to a particular definition. This information is intended + // to be useful to IDEs, code indexers, documentation generators, and similar + // tools. + // + // For example, say we have a file like: + // message Foo { + // optional string foo = 1; + // } + // Let's look at just the field definition: + // optional string foo = 1; + // ^ ^^ ^^ ^ ^^^ + // a bc de f ghi + // We have the following locations: + // span path represents + // [a,i) [ 4, 0, 2, 0 ] The whole field definition. + // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + // + // Notes: + // - A location may refer to a repeated field itself (i.e. not to any + // particular index within it). This is used whenever a set of elements are + // logically enclosed in a single code segment. For example, an entire + // extend block (possibly containing multiple extension definitions) will + // have an outer location whose path refers to the "extensions" repeated + // field without an index. + // - Multiple locations may have the same path. This happens when a single + // logical declaration is spread out across multiple places. The most + // obvious example is the "extend" block again -- there may be multiple + // extend blocks in the same scope, each of which will have the same path. + // - A location's span is not always a subset of its parent's span. For + // example, the "extendee" of an extension declaration appears at the + // beginning of the "extend" block and is shared by all extensions within + // the block. + // - Just because a location's span is a subset of some other location's span + // does not mean that it is a descendent. For example, a "group" defines + // both a type and a field in a single declaration. Thus, the locations + // corresponding to the type and field and their components will overlap. + // - Code which tries to interpret locations should probably be designed to + // ignore those that it doesn't understand, as more types of locations could + // be recorded in the future. + repeated Location location = 1; + message Location { + // Identifies which part of the FileDescriptorProto was defined at this + // location. + // + // Each element is a field number or an index. They form a path from + // the root FileDescriptorProto to the place where the definition. For + // example, this path: + // [ 4, 3, 2, 7, 1 ] + // refers to: + // file.message_type(3) // 4, 3 + // .field(7) // 2, 7 + // .name() // 1 + // This is because FileDescriptorProto.message_type has field number 4: + // repeated DescriptorProto message_type = 4; + // and DescriptorProto.field has field number 2: + // repeated FieldDescriptorProto field = 2; + // and FieldDescriptorProto.name has field number 1: + // optional string name = 1; + // + // Thus, the above path gives the location of a field name. If we removed + // the last element: + // [ 4, 3, 2, 7 ] + // this path refers to the whole field declaration (from the beginning + // of the label to the terminating semicolon). + repeated int32 path = 1 [packed=true]; + + // Always has exactly three or four elements: start line, start column, + // end line (optional, otherwise assumed same as start line), end column. + // These are packed into a single field for efficiency. Note that line + // and column numbers are zero-based -- typically you will want to add + // 1 to each before displaying to a user. + repeated int32 span = 2 [packed=true]; + + // If this SourceCodeInfo represents a complete declaration, these are any + // comments appearing before and after the declaration which appear to be + // attached to the declaration. + // + // A series of line comments appearing on consecutive lines, with no other + // tokens appearing on those lines, will be treated as a single comment. + // + // Only the comment content is provided; comment markers (e.g. //) are + // stripped out. For block comments, leading whitespace and an asterisk + // will be stripped from the beginning of each line other than the first. + // Newlines are included in the output. + // + // Examples: + // + // optional int32 foo = 1; // Comment attached to foo. + // // Comment attached to bar. + // optional int32 bar = 2; + // + // optional string baz = 3; + // // Comment attached to baz. + // // Another line attached to baz. + // + // // Comment attached to qux. + // // + // // Another line attached to qux. + // optional double qux = 4; + // + // optional string corge = 5; + // /* Block comment attached + // * to corge. Leading asterisks + // * will be removed. */ + // /* Block comment attached to + // * grault. */ + // optional int32 grault = 6; + optional string leading_comments = 3; + optional string trailing_comments = 4; + } +} diff --git a/javascript/node_modules/protobufjs/tests/gtfs-realtime.proto b/javascript/node_modules/protobufjs/tests/gtfs-realtime.proto new file mode 100644 index 0000000..252e07f --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/gtfs-realtime.proto @@ -0,0 +1,552 @@ +// Copyright 2011 Google Inc +// +// The content of this file is licensed under the Creative Commons Attribution +// 3.0 License. +// +// Protocol definition file for GTFS-realtime. +// +// GTFS-realtime lets transit agencies provide consumers with realtime +// information about disruptions to their service (stations closed, lines not +// operating, important delays etc), location of their vehicles and expected +// arrival times. +// +// This protocol is published at: +// http://developers.google.com/transit/gtfs-realtime/ + +syntax = "proto2"; + +option java_package = "com.google.transit.realtime"; +package transit_realtime; + +// The contents of a feed message. +// A feed is a continuous stream of feed messages. Each message in the stream is +// obtained as a response to an appropriate HTTP GET request. +// A realtime feed is always defined with relation to an existing GTFS feed. +// All the entity ids are resolved with respect to the GTFS feed. +// +// A feed depends on some external configuration: +// - The corresponding GTFS feed. +// - Feed application (updates, positions or alerts). A feed should contain only +// items of one specified application; all the other entities will be ignored. +// - Polling frequency +message FeedMessage { + // Metadata about this feed and feed message. + required FeedHeader header = 1; + + // Contents of the feed. + repeated FeedEntity entity = 2; +} + +// Metadata about a feed, included in feed messages. +message FeedHeader { + // Version of the feed specification. + // The current version is 1.0. + required string gtfs_realtime_version = 1; + + // Determines whether the current fetch is incremental. Currently, + // DIFFERENTIAL mode is unsupported and behavior is unspecified for feeds + // that use this mode. There are discussions on the GTFS-realtime mailing + // list around fully specifying the behavior of DIFFERENTIAL mode and the + // documentation will be updated when those discussions are finalized. + enum Incrementality { + FULL_DATASET = 0; + DIFFERENTIAL = 1; + } + optional Incrementality incrementality = 2 [default = FULL_DATASET]; + + // This timestamp identifies the moment when the content of this feed has been + // created (in server time). In POSIX time (i.e., number of seconds since + // January 1st 1970 00:00:00 UTC). + optional uint64 timestamp = 3; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features and + // modifications to the spec. + extensions 1000 to 1999; +} + +// A definition (or update) of an entity in the transit feed. +message FeedEntity { + // The ids are used only to provide incrementality support. The id should be + // unique within a FeedMessage. Consequent FeedMessages may contain + // FeedEntities with the same id. In case of a DIFFERENTIAL update the new + // FeedEntity with some id will replace the old FeedEntity with the same id + // (or delete it - see is_deleted below). + // The actual GTFS entities (e.g. stations, routes, trips) referenced by the + // feed must be specified by explicit selectors (see EntitySelector below for + // more info). + required string id = 1; + + // Whether this entity is to be deleted. Relevant only for incremental + // fetches. + optional bool is_deleted = 2 [default = false]; + + // Data about the entity itself. Exactly one of the following fields must be + // present (unless the entity is being deleted). + optional TripUpdate trip_update = 3; + optional VehiclePosition vehicle = 4; + optional Alert alert = 5; +} + +// +// Entities used in the feed. +// + +// Realtime update of the progress of a vehicle along a trip. +// Depending on the value of ScheduleRelationship, a TripUpdate can specify: +// - A trip that proceeds along the schedule. +// - A trip that proceeds along a route but has no fixed schedule. +// - A trip that have been added or removed with regard to schedule. +// +// The updates can be for future, predicted arrival/departure events, or for +// past events that already occurred. +// Normally, updates should get more precise and more certain (see +// uncertainty below) as the events gets closer to current time. +// Even if that is not possible, the information for past events should be +// precise and certain. In particular, if an update points to time in the past +// but its update's uncertainty is not 0, the client should conclude that the +// update is a (wrong) prediction and that the trip has not completed yet. +// +// Note that the update can describe a trip that is already completed. +// To this end, it is enough to provide an update for the last stop of the trip. +// If the time of that is in the past, the client will conclude from that that +// the whole trip is in the past (it is possible, although inconsequential, to +// also provide updates for preceding stops). +// This option is most relevant for a trip that has completed ahead of schedule, +// but according to the schedule, the trip is still proceeding at the current +// time. Removing the updates for this trip could make the client assume +// that the trip is still proceeding. +// Note that the feed provider is allowed, but not required, to purge past +// updates - this is one case where this would be practically useful. +message TripUpdate { + // The Trip that this message applies to. There can be at most one + // TripUpdate entity for each actual trip instance. + // If there is none, that means there is no prediction information available. + // It does *not* mean that the trip is progressing according to schedule. + required TripDescriptor trip = 1; + + // Additional information on the vehicle that is serving this trip. + optional VehicleDescriptor vehicle = 3; + + // Timing information for a single predicted event (either arrival or + // departure). + // Timing consists of delay and/or estimated time, and uncertainty. + // - delay should be used when the prediction is given relative to some + // existing schedule in GTFS. + // - time should be given whether there is a predicted schedule or not. If + // both time and delay are specified, time will take precedence + // (although normally, time, if given for a scheduled trip, should be + // equal to scheduled time in GTFS + delay). + // + // Uncertainty applies equally to both time and delay. + // The uncertainty roughly specifies the expected error in true delay (but + // note, we don't yet define its precise statistical meaning). It's possible + // for the uncertainty to be 0, for example for trains that are driven under + // computer timing control. + message StopTimeEvent { + // Delay (in seconds) can be positive (meaning that the vehicle is late) or + // negative (meaning that the vehicle is ahead of schedule). Delay of 0 + // means that the vehicle is exactly on time. + optional int32 delay = 1; + + // Event as absolute time. + // In Unix time (i.e., number of seconds since January 1st 1970 00:00:00 + // UTC). + optional int64 time = 2; + + // If uncertainty is omitted, it is interpreted as unknown. + // If the prediction is unknown or too uncertain, the delay (or time) field + // should be empty. In such case, the uncertainty field is ignored. + // To specify a completely certain prediction, set its uncertainty to 0. + optional int32 uncertainty = 3; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; + } + + // Realtime update for arrival and/or departure events for a given stop on a + // trip. Updates can be supplied for both past and future events. + // The producer is allowed, although not required, to drop past events. + message StopTimeUpdate { + // The update is linked to a specific stop either through stop_sequence or + // stop_id, so one of the fields below must necessarily be set. + // See the documentation in TripDescriptor for more information. + + // Must be the same as in stop_times.txt in the corresponding GTFS feed. + optional uint32 stop_sequence = 1; + // Must be the same as in stops.txt in the corresponding GTFS feed. + optional string stop_id = 4; + + optional StopTimeEvent arrival = 2; + optional StopTimeEvent departure = 3; + + // The relation between this StopTime and the static schedule. + enum ScheduleRelationship { + // The vehicle is proceeding in accordance with its static schedule of + // stops, although not necessarily according to the times of the schedule. + // At least one of arrival and departure must be provided. If the schedule + // for this stop contains both arrival and departure times then so must + // this update. An update with only an arrival, say, where the schedule + // has both, indicates that the trip is terminating early at this stop. + SCHEDULED = 0; + + // The stop is skipped, i.e., the vehicle will not stop at this stop. + // Arrival and departure are optional. + SKIPPED = 1; + + // No data is given for this stop. The main intention for this value is to + // give the predictions only for part of a trip, i.e., if the last update + // for a trip has a NO_DATA specifier, then StopTimes for the rest of the + // stops in the trip are considered to be unspecified as well. + // Neither arrival nor departure should be supplied. + NO_DATA = 2; + } + optional ScheduleRelationship schedule_relationship = 5 + [default = SCHEDULED]; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; + } + + // Updates to StopTimes for the trip (both future, i.e., predictions, and in + // some cases, past ones, i.e., those that already happened). + // The updates must be sorted by stop_sequence, and apply for all the + // following stops of the trip up to the next specified one. + // + // Example 1: + // For a trip with 20 stops, a StopTimeUpdate with arrival delay and departure + // delay of 0 for stop_sequence of the current stop means that the trip is + // exactly on time. + // + // Example 2: + // For the same trip instance, 3 StopTimeUpdates are provided: + // - delay of 5 min for stop_sequence 3 + // - delay of 1 min for stop_sequence 8 + // - delay of unspecified duration for stop_sequence 10 + // This will be interpreted as: + // - stop_sequences 3,4,5,6,7 have delay of 5 min. + // - stop_sequences 8,9 have delay of 1 min. + // - stop_sequences 10,... have unknown delay. + repeated StopTimeUpdate stop_time_update = 2; + + // Moment at which the vehicle's real-time progress was measured. In POSIX + // time (i.e., the number of seconds since January 1st 1970 00:00:00 UTC). + optional uint64 timestamp = 4; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features and + // modifications to the spec. + extensions 1000 to 1999; +} + +// Realtime positioning information for a given vehicle. +message VehiclePosition { + // The Trip that this vehicle is serving. + // Can be empty or partial if the vehicle can not be identified with a given + // trip instance. + optional TripDescriptor trip = 1; + + // Additional information on the vehicle that is serving this trip. + optional VehicleDescriptor vehicle = 8; + + // Current position of this vehicle. + optional Position position = 2; + + // The stop sequence index of the current stop. The meaning of + // current_stop_sequence (i.e., the stop that it refers to) is determined by + // current_status. + // If current_status is missing IN_TRANSIT_TO is assumed. + optional uint32 current_stop_sequence = 3; + // Identifies the current stop. The value must be the same as in stops.txt in + // the corresponding GTFS feed. + optional string stop_id = 7; + + enum VehicleStopStatus { + // The vehicle is just about to arrive at the stop (on a stop + // display, the vehicle symbol typically flashes). + INCOMING_AT = 0; + + // The vehicle is standing at the stop. + STOPPED_AT = 1; + + // The vehicle has departed and is in transit to the next stop. + IN_TRANSIT_TO = 2; + } + // The exact status of the vehicle with respect to the current stop. + // Ignored if current_stop_sequence is missing. + optional VehicleStopStatus current_status = 4 [default = IN_TRANSIT_TO]; + + // Moment at which the vehicle's position was measured. In POSIX time + // (i.e., number of seconds since January 1st 1970 00:00:00 UTC). + optional uint64 timestamp = 5; + + // Congestion level that is affecting this vehicle. + enum CongestionLevel { + UNKNOWN_CONGESTION_LEVEL = 0; + RUNNING_SMOOTHLY = 1; + STOP_AND_GO = 2; + CONGESTION = 3; + SEVERE_CONGESTION = 4; // People leaving their cars. + } + optional CongestionLevel congestion_level = 6; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// An alert, indicating some sort of incident in the public transit network. +message Alert { + // Time when the alert should be shown to the user. If missing, the + // alert will be shown as long as it appears in the feed. + // If multiple ranges are given, the alert will be shown during all of them. + repeated TimeRange active_period = 1; + + // Entities whose users we should notify of this alert. + repeated EntitySelector informed_entity = 5; + + // Cause of this alert. + enum Cause { + UNKNOWN_CAUSE = 1; + OTHER_CAUSE = 2; // Not machine-representable. + TECHNICAL_PROBLEM = 3; + STRIKE = 4; // Public transit agency employees stopped working. + DEMONSTRATION = 5; // People are blocking the streets. + ACCIDENT = 6; + HOLIDAY = 7; + WEATHER = 8; + MAINTENANCE = 9; + CONSTRUCTION = 10; + POLICE_ACTIVITY = 11; + MEDICAL_EMERGENCY = 12; + } + optional Cause cause = 6 [default = UNKNOWN_CAUSE]; + + // What is the effect of this problem on the affected entity. + enum Effect { + NO_SERVICE = 1; + REDUCED_SERVICE = 2; + + // We don't care about INsignificant delays: they are hard to detect, have + // little impact on the user, and would clutter the results as they are too + // frequent. + SIGNIFICANT_DELAYS = 3; + + DETOUR = 4; + ADDITIONAL_SERVICE = 5; + MODIFIED_SERVICE = 6; + OTHER_EFFECT = 7; + UNKNOWN_EFFECT = 8; + STOP_MOVED = 9; + } + optional Effect effect = 7 [default = UNKNOWN_EFFECT]; + + // The URL which provides additional information about the alert. + optional TranslatedString url = 8; + + // Alert header. Contains a short summary of the alert text as plain-text. + optional TranslatedString header_text = 10; + + // Full description for the alert as plain-text. The information in the + // description should add to the information of the header. + optional TranslatedString description_text = 11; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// +// Low level data structures used above. +// + +// A time interval. The interval is considered active at time 't' if 't' is +// greater than or equal to the start time and less than the end time. +message TimeRange { + // Start time, in POSIX time (i.e., number of seconds since January 1st 1970 + // 00:00:00 UTC). + // If missing, the interval starts at minus infinity. + optional uint64 start = 1; + + // End time, in POSIX time (i.e., number of seconds since January 1st 1970 + // 00:00:00 UTC). + // If missing, the interval ends at plus infinity. + optional uint64 end = 2; +} + +// A position. +message Position { + // Degrees North, in the WGS-84 coordinate system. + required float latitude = 1; + + // Degrees East, in the WGS-84 coordinate system. + required float longitude = 2; + + // Bearing, in degrees, clockwise from North, i.e., 0 is North and 90 is East. + // This can be the compass bearing, or the direction towards the next stop + // or intermediate location. + // This should not be direction deduced from the sequence of previous + // positions, which can be computed from previous data. + optional float bearing = 3; + + // Odometer value, in meters. + optional double odometer = 4; + // Momentary speed measured by the vehicle, in meters per second. + optional float speed = 5; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// A descriptor that identifies an instance of a GTFS trip, or all instances of +// a trip along a route. +// - To specify a single trip instance, the trip_id (and if necessary, +// start_time) is set. If route_id is also set, then it should be same as one +// that the given trip corresponds to. +// - To specify all the trips along a given route, only the route_id should be +// set. Note that if the trip_id is not known, then stop sequence ids in +// TripUpdate are not sufficient, and stop_ids must be provided as well. In +// addition, absolute arrival/departure times must be provided. +message TripDescriptor { + // The trip_id from the GTFS feed that this selector refers to. + // For non frequency expanded trips, this field is enough to uniquely identify + // the trip. For frequency expanded, start_time and start_date might also be + // necessary. + optional string trip_id = 1; + + // The route_id from the GTFS that this selector refers to. + optional string route_id = 5; + + // The scheduled start time of this trip instance. + // This field should be given only if the trip is frequency-expanded in the + // GTFS feed. The value must precisely correspond to start_time specified for + // the route in the GTFS feed plus some multiple of headway_secs. + // Format of the field is same as that of GTFS/frequencies.txt/start_time, + // e.g., 11:15:35 or 25:15:35. + optional string start_time = 2; + + // The scheduled start date of this trip instance. + // Must be provided to disambiguate trips that are so late as to collide with + // a scheduled trip on a next day. For example, for a train that departs 8:00 + // and 20:00 every day, and is 12 hours late, there would be two distinct + // trips on the same time. + // This field can be provided but is not mandatory for schedules in which such + // collisions are impossible - for example, a service running on hourly + // schedule where a vehicle that is one hour late is not considered to be + // related to schedule anymore. + // In YYYYMMDD format. + optional string start_date = 3; + + // The relation between this trip and the static schedule. If a trip is done + // in accordance with temporary schedule, not reflected in GTFS, then it + // shouldn't be marked as SCHEDULED, but likely as ADDED. + enum ScheduleRelationship { + // Trip that is running in accordance with its GTFS schedule, or is close + // enough to the scheduled trip to be associated with it. + SCHEDULED = 0; + + // An extra trip that was added in addition to a running schedule, for + // example, to replace a broken vehicle or to respond to sudden passenger + // load. + ADDED = 1; + + // A trip that is running with no schedule associated to it, for example, if + // there is no schedule at all. + UNSCHEDULED = 2; + + // A trip that existed in the schedule but was removed. + CANCELED = 3; + + // A trip that replaces a portion of static schedule. + // If the trip selector identifies a certain trip instance, then only that + // instance is replaced. If the selector identifies a route, then all the + // trips along that route are replaced. + // + // The replacement applies only to the portion of the trip supplied. For + // instance, consider a route that goes through stops A,B,C,D,E,F, and a + // REPLACEMENT trip provides data for stops A,B,C. Then, the times for stops + // D,E,F are still taken from the static schedule. + // + // A feed might supply several REPLACEMENT trips. In this case, the portion + // of static schedule that is replaced is the union of what is defined by + // all the feeds. Normally, all the REPLACEMENT trips should either + // correspond to the same route or to individual trip instances. + REPLACEMENT = 5; + } + optional ScheduleRelationship schedule_relationship = 4; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// Identification information for the vehicle performing the trip. +message VehicleDescriptor { + // Internal system identification of the vehicle. Should be unique per + // vehicle, and can be used for tracking the vehicle as it proceeds through + // the system. + optional string id = 1; + + // User visible label, i.e., something that must be shown to the passenger to + // help identify the correct vehicle. + optional string label = 2; + + // The license plate of the vehicle. + optional string license_plate = 3; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// A selector for an entity in a GTFS feed. +message EntitySelector { + // The values of the fields should correspond to the appropriate fields in the + // GTFS feed. + // At least one specifier must be given. If several are given, then the + // matching has to apply to all the given specifiers. + optional string agency_id = 1; + optional string route_id = 2; + // corresponds to route_type in GTFS. + optional int32 route_type = 3; + optional TripDescriptor trip = 4; + optional string stop_id = 5; + + // The extensions namespace allows 3rd-party developers to extend the + // GTFS-realtime specification in order to add and evaluate new features + // and modifications to the spec. + extensions 1000 to 1999; +} + +// An internationalized message containing per-language versions of a snippet of +// text or a URL. +// One of the strings from a message will be picked up. The resolution proceeds +// as follows: +// 1. If the UI language matches the language code of a translation, +// the first matching translation is picked. +// 2. If a default UI language (e.g., English) matches the language code of a +// translation, the first matching translation is picked. +// 3. If some translation has an unspecified language code, that translation is +// picked. +message TranslatedString { + message Translation { + // A UTF-8 string containing the message. + required string text = 1; + // BCP-47 language code. Can be omitted if the language is unknown or if + // no i18n is done at all for the feed. At most one translation is + // allowed to have an unspecified language tag. + optional string language = 2; + } + // At least one translation must be provided. + repeated Translation translation = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/importRoot/file1.proto b/javascript/node_modules/protobufjs/tests/importRoot/file1.proto new file mode 100644 index 0000000..eaf02ee --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/importRoot/file1.proto @@ -0,0 +1 @@ +import "importRoot/file2.proto"; diff --git a/javascript/node_modules/protobufjs/tests/importRoot/file2.proto b/javascript/node_modules/protobufjs/tests/importRoot/file2.proto new file mode 100644 index 0000000..44c7794 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/importRoot/file2.proto @@ -0,0 +1 @@ +import "importRoot/file3.proto"; diff --git a/javascript/node_modules/protobufjs/tests/importRoot/file3.proto b/javascript/node_modules/protobufjs/tests/importRoot/file3.proto new file mode 100644 index 0000000..24377d9 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/importRoot/file3.proto @@ -0,0 +1 @@ +message Test {} diff --git a/javascript/node_modules/protobufjs/tests/import_a.proto b/javascript/node_modules/protobufjs/tests/import_a.proto new file mode 100644 index 0000000..f50242f --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/import_a.proto @@ -0,0 +1,5 @@ +import "import_common.proto"; + +message A { + optional Common common = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/import_b.proto b/javascript/node_modules/protobufjs/tests/import_b.proto new file mode 100644 index 0000000..4809bfd --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/import_b.proto @@ -0,0 +1,5 @@ +import "import_common.proto"; + +message B { + optional Common common = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/import_common.proto b/javascript/node_modules/protobufjs/tests/import_common.proto new file mode 100644 index 0000000..ad9bfe7 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/import_common.proto @@ -0,0 +1,2 @@ +message Common { +} diff --git a/javascript/node_modules/protobufjs/tests/imports-toplevel.proto b/javascript/node_modules/protobufjs/tests/imports-toplevel.proto new file mode 100644 index 0000000..ebca0ff --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/imports-toplevel.proto @@ -0,0 +1,13 @@ +import "toplevel.proto"; + +package My; + +enum MyEnum1 { + ONE = 1; + TWO = 2; +} + +message Test1 { + required MyEnum num = 1 [default=ONE]; + required MyEnum1 num1 = 2 [default=ONE]; +} diff --git a/javascript/node_modules/protobufjs/tests/imports.proto b/javascript/node_modules/protobufjs/tests/imports.proto new file mode 100644 index 0000000..2246aac --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/imports.proto @@ -0,0 +1,9 @@ +package My; + +import public "example1.proto"; +import "example2.proto"; + +message Test2 { + required Test1 test1 = 1; + required .Test2 test2 = 2; +} diff --git a/javascript/node_modules/protobufjs/tests/inner.proto b/javascript/node_modules/protobufjs/tests/inner.proto new file mode 100644 index 0000000..c750f28 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/inner.proto @@ -0,0 +1,10 @@ +message Foo { + required Bar bar = 1; + required Baz baz = 2; +} +message Bar { + required string blah = 1; +} +message Baz { + required string blah = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/negid.proto b/javascript/node_modules/protobufjs/tests/negid.proto new file mode 100644 index 0000000..9b6a2ec --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/negid.proto @@ -0,0 +1,9 @@ +message Test { + required LobbyType type = 1 [default=INVALID]; + + enum LobbyType { + INVALID = -1; + MATCH = 0; + PRACTICE = 1; + } +} diff --git a/javascript/node_modules/protobufjs/tests/nodeunit-browser/LICENSE b/javascript/node_modules/protobufjs/tests/nodeunit-browser/LICENSE new file mode 100644 index 0000000..5dfdc43 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/nodeunit-browser/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2010 Caolan McMahon + +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. diff --git a/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.css b/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.css new file mode 100644 index 0000000..274434a --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.css @@ -0,0 +1,70 @@ +/*! + * Styles taken from qunit.css + */ + +h1#nodeunit-header, h1.nodeunit-header { + padding: 15px; + font-size: large; + background-color: #06b; + color: white; + font-family: 'trebuchet ms', verdana, arial; + margin: 0; +} + +h1#nodeunit-header a { + color: white; +} + +h2#nodeunit-banner { + height: 2em; + border-bottom: 1px solid white; + background-color: #eee; + margin: 0; + font-family: 'trebuchet ms', verdana, arial; +} +h2#nodeunit-banner.pass { + background-color: green; +} +h2#nodeunit-banner.fail { + background-color: red; +} + +h2#nodeunit-userAgent, h2.nodeunit-userAgent { + padding: 10px; + background-color: #eee; + color: black; + margin: 0; + font-size: small; + font-weight: normal; + font-family: 'trebuchet ms', verdana, arial; + font-size: 10pt; +} + +div#nodeunit-testrunner-toolbar { + background: #eee; + border-top: 1px solid black; + padding: 10px; + font-family: 'trebuchet ms', verdana, arial; + margin: 0; + font-size: 10pt; +} + +ol#nodeunit-tests { + font-family: 'trebuchet ms', verdana, arial; + font-size: 10pt; +} +ol#nodeunit-tests li strong { + cursor:pointer; +} +ol#nodeunit-tests .pass { + color: green; +} +ol#nodeunit-tests .fail { + color: red; +} + +p#nodeunit-testresult { + margin-left: 1em; + font-size: 10pt; + font-family: 'trebuchet ms', verdana, arial; +} diff --git a/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.js b/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.js new file mode 100644 index 0000000..2b0ea80 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/nodeunit-browser/nodeunit.js @@ -0,0 +1,2108 @@ +/*! + * Nodeunit + * https://github.com/caolan/nodeunit + * Copyright (c) 2010 Caolan McMahon + * MIT Licensed + * + * json2.js + * http://www.JSON.org/json2.js + * Public Domain. + * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + */ +nodeunit = (function(){ +/* + http://www.JSON.org/json2.js + 2010-11-17 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. + + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array of strings. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the value + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array of strings, then it will be + used to select the members to be serialized. It filters the results + such that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + var a; + if (typeof value === 'string') { + a = +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + var d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. +*/ + +/*jslint evil: true, strict: false, regexp: false */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +var JSON = {}; + +(function () { + "use strict"; + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return isFinite(this.valueOf()) ? + this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z' : null; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? + '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : + '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : + gap ? '[\n' + gap + + partial.join(',\n' + gap) + '\n' + + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + k = rep[i]; + if (typeof k === 'string') { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + + mind + '}' : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/ +.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') +.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') +.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}()); +var assert = this.assert = {}; +var types = {}; +var core = {}; +var nodeunit = {}; +var reporter = {}; +/*global setTimeout: false, console: false */ +(function () { + + var async = {}; + + // global on the server, window in the browser + var root = this, + previous_async = root.async; + + if (typeof module !== 'undefined' && module.exports) { + module.exports = async; + } + else { + root.async = async; + } + + async.noConflict = function () { + root.async = previous_async; + return async; + }; + + //// cross-browser compatiblity functions //// + + var _forEach = function (arr, iterator) { + if (arr.forEach) { + return arr.forEach(iterator); + } + for (var i = 0; i < arr.length; i += 1) { + iterator(arr[i], i, arr); + } + }; + + var _map = function (arr, iterator) { + if (arr.map) { + return arr.map(iterator); + } + var results = []; + _forEach(arr, function (x, i, a) { + results.push(iterator(x, i, a)); + }); + return results; + }; + + var _reduce = function (arr, iterator, memo) { + if (arr.reduce) { + return arr.reduce(iterator, memo); + } + _forEach(arr, function (x, i, a) { + memo = iterator(memo, x, i, a); + }); + return memo; + }; + + var _keys = function (obj) { + if (Object.keys) { + return Object.keys(obj); + } + var keys = []; + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + keys.push(k); + } + } + return keys; + }; + + var _indexOf = function (arr, item) { + if (arr.indexOf) { + return arr.indexOf(item); + } + for (var i = 0; i < arr.length; i += 1) { + if (arr[i] === item) { + return i; + } + } + return -1; + }; + + //// exported async module functions //// + + //// nextTick implementation with browser-compatible fallback //// + if (typeof process === 'undefined' || !(process.nextTick)) { + async.nextTick = function (fn) { + setTimeout(fn, 0); + }; + } + else { + async.nextTick = process.nextTick; + } + + async.forEach = function (arr, iterator, callback) { + if (!arr.length) { + return callback(); + } + var completed = 0; + _forEach(arr, function (x) { + iterator(x, function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + completed += 1; + if (completed === arr.length) { + callback(); + } + } + }); + }); + }; + + async.forEachSeries = function (arr, iterator, callback) { + if (!arr.length) { + return callback(); + } + var completed = 0; + var iterate = function () { + iterator(arr[completed], function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + completed += 1; + if (completed === arr.length) { + callback(); + } + else { + iterate(); + } + } + }); + }; + iterate(); + }; + + + var doParallel = function (fn) { + return function () { + var args = Array.prototype.slice.call(arguments); + return fn.apply(null, [async.forEach].concat(args)); + }; + }; + var doSeries = function (fn) { + return function () { + var args = Array.prototype.slice.call(arguments); + return fn.apply(null, [async.forEachSeries].concat(args)); + }; + }; + + + var _asyncMap = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (err, v) { + results[x.index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + }; + async.map = doParallel(_asyncMap); + async.mapSeries = doSeries(_asyncMap); + + + // reduce only has a series version, as doing reduce in parallel won't + // work in many situations. + async.reduce = function (arr, memo, iterator, callback) { + async.forEachSeries(arr, function (x, callback) { + iterator(memo, x, function (err, v) { + memo = v; + callback(err); + }); + }, function (err) { + callback(err, memo); + }); + }; + // inject alias + async.inject = async.reduce; + // foldl alias + async.foldl = async.reduce; + + async.reduceRight = function (arr, memo, iterator, callback) { + var reversed = _map(arr, function (x) { + return x; + }).reverse(); + async.reduce(reversed, memo, iterator, callback); + }; + // foldr alias + async.foldr = async.reduceRight; + + var _filter = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (v) { + if (v) { + results.push(x); + } + callback(); + }); + }, function (err) { + callback(_map(results.sort(function (a, b) { + return a.index - b.index; + }), function (x) { + return x.value; + })); + }); + }; + async.filter = doParallel(_filter); + async.filterSeries = doSeries(_filter); + // select alias + async.select = async.filter; + async.selectSeries = async.filterSeries; + + var _reject = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (v) { + if (!v) { + results.push(x); + } + callback(); + }); + }, function (err) { + callback(_map(results.sort(function (a, b) { + return a.index - b.index; + }), function (x) { + return x.value; + })); + }); + }; + async.reject = doParallel(_reject); + async.rejectSeries = doSeries(_reject); + + var _detect = function (eachfn, arr, iterator, main_callback) { + eachfn(arr, function (x, callback) { + iterator(x, function (result) { + if (result) { + main_callback(x); + } + else { + callback(); + } + }); + }, function (err) { + main_callback(); + }); + }; + async.detect = doParallel(_detect); + async.detectSeries = doSeries(_detect); + + async.some = function (arr, iterator, main_callback) { + async.forEach(arr, function (x, callback) { + iterator(x, function (v) { + if (v) { + main_callback(true); + main_callback = function () {}; + } + callback(); + }); + }, function (err) { + main_callback(false); + }); + }; + // any alias + async.any = async.some; + + async.every = function (arr, iterator, main_callback) { + async.forEach(arr, function (x, callback) { + iterator(x, function (v) { + if (!v) { + main_callback(false); + main_callback = function () {}; + } + callback(); + }); + }, function (err) { + main_callback(true); + }); + }; + // all alias + async.all = async.every; + + async.sortBy = function (arr, iterator, callback) { + async.map(arr, function (x, callback) { + iterator(x, function (err, criteria) { + if (err) { + callback(err); + } + else { + callback(null, {value: x, criteria: criteria}); + } + }); + }, function (err, results) { + if (err) { + return callback(err); + } + else { + var fn = function (left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }; + callback(null, _map(results.sort(fn), function (x) { + return x.value; + })); + } + }); + }; + + async.auto = function (tasks, callback) { + callback = callback || function () {}; + var keys = _keys(tasks); + if (!keys.length) { + return callback(null); + } + + var completed = []; + + var listeners = []; + var addListener = function (fn) { + listeners.unshift(fn); + }; + var removeListener = function (fn) { + for (var i = 0; i < listeners.length; i += 1) { + if (listeners[i] === fn) { + listeners.splice(i, 1); + return; + } + } + }; + var taskComplete = function () { + _forEach(listeners, function (fn) { + fn(); + }); + }; + + addListener(function () { + if (completed.length === keys.length) { + callback(null); + } + }); + + _forEach(keys, function (k) { + var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k]; + var taskCallback = function (err) { + if (err) { + callback(err); + // stop subsequent errors hitting callback multiple times + callback = function () {}; + } + else { + completed.push(k); + taskComplete(); + } + }; + var requires = task.slice(0, Math.abs(task.length - 1)) || []; + var ready = function () { + return _reduce(requires, function (a, x) { + return (a && _indexOf(completed, x) !== -1); + }, true); + }; + if (ready()) { + task[task.length - 1](taskCallback); + } + else { + var listener = function () { + if (ready()) { + removeListener(listener); + task[task.length - 1](taskCallback); + } + }; + addListener(listener); + } + }); + }; + + async.waterfall = function (tasks, callback) { + if (!tasks.length) { + return callback(); + } + callback = callback || function () {}; + var wrapIterator = function (iterator) { + return function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + var args = Array.prototype.slice.call(arguments, 1); + var next = iterator.next(); + if (next) { + args.push(wrapIterator(next)); + } + else { + args.push(callback); + } + async.nextTick(function () { + iterator.apply(null, args); + }); + } + }; + }; + wrapIterator(async.iterator(tasks))(); + }; + + async.parallel = function (tasks, callback) { + callback = callback || function () {}; + if (tasks.constructor === Array) { + async.map(tasks, function (fn, callback) { + if (fn) { + fn(function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + callback.call(null, err, args || null); + }); + } + }, callback); + } + else { + var results = {}; + async.forEach(_keys(tasks), function (k, callback) { + tasks[k](function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + results[k] = args; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + } + }; + + async.series = function (tasks, callback) { + callback = callback || function () {}; + if (tasks.constructor === Array) { + async.mapSeries(tasks, function (fn, callback) { + if (fn) { + fn(function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + callback.call(null, err, args || null); + }); + } + }, callback); + } + else { + var results = {}; + async.forEachSeries(_keys(tasks), function (k, callback) { + tasks[k](function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + results[k] = args; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + } + }; + + async.iterator = function (tasks) { + var makeCallback = function (index) { + var fn = function () { + if (tasks.length) { + tasks[index].apply(null, arguments); + } + return fn.next(); + }; + fn.next = function () { + return (index < tasks.length - 1) ? makeCallback(index + 1): null; + }; + return fn; + }; + return makeCallback(0); + }; + + async.apply = function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + return function () { + return fn.apply( + null, args.concat(Array.prototype.slice.call(arguments)) + ); + }; + }; + + var _concat = function (eachfn, arr, fn, callback) { + var r = []; + eachfn(arr, function (x, cb) { + fn(x, function (err, y) { + r = r.concat(y || []); + cb(err); + }); + }, function (err) { + callback(err, r); + }); + }; + async.concat = doParallel(_concat); + async.concatSeries = doSeries(_concat); + + async.whilst = function (test, iterator, callback) { + if (test()) { + iterator(function (err) { + if (err) { + return callback(err); + } + async.whilst(test, iterator, callback); + }); + } + else { + callback(); + } + }; + + async.until = function (test, iterator, callback) { + if (!test()) { + iterator(function (err) { + if (err) { + return callback(err); + } + async.until(test, iterator, callback); + }); + } + else { + callback(); + } + }; + + async.queue = function (worker, concurrency) { + var workers = 0; + var tasks = []; + var q = { + concurrency: concurrency, + push: function (data, callback) { + tasks.push({data: data, callback: callback}); + async.nextTick(q.process); + }, + process: function () { + if (workers < q.concurrency && tasks.length) { + var task = tasks.splice(0, 1)[0]; + workers += 1; + worker(task.data, function () { + workers -= 1; + if (task.callback) { + task.callback.apply(task, arguments); + } + q.process(); + }); + } + }, + length: function () { + return tasks.length; + } + }; + return q; + }; + + var _console_fn = function (name) { + return function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + fn.apply(null, args.concat([function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (typeof console !== 'undefined') { + if (err) { + if (console.error) { + console.error(err); + } + } + else if (console[name]) { + _forEach(args, function (x) { + console[name](x); + }); + } + } + }])); + }; + }; + async.log = _console_fn('log'); + async.dir = _console_fn('dir'); + /*async.info = _console_fn('info'); + async.warn = _console_fn('warn'); + async.error = _console_fn('error');*/ + + async.memoize = function (fn, hasher) { + var memo = {}; + hasher = hasher || function (x) { + return x; + }; + return function () { + var args = Array.prototype.slice.call(arguments); + var callback = args.pop(); + var key = hasher.apply(null, args); + if (key in memo) { + callback.apply(null, memo[key]); + } + else { + fn.apply(null, args.concat([function () { + memo[key] = arguments; + callback.apply(null, arguments); + }])); + } + }; + }; + +}()); +(function(exports){ +/** + * This file is based on the node.js assert module, but with some small + * changes for browser-compatibility + * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! + */ + + +/** + * Added for browser compatibility + */ + +var _keys = function(obj){ + if(Object.keys) return Object.keys(obj); + if (typeof obj != 'object' && typeof obj != 'function') { + throw new TypeError('-'); + } + var keys = []; + for(var k in obj){ + if(obj.hasOwnProperty(k)) keys.push(k); + } + return keys; +}; + + + +// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 +// +// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! +// +// Originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// +// 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 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. + + +var pSlice = Array.prototype.slice; + +// 1. The assert module provides functions that throw +// AssertionError's when particular conditions are not met. The +// assert module must conform to the following interface. + +var assert = exports; + +// 2. The AssertionError is defined in assert. +// new assert.AssertionError({message: message, actual: actual, expected: expected}) + +assert.AssertionError = function AssertionError (options) { + this.name = "AssertionError"; + this.message = options.message; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + var stackStartFunction = options.stackStartFunction || fail; + + if (Error.captureStackTrace) { + Error.captureStackTrace(this, stackStartFunction); + } +}; +// code from util.inherits in node +assert.AssertionError.super_ = Error; + + +// EDITED FOR BROWSER COMPATIBILITY: replaced Object.create call +// TODO: test what effect this may have +var ctor = function () { this.constructor = assert.AssertionError; }; +ctor.prototype = Error.prototype; +assert.AssertionError.prototype = new ctor(); + + +assert.AssertionError.prototype.toString = function() { + if (this.message) { + return [this.name+":", this.message].join(' '); + } else { + return [ this.name+":" + , JSON.stringify(this.expected ) + , this.operator + , JSON.stringify(this.actual) + ].join(" "); + } +}; + +// assert.AssertionError instanceof Error + +assert.AssertionError.__proto__ = Error.prototype; + +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. + +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. + +function fail(actual, expected, message, operator, stackStartFunction) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator, + stackStartFunction: stackStartFunction + }); +} + +// EXTENSION! allows for well behaved errors defined elsewhere. +assert.fail = fail; + +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. + +assert.ok = function ok(value, message) { + if (!!!value) fail(value, true, message, "==", assert.ok); +}; + +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); + +assert.equal = function equal(actual, expected, message) { + if (actual != expected) fail(actual, expected, message, "==", assert.equal); +}; + +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); + +assert.notEqual = function notEqual(actual, expected, message) { + if (actual == expected) { + fail(actual, expected, message, "!=", assert.notEqual); + } +}; + +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); + +assert.deepEqual = function deepEqual(actual, expected, message) { + if (!_deepEqual(actual, expected)) { + fail(actual, expected, message, "deepEqual", assert.deepEqual); + } +}; + +var Buffer = null; +if (typeof require !== 'undefined' && typeof process !== 'undefined') { + try { + Buffer = require('buffer').Buffer; + } + catch (e) { + // May be a CommonJS environment other than Node.js + Buffer = null; + } +} + +function _deepEqual(actual, expected) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (actual instanceof Date && expected instanceof Date) { + return actual.getTime() === expected.getTime(); + + // 7.2.1 If the expcted value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object that refers to the same source and options + } else if (actual instanceof RegExp && expected instanceof RegExp) { + return actual.source === expected.source && + actual.global === expected.global && + actual.ignoreCase === expected.ignoreCase && + actual.multiline === expected.multiline; + + } else if (Buffer && actual instanceof Buffer && expected instanceof Buffer) { + return (function() { + var i, len; + + for (i = 0, len = expected.length; i < len; i++) { + if (actual[i] !== expected[i]) { + return false; + } + } + return actual.length === expected.length; + })(); + // 7.3. Other pairs that do not both pass typeof value == "object", + // equivalence is determined by ==. + } else if (typeof actual != 'object' && typeof expected != 'object') { + return actual == expected; + + // 7.4. For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical "prototype" property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return objEquiv(actual, expected); + } +} + +function isUndefinedOrNull (value) { + return value === null || value === undefined; +} + +function isArguments (object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; +} + +function objEquiv (a, b) { + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) + return false; + // an identical "prototype" property. + if (a.prototype !== b.prototype) return false; + //~~~I've managed to break Object.keys through screwy arguments passing. + // Converting to array solves the problem. + if (isArguments(a)) { + if (!isArguments(b)) { + return false; + } + a = pSlice.call(a); + b = pSlice.call(b); + return _deepEqual(a, b); + } + try{ + var ka = _keys(a), + kb = _keys(b), + key, i; + } catch (e) {//happens when one is a string literal and the other isn't + return false; + } + // having the same number of owned properties (keys incorporates hasOwnProperty) + if (ka.length != kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] != kb[i]) + return false; + } + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!_deepEqual(a[key], b[key] )) + return false; + } + return true; +} + +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); + +assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (_deepEqual(actual, expected)) { + fail(actual, expected, message, "notDeepEqual", assert.notDeepEqual); + } +}; + +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); + +assert.strictEqual = function strictEqual(actual, expected, message) { + if (actual !== expected) { + fail(actual, expected, message, "===", assert.strictEqual); + } +}; + +// 10. The strict non-equality assertion tests for strict inequality, as determined by !==. +// assert.notStrictEqual(actual, expected, message_opt); + +assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (actual === expected) { + fail(actual, expected, message, "!==", assert.notStrictEqual); + } +}; + +function expectedException(actual, expected) { + if (!actual || !expected) { + return false; + } + + if (expected instanceof RegExp) { + return expected.test(actual.message || actual); + } else if (actual instanceof expected) { + return true; + } else if (expected.call({}, actual) === true) { + return true; + } + + return false; +} + +function _throws(shouldThrow, block, expected, message) { + var actual; + + if (typeof expected === 'string') { + message = expected; + expected = null; + } + + try { + block(); + } catch (e) { + actual = e; + } + + message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + + (message ? ' ' + message : '.'); + + if (shouldThrow && !actual) { + fail('Missing expected exception' + message); + } + + if (!shouldThrow && expectedException(actual, expected)) { + fail('Got unwanted exception' + message); + } + + if ((shouldThrow && actual && expected && + !expectedException(actual, expected)) || (!shouldThrow && actual)) { + throw actual; + } +} + +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); + +assert.throws = function(block, /*optional*/error, /*optional*/message) { + _throws.apply(this, [true].concat(pSlice.call(arguments))); +}; + +// EXTENSION! This is annoying to write outside this module. +assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { + _throws.apply(this, [false].concat(pSlice.call(arguments))); +}; + +assert.ifError = function (err) { if (err) {throw err;}}; +})(assert); +(function(exports){ +/*! + * Nodeunit + * Copyright (c) 2010 Caolan McMahon + * MIT Licensed + * + * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! + * Only code on that line will be removed, it's mostly to avoid requiring code + * that is node specific + */ + +/** + * Module dependencies + */ + + + +/** + * Creates assertion objects representing the result of an assert call. + * Accepts an object or AssertionError as its argument. + * + * @param {object} obj + * @api public + */ + +exports.assertion = function (obj) { + return { + method: obj.method || '', + message: obj.message || (obj.error && obj.error.message) || '', + error: obj.error, + passed: function () { + return !this.error; + }, + failed: function () { + return Boolean(this.error); + } + }; +}; + +/** + * Creates an assertion list object representing a group of assertions. + * Accepts an array of assertion objects. + * + * @param {Array} arr + * @param {Number} duration + * @api public + */ + +exports.assertionList = function (arr, duration) { + var that = arr || []; + that.failures = function () { + var failures = 0; + for (var i = 0; i < this.length; i += 1) { + if (this[i].failed()) { + failures += 1; + } + } + return failures; + }; + that.passes = function () { + return that.length - that.failures(); + }; + that.duration = duration || 0; + return that; +}; + +/** + * Create a wrapper function for assert module methods. Executes a callback + * after it's complete with an assertion object representing the result. + * + * @param {Function} callback + * @api private + */ + +var assertWrapper = function (callback) { + return function (new_method, assert_method, arity) { + return function () { + var message = arguments[arity - 1]; + var a = exports.assertion({method: new_method, message: message}); + try { + assert[assert_method].apply(null, arguments); + } + catch (e) { + a.error = e; + } + callback(a); + }; + }; +}; + +/** + * Creates the 'test' object that gets passed to every test function. + * Accepts the name of the test function as its first argument, followed by + * the start time in ms, the options object and a callback function. + * + * @param {String} name + * @param {Number} start + * @param {Object} options + * @param {Function} callback + * @api public + */ + +exports.test = function (name, start, options, callback) { + var expecting; + var a_list = []; + + var wrapAssert = assertWrapper(function (a) { + a_list.push(a); + if (options.log) { + async.nextTick(function () { + options.log(a); + }); + } + }); + + var test = { + done: function (err) { + if (expecting !== undefined && expecting !== a_list.length) { + var e = new Error( + 'Expected ' + expecting + ' assertions, ' + + a_list.length + ' ran' + ); + var a1 = exports.assertion({method: 'expect', error: e}); + a_list.push(a1); + if (options.log) { + async.nextTick(function () { + options.log(a1); + }); + } + } + if (err) { + var a2 = exports.assertion({error: err}); + a_list.push(a2); + if (options.log) { + async.nextTick(function () { + options.log(a2); + }); + } + } + var end = new Date().getTime(); + async.nextTick(function () { + var assertion_list = exports.assertionList(a_list, end - start); + options.testDone(name, assertion_list); + callback(null, a_list); + }); + }, + ok: wrapAssert('ok', 'ok', 2), + same: wrapAssert('same', 'deepEqual', 3), + equals: wrapAssert('equals', 'equal', 3), + expect: function (num) { + expecting = num; + }, + _assertion_list: a_list + }; + // add all functions from the assert module + for (var k in assert) { + if (assert.hasOwnProperty(k)) { + test[k] = wrapAssert(k, k, assert[k].length); + } + } + return test; +}; + +/** + * Ensures an options object has all callbacks, adding empty callback functions + * if any are missing. + * + * @param {Object} opt + * @return {Object} + * @api public + */ + +exports.options = function (opt) { + var optionalCallback = function (name) { + opt[name] = opt[name] || function () {}; + }; + + optionalCallback('moduleStart'); + optionalCallback('moduleDone'); + optionalCallback('testStart'); + optionalCallback('testDone'); + //optionalCallback('log'); + + // 'done' callback is not optional. + + return opt; +}; +})(types); +(function(exports){ +/*! + * Nodeunit + * Copyright (c) 2010 Caolan McMahon + * MIT Licensed + * + * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! + * Only code on that line will be removed, it's mostly to avoid requiring code + * that is node specific + */ + +/** + * Module dependencies + */ + + + +/** + * Added for browser compatibility + */ + +var _keys = function (obj) { + if (Object.keys) { + return Object.keys(obj); + } + var keys = []; + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + keys.push(k); + } + } + return keys; +}; + + +var _copy = function (obj) { + var nobj = {}; + var keys = _keys(obj); + for (var i = 0; i < keys.length; i += 1) { + nobj[keys[i]] = obj[keys[i]]; + } + return nobj; +}; + + +/** + * Runs a test function (fn) from a loaded module. After the test function + * calls test.done(), the callback is executed with an assertionList as its + * second argument. + * + * @param {String} name + * @param {Function} fn + * @param {Object} opt + * @param {Function} callback + * @api public + */ + +exports.runTest = function (name, fn, opt, callback) { + var options = types.options(opt); + + options.testStart(name); + var start = new Date().getTime(); + var test = types.test(name, start, options, callback); + + try { + fn(test); + } + catch (e) { + test.done(e); + } +}; + +/** + * Takes an object containing test functions or other test suites as properties + * and runs each in series. After all tests have completed, the callback is + * called with a list of all assertions as the second argument. + * + * If a name is passed to this function it is prepended to all test and suite + * names that run within it. + * + * @param {String} name + * @param {Object} suite + * @param {Object} opt + * @param {Function} callback + * @api public + */ + +exports.runSuite = function (name, suite, opt, callback) { + suite = wrapGroup(suite); + var keys = _keys(suite); + + async.concatSeries(keys, function (k, cb) { + var prop = suite[k], _name; + + _name = name ? [].concat(name, k) : [k]; + _name.toString = function () { + // fallback for old one + return this.join(' - '); + }; + + if (typeof prop === 'function') { + var in_name = false, + in_specific_test = (_name.toString() === opt.testFullSpec) ? true : false; + for (var i = 0; i < _name.length; i += 1) { + if (_name[i] === opt.testspec) { + in_name = true; + } + } + + if ((!opt.testFullSpec || in_specific_test) && (!opt.testspec || in_name)) { + if (opt.moduleStart) { + opt.moduleStart(); + } + exports.runTest(_name, suite[k], opt, cb); + } + else { + return cb(); + } + } + else { + exports.runSuite(_name, suite[k], opt, cb); + } + }, callback); +}; + +/** + * Run each exported test function or test suite from a loaded module. + * + * @param {String} name + * @param {Object} mod + * @param {Object} opt + * @param {Function} callback + * @api public + */ + +exports.runModule = function (name, mod, opt, callback) { + var options = _copy(types.options(opt)); + + var _run = false; + var _moduleStart = options.moduleStart; + + mod = wrapGroup(mod); + + function run_once() { + if (!_run) { + _run = true; + _moduleStart(name); + } + } + options.moduleStart = run_once; + + var start = new Date().getTime(); + + exports.runSuite(null, mod, options, function (err, a_list) { + var end = new Date().getTime(); + var assertion_list = types.assertionList(a_list, end - start); + options.moduleDone(name, assertion_list); + if (nodeunit.complete) { + nodeunit.complete(name, assertion_list); + } + callback(null, a_list); + }); +}; + +/** + * Treats an object literal as a list of modules keyed by name. Runs each + * module and finished with calling 'done'. You can think of this as a browser + * safe alternative to runFiles in the nodeunit module. + * + * @param {Object} modules + * @param {Object} opt + * @api public + */ + +// TODO: add proper unit tests for this function +exports.runModules = function (modules, opt) { + var all_assertions = []; + var options = types.options(opt); + var start = new Date().getTime(); + + async.concatSeries(_keys(modules), function (k, cb) { + exports.runModule(k, modules[k], options, cb); + }, + function (err, all_assertions) { + var end = new Date().getTime(); + options.done(types.assertionList(all_assertions, end - start)); + }); +}; + + +/** + * Wraps a test function with setUp and tearDown functions. + * Used by testCase. + * + * @param {Function} setUp + * @param {Function} tearDown + * @param {Function} fn + * @api private + */ + +var wrapTest = function (setUp, tearDown, fn) { + return function (test) { + var context = {}; + if (tearDown) { + var done = test.done; + test.done = function (err) { + try { + tearDown.call(context, function (err2) { + if (err && err2) { + test._assertion_list.push( + types.assertion({error: err}) + ); + return done(err2); + } + done(err || err2); + }); + } + catch (e) { + done(e); + } + }; + } + if (setUp) { + setUp.call(context, function (err) { + if (err) { + return test.done(err); + } + fn.call(context, test); + }); + } + else { + fn.call(context, test); + } + }; +}; + + +/** + * Returns a serial callback from two functions. + * + * @param {Function} funcFirst + * @param {Function} funcSecond + * @api private + */ + +var getSerialCallback = function (fns) { + if (!fns.length) { + return null; + } + return function (callback) { + var that = this; + var bound_fns = []; + for (var i = 0, len = fns.length; i < len; i++) { + (function (j) { + bound_fns.push(function () { + return fns[j].apply(that, arguments); + }); + })(i); + } + return async.series(bound_fns, callback); + }; +}; + + +/** + * Wraps a group of tests with setUp and tearDown functions. + * Used by testCase. + * + * @param {Object} group + * @param {Array} setUps - parent setUp functions + * @param {Array} tearDowns - parent tearDown functions + * @api private + */ + +var wrapGroup = function (group, setUps, tearDowns) { + var tests = {}; + + var setUps = setUps ? setUps.slice(): []; + var tearDowns = tearDowns ? tearDowns.slice(): []; + + if (group.setUp) { + setUps.push(group.setUp); + delete group.setUp; + } + if (group.tearDown) { + tearDowns.unshift(group.tearDown); + delete group.tearDown; + } + + var keys = _keys(group); + + for (var i = 0; i < keys.length; i += 1) { + var k = keys[i]; + if (typeof group[k] === 'function') { + tests[k] = wrapTest( + getSerialCallback(setUps), + getSerialCallback(tearDowns), + group[k] + ); + } + else if (typeof group[k] === 'object') { + tests[k] = wrapGroup(group[k], setUps, tearDowns); + } + } + return tests; +}; + + +/** + * Backwards compatibility for test suites using old testCase API + */ + +exports.testCase = function (suite) { + return suite; +}; +})(core); +(function(exports){ +/*! + * Nodeunit + * Copyright (c) 2010 Caolan McMahon + * MIT Licensed + * + * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! + * Only code on that line will be removed, its mostly to avoid requiring code + * that is node specific + */ + + +/** + * NOTE: this test runner is not listed in index.js because it cannot be + * used with the command-line tool, only inside the browser. + */ + + +/** + * Reporter info string + */ + +exports.info = "Browser-based test reporter"; + + +/** + * Run all tests within each module, reporting the results + * + * @param {Array} files + * @api public + */ + +exports.run = function (modules, options) { + var start = new Date().getTime(), div; + options = options || {}; + div = options.div || document.body; + + function setText(el, txt) { + if ('innerText' in el) { + el.innerText = txt; + } + else if ('textContent' in el){ + el.textContent = txt; + } + } + + function getOrCreate(tag, id) { + var el = document.getElementById(id); + if (!el) { + el = document.createElement(tag); + el.id = id; + div.appendChild(el); + } + return el; + }; + + var header = getOrCreate('h1', 'nodeunit-header'); + var banner = getOrCreate('h2', 'nodeunit-banner'); + var userAgent = getOrCreate('h2', 'nodeunit-userAgent'); + var tests = getOrCreate('ol', 'nodeunit-tests'); + var result = getOrCreate('p', 'nodeunit-testresult'); + + setText(userAgent, navigator.userAgent); + + nodeunit.runModules(modules, { + moduleStart: function (name) { + /*var mheading = document.createElement('h2'); + mheading.innerText = name; + results.appendChild(mheading); + module = document.createElement('ol'); + results.appendChild(module);*/ + }, + testDone: function (name, assertions) { + var test = document.createElement('li'); + var strong = document.createElement('strong'); + strong.innerHTML = name + ' (' + + '' + assertions.failures() + ', ' + + '' + assertions.passes() + ', ' + + assertions.length + + ')'; + test.className = assertions.failures() ? 'fail': 'pass'; + test.appendChild(strong); + + var aList = document.createElement('ol'); + aList.style.display = 'none'; + test.onclick = function () { + var d = aList.style.display; + aList.style.display = (d == 'none') ? 'block': 'none'; + }; + for (var i=0; i' + (a.error.stack || a.error) + ''; + li.className = 'fail'; + } + else { + li.innerHTML = a.message || a.method || 'no message'; + li.className = 'pass'; + } + aList.appendChild(li); + } + test.appendChild(aList); + tests.appendChild(test); + }, + done: function (assertions) { + var end = new Date().getTime(); + var duration = end - start; + + var failures = assertions.failures(); + banner.className = failures ? 'fail': 'pass'; + + result.innerHTML = 'Tests completed in ' + duration + + ' milliseconds.
      ' + + assertions.passes() + ' assertions of ' + + '' + assertions.length + ' passed, ' + + assertions.failures() + ' failed.'; + } + }); +}; +})(reporter); +nodeunit = core; +nodeunit.assert = assert; +nodeunit.reporter = reporter; +nodeunit.run = reporter.run; +return nodeunit; })(); diff --git a/javascript/node_modules/protobufjs/tests/numberformats.proto b/javascript/node_modules/protobufjs/tests/numberformats.proto new file mode 100644 index 0000000..5b31eb4 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/numberformats.proto @@ -0,0 +1,11 @@ +enum Formats { + DEC = 1; + HEX = 0x1F; + OCT = 017; +} + +message Msg { + required int32 dec = 1 [default=-1]; + required int32 hex = 2 [default=-0x1F]; + required int32 oct = 3 [default=-017]; +} diff --git a/javascript/node_modules/protobufjs/tests/optional.proto b/javascript/node_modules/protobufjs/tests/optional.proto new file mode 100644 index 0000000..9570665 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/optional.proto @@ -0,0 +1,3 @@ +message Test1 { + optional int32 a = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/options.proto b/javascript/node_modules/protobufjs/tests/options.proto new file mode 100644 index 0000000..094f480 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/options.proto @@ -0,0 +1,8 @@ +option (toplevel_1) = 10; +package My; +option (toplevel_2) = "Hello world!"; + +message Test { + optional string name = 1 [default="Max"]; + option (inmessage) = My.Test; +} diff --git a/javascript/node_modules/protobufjs/tests/proto2js/Bar.json b/javascript/node_modules/protobufjs/tests/proto2js/Bar.json new file mode 100644 index 0000000..71d0c6b --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/proto2js/Bar.json @@ -0,0 +1,46 @@ +{ + "package": null, + "messages": [ + { + "ref": "Foo", + "fields": [ + { + "rule": "required", + "type": "string", + "name": "buzz", + "id": 2, + "options": {} + } + ] + } + ], + "enums": [], + "imports": [ + { + "package": null, + "messages": [ + { + "name": "Foo", + "fields": [ + { + "rule": "required", + "type": "string", + "name": "fizz", + "id": 1, + "options": {} + } + ], + "enums": [], + "messages": [], + "options": {} + } + ], + "enums": [], + "imports": [], + "options": {}, + "services": [] + } + ], + "options": {}, + "services": [] +} diff --git a/javascript/node_modules/protobufjs/tests/proto2js/Bar.proto b/javascript/node_modules/protobufjs/tests/proto2js/Bar.proto new file mode 100644 index 0000000..309157b --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/proto2js/Bar.proto @@ -0,0 +1,7 @@ +// Bar.proto +import "Foo.proto"; + +// really extend Bar but that produces an empty constructor. +extend Foo { + required string buzz = 2; +} diff --git a/javascript/node_modules/protobufjs/tests/proto2js/Foo.proto b/javascript/node_modules/protobufjs/tests/proto2js/Foo.proto new file mode 100644 index 0000000..f56944a --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/proto2js/Foo.proto @@ -0,0 +1,4 @@ +// Foo.proto +message Foo { + required string fizz = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/protobufnet.proto b/javascript/node_modules/protobufjs/tests/protobufnet.proto new file mode 100644 index 0000000..1d255c2 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/protobufnet.proto @@ -0,0 +1,19 @@ +message IMeshImp { +} +message Mesh { + optional IMeshImp _meshImp = 1; + repeated float3 _vertices = 2; + repeated uint32 _colors = 3; + repeated float3 _normals = 4; + repeated float2 _uvs = 5; + repeated int32 _triangles = 6; +} +message float2 { + optional float x = 1 [default = 0]; + optional float y = 2 [default = 0]; +} +message float3 { + optional float x = 1 [default = 0]; + optional float y = 2 [default = 0]; + optional float z = 3 [default = 0]; +} diff --git a/javascript/node_modules/protobufjs/tests/repeated.proto b/javascript/node_modules/protobufjs/tests/repeated.proto new file mode 100644 index 0000000..0091d88 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/repeated.proto @@ -0,0 +1,17 @@ +message Outer { + // As of: https://developers.google.com/protocol-buffers/docs/encoding#optional + + repeated Inner inner = 1; + // "If your message definition has repeated elements (without the [packed=true] option), the encoded message has + // zero or more key-value pairs with the same tag number." + + repeated Inner innerPacked = 2 [packed = true]; + // "A packed repeated field containing zero elements does not appear in the encoded message. Otherwise, all of the + // elements of the field are packed into a single key-value pair with wire type 2 (length-delimited). Each element + // is encoded the same way it would be normally, except without a tag preceding it." + +} + +message Inner { + optional uint32 inner_value = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/setarray.proto b/javascript/node_modules/protobufjs/tests/setarray.proto new file mode 100644 index 0000000..8bbcc32 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/setarray.proto @@ -0,0 +1,7 @@ +message Outer { + repeated Inner inners = 4; +} + +message Inner { + required string str = 1; +} diff --git a/javascript/node_modules/protobufjs/tests/suite.html b/javascript/node_modules/protobufjs/tests/suite.html new file mode 100644 index 0000000..ed15eaa --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/suite.html @@ -0,0 +1,16 @@ + + + + ProtoBuf.js Test Suite + + + + + + + + +

      ProtoBuf.js Test Suite

      + + + diff --git a/javascript/node_modules/protobufjs/tests/suite.js b/javascript/node_modules/protobufjs/tests/suite.js new file mode 100644 index 0000000..0153e14 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/suite.js @@ -0,0 +1,1367 @@ +/* + Copyright 2013 Daniel Wirtz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * ProtoBuf.js Test Suite. + * @author Daniel Wirtz + */ +(function(global) { + + var FILE = "ProtoBuf.js"; + var BROWSER = !!global.window; + + var ProtoBuf = BROWSER ? global.dcodeIO.ProtoBuf : require(__dirname+"/../"+FILE), + ByteBuffer = BROWSER ? global.dcodeIO.ByteBuffer : ByteBuffer || require("bytebuffer"), + util = BROWSER ? null : require("util"), + fs = BROWSER ? null : require("fs"); + + if (typeof __dirname == 'undefined') { + __dirname = document.location.href.replace(/[\/\\][^\/\\]*$/, ""); + } + + /** + * Constructs a new Sandbox for module loaders and shim testing. + * @param {Object.} properties Additional properties to set + * @constructor + */ + var Sandbox = function(properties) { + this.ByteBuffer = function() {}; + for (var i in properties) { + this[i] = properties[i]; + } + this.console = { + log: function(s) { + console.log(s); + } + }; + }; + + function fail(e) { + throw(e); + } + + /** + * Validates the complexDotProto and complexInline tests. + * @param {*} test Nodeunit test + * @param {Object} Game Game namespace + */ + function validateComplex(test, Game) { + var Car = Game.Cars.Car, + Vendor = Car.Vendor, + Speed = Car.Speed; + + var vendor; + // Car from class with argument list properties + var car = new Car( + "Rusty", + // Vendor from class with object properties + vendor = new Vendor({ + "name": "Iron Inc.", + // Address from object + "address": { + "country": "US" + } + }), + // Speed from enum object + Speed.SUPERFAST + ); + test.equal(car.model, "Rusty"); + test.equal(car.vendor.name, "Iron Inc."); + test.equal(car.vendor.address.country, "US"); + test.equal(car.vendor.address.country, car.getVendor().get_address().country); + var bb = new ByteBuffer(28); + car.encode(bb); + test.equal(bb.toString("debug"), "<0A 05 52 75 73 74 79 12 11 0A 09 49 72 6F 6E 20 49 6E 63 2E 12 04 0A 02 55 53 18 02>"); + var carDec = Car.decode(bb); + test.equal(carDec.model, "Rusty"); + test.equal(carDec.vendor.name, "Iron Inc."); + test.equal(carDec.vendor.address.country, "US"); + test.equal(carDec.vendor.address.country, carDec.getVendor().get_address().country); + } + + /** + * Test suite. + * @type {Object.} + */ + var suite = { + + "init": function(test) { + test.ok(typeof ProtoBuf == "object"); + test.ok(typeof ProtoBuf.Reflect == 'object'); + test.ok(typeof ProtoBuf.protoFromFile == "function"); + test.done(); + }, + + // Example "A Simple Message" from the protobuf docs + // https://developers.google.com/protocol-buffers/docs/encoding#simple + "example1": function(test) { + try{ + var builder = ProtoBuf.loadProtoFile(__dirname+"/example1.proto"); + var Test1 = builder.build("Test1"); + test.ok(typeof Test1 == 'function'); + var inst = new Test1(150); + test.ok(inst instanceof ProtoBuf.Builder.Message); + test.equal(inst.a, 150); + test.equal(inst.getA(), 150); + test.equal(inst.get_a(), 150); + inst.setA(151); + test.equal(inst.a, 151); + test.equal(inst.getA(), 151); + test.equal(inst.get_a(), 151); + inst.set_a(152); + test.equal(inst.a, 152); + test.equal(inst.toString(), ".Test1"); + test.throws(function() { + inst.setA(null); // required + }); + test.throws(function() { + inst.setA([]); + }); + var bb = new ByteBuffer(3); + inst.encode(bb); + test.equal(bb.toString("debug"), "<08 98 01>"); + var instDec = Test1.decode(bb); + test.equal(instDec.a, 152); + + } catch (e) { + fail(e); + } + test.done(); + }, + + // Basically the same as example1, but with an unsigned value. + "example1u": function(test) { + try{ + var builder = ProtoBuf.loadProtoFile(__dirname+"/example1u.proto"); + var Test1u = builder.build("Test1u"); + test.ok(typeof Test1u == 'function'); + var inst = new Test1u(-1); + test.equal(inst.a, 4294967295); + var bb = new ByteBuffer(6); + inst.encode(bb); + test.equal(bb.toString("debug"), "<08 FF FF FF FF 7F>"); + var instDec = Test1u.decode(bb); + test.equal(instDec.a, 4294967295); + + } catch (e) { + fail(e); + } + test.done(); + }, + + // Example "Strings" from the protobuf docs + // https://developers.google.com/protocol-buffers/docs/encoding#types + "example2": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/example2.proto"); + var Test2 = builder.build("Test2"); + var inst = new Test2("testing"); + var bb = new ByteBuffer(9); + inst.encode(bb); + test.equal(bb.toString("debug"), "<12 07 74 65 73 74 69 6E 67>"); + var instDec = Test2.decode(bb); + test.equal(instDec.b, "testing"); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Example "Embedded Messages" from the protobuf docs + // https://developers.google.com/protocol-buffers/docs/encoding#embedded + "example3": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/example3.proto"); + var root = builder.build(); + var Test1 = root.Test1; + var Test3 = root.Test3; + var inst = new Test3(new Test1(150)); + var bb = new ByteBuffer(5); + test.equal(inst.c.a, 150); + inst.encode(bb); + test.equal(bb.toString("debug"), "<1A 03 08 96 01>"); + var instDec = Test3.decode(bb); + test.equal(instDec.c.a, 150); + } catch(e) { + fail(e); + } + test.done(); + }, + + "example4": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/example4.proto"); + var Test4 = builder.build("Test4"); + var inst = new Test4([3, 270, 86942]); + var bb = new ByteBuffer(8); + test.equal(inst.d.length, 3); + inst.encode(bb); + test.equal(bb.toString("debug"), "<22 06 03 8E 02 9E A7 05>"); + var instDec = Test4.decode(bb); + test.equal(bb.toString("debug"), " 22 06 03 8E 02 9E A7 05|"); + test.equal(instDec.d.length, 3); + test.equal(instDec.d[2], 86942); + } catch(e) { + fail(e); + } + test.done(); + }, + + "numberFormats": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/numberformats.proto"); + var Formats = builder.build("Formats"); + test.strictEqual(Formats.DEC, 1); + test.strictEqual(Formats.HEX, 31); + test.strictEqual(Formats.OCT, 15); + var Msg = builder.build("Msg"); + var msg = new Msg(); + test.strictEqual(msg.dec, -1); + test.strictEqual(msg.hex, -31); + test.strictEqual(msg.oct, -15); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Check encode/decode against a table of known correct pairs. + // Note that javascript ArrayBuffer does not support signed Zero or NaN + // bertdouglas (https://github.com/bertdouglas) + "float": function(test) { + try { + var str_proto = "message Float {" + + " required float f = 1;" + + "}"; + var builder = ProtoBuf.loadProto(str_proto); + var root = builder.build(); + var Float = root.Float; + + var in_tolerance = function (reference,actual) { + var tol = 1e-6; + var scale = 1.0; + if (reference != 0.0 ) { + scale = reference; + }; + var err = Math.abs(reference - actual)/scale; + return err < tol; + }; + + var f_vals = [ + // hex values are shown here in big-endian following IEEE754 notation + // protobuf is little-endian + // { f: -0.0 , b: "80 00 00 00" }, + { f: +0.0 , b: "00 00 00 00" }, + { f: -1e-10 , b: "AE DB E6 FF" }, + { f: +1e-10 , b: "2E DB E6 FF" }, + { f: -2e+10 , b: "D0 95 02 F9" }, + { f: +2e+10 , b: "50 95 02 F9" }, + { f: -3e-30 , b: "8E 73 63 90" }, + { f: +3e-30 , b: "0E 73 63 90" }, + { f: -4e+30 , b: "F2 49 F2 CA" }, + { f: +4e+30 , b: "72 49 F2 CA" }, + { f: -123456789.0 , b: "CC EB 79 A3" }, + { f: +123456789.0 , b: "4C EB 79 A3" }, + { f: -0.987654321 , b: "BF 7C D6 EA" }, + { f: +0.987654321 , b: "3F 7C D6 EA" }, + { f: -Infinity , b: "FF 80 00 00" }, + { f: +Infinity , b: "7F 80 00 00" } + // { f: -NaN , b: "FF C0 00 00>" }, + // { f: +NaN , b: "7F C0 00 00" } + ]; + + f_vals.map( function(x) { + // check encode + var m1 = new Float(); + var b1 = new ByteBuffer(); + m1.f = x.f; + m1.encode(b1); + var q1 = b1.slice(1,5).compact().reverse(); + test.strictEqual('<' + x.b + '>', q1.toString("debug")); + + // check decode + var b2 = new ByteBuffer(); + var s1 = x.b + ' 0D'; + var s2 = s1.split(" "); + var s3 = s2.reverse(); + var i1 = s3.map(function(y) { return parseInt(y,16) } ); + i1.map(function(y) { b2.writeUint8(y) }); + b2.length = b2.offset; + b2.offset = 0; + var m2 = Float.decode(b2); + + var s4 = "" + x.f +" " + m2.f; + if ( isNaN(x.f) ) { + test.ok( isNaN(m2.f), s4 ); + } + else if ( ! isFinite( x.f) ) { + test.ok( x.f === m2.f, s4 ); + } + else { + test.ok( in_tolerance(x.f, m2.f), s4 ); + } + }); + } catch(e) { + fail(e); + } + test.done(); + }, + + "bytes": function(test) { + try { + var str_proto = "message Test { required bytes b = 1; }"; + var builder = ProtoBuf.loadProto(str_proto); + var Test = builder.build("Test"); + var bb = new ByteBuffer(4).writeUint32(0x12345678).flip(); + var myTest = new Test(bb); + test.strictEqual(myTest.b.array, bb.array); + var bb2 = new ByteBuffer(6); + myTest.encode(bb2); + test.equal(bb2.toString("debug"), "<0A 04 12 34 56 78>"); + myTest = Test.decode(bb2); + test.equal(myTest.b.BE().readUint32(), 0x12345678); + } catch (e) { + fail(e); + } + test.done(); + }, + + "bytesFromFile": function(test) { + try { + var builder = ProtoBuf.loadProto("message Image { required bytes data = 1; }"), + Image = builder.build("Image"), + data = fs.readFileSync(__dirname+"/../ProtoBuf.png"), + image = new Image({ data: data }), + bb = image.encode(), + imageDec = Image.decode(bb), + dataDec = imageDec.data.toBuffer(); + test.strictEqual(data.length, dataDec.length); + test.deepEqual(data, dataDec); + } catch (e) { + fail(e); + } + test.done(); + }, + + "notEnoughBytes": function(test) { + var builder = ProtoBuf.loadProto("message Test { required bytes b = 1; }"); + var Test = builder.build("Test"); + var bb = new ByteBuffer().writeUint32(0x12345678).flip(); + var encoded = new ByteBuffer(6); + new Test(bb).encode(encoded); + test.equal(encoded.toString("debug"), "<0A 04 12 34 56 78>"); + encoded = encoded.slice(0, 5); // chop off the last byte + var err = null; + try { + Test.decode(encoded); + } catch (caught) { + err = caught; + } + test.ok(err && err.message && err.message.indexOf(": 4 required but got only 3") >= 0); + test.done(); + }, + + "bool": function(test) { + try { + var builder = ProtoBuf.loadProto("message Test { optional bool ok = 1 [ default = false ]; }"), + Test = builder.build("Test"), + t = new Test(); + test.strictEqual(t.ok, false); + t.setOk("true"); + test.strictEqual(t.ok, true); + test.strictEqual(Test.decode(t.encode()).ok, true); + t.setOk("false"); + test.strictEqual(t.ok, false); + test.strictEqual(Test.decode(t.encode()).ok, false); + } catch (err) { + fail(err); + } + test.done(); + }, + + // As mentioned by Bill Katz + "T139": function(test) { + try{ + var builder = ProtoBuf.loadProtoFile(__dirname+"/T139.proto"); + var T139 = builder.build("T139"); + test.ok(typeof T139 == 'function'); + var inst = new T139(139,139); + test.equal(inst.a, 139); + test.equal(inst.b, 139); + inst.setA(139); + inst.setB(139); + test.equal(inst.a, 139); + test.equal(inst.b, 139); + var bb = new ByteBuffer(3); + inst.encode(bb); + test.equal(bb.toString("debug"), "<08 8B 01 10 8B 01>"); + var instDec = T139.decode(bb); + test.equal(instDec.a, 139); + test.equal(instDec.b, 139); + } catch (e) { + fail(e); + } + test.done(); + }, + + "emptyDefaultString": function(test) { + try { + var builder = ProtoBuf.loadProto("message Test1 { optional string test = 1 [default = \"\"]; }"); + var Test1; + test.doesNotThrow(function() { + Test1 = builder.build("Test1"); + }); + var test1 = new Test1(); + test.strictEqual(test1.test, ""); + } catch (e) { + fail(e); + } + test.done(); + }, + + "trailingSemicolon": function(test) { + try { + var builder = ProtoBuf.loadProto("message Test1 { optional string test = 1; };"); + test.doesNotThrow(function() { + var Test1 = builder.build("Test1"); + }); + } catch (e) { + fail(e); + } + test.done(); + }, + + "inner": { + + "longstr": function(test) { + try { + var builder = ProtoBuf.loadProto("message Test { required Inner a = 1; message Inner { required string b = 1; } }"); + var Test = builder.build("Test"); + var t = new Test(); + var data = "0123456789"; // 10: 20, 40, 80, 160, 320 bytes + for (var i=0; i<5; i++) data += data; + test.equal(data.length, 320); + t.a = new Test.Inner(data); + var bb = t.encode(); + var t2 = Test.decode(bb); + test.equal(t2.a.b.length, 320); + test.equal(data, t2.a.b); + } catch (e) { + fail(e); + } + test.done(); + }, + + "multiple": function(test) { + try { + var str = ""; + for (var i=0; i<200; i++) str += 'a'; + var builder = ProtoBuf.loadProtoFile(__dirname+"/inner.proto"); + var fooCls = builder.build("Foo"); + var barCls = builder.build("Bar"); + var bazCls = builder.build("Baz"); + var foo = new fooCls(new barCls(str), new bazCls(str)); + var fooEncoded = foo.encode(); + test.doesNotThrow(function() { + fooCls.decode(fooEncoded); + }); + } catch (e) { + fail(e); + } + test.done(); + }, + + "float": function(test) { + try { + var builder = ProtoBuf.loadProto("message Foo { required Bar bar = 1; } message Bar { required float baz = 1; }"); + var root = builder.build(); + var foo = new root.Foo(new root.Bar(4)); + var bb = foo.encode(); + var foo2 = root.Foo.decode(bb); + test.equal(foo.bar.baz, 4); + test.equal(foo2.bar.baz, foo.bar.baz); + } catch (e) { + fail(e); + } + test.done(); + } + + }, + + "truncated": function(test) { + try { + var builder = ProtoBuf.loadProto("message Test { required int32 a = 1; required int32 b = 2; }"); + var Test = builder.build("Test"); + var t = new Test(), bb = new ByteBuffer(2); + t.setA(1); + try { + bb = t.encode(bb).flip(); + test.ok(false); + } catch (e) { + test.ok(e.encoded); + bb = e.encoded.flip(); + test.equal(bb.toString("debug"), "<08 01>"); + } + var t2; + try /* to decode truncated message */ { + t2 = Test.decode(bb); + test.ok(false); // ^ throws + } catch (e) { + // But still be able to access the rest + var t3 = e.decoded; + test.strictEqual(t3.a, 1); + test.strictEqual(t3.b, null); + } + test.strictEqual(t2, undefined); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Options on all levels + "options": { + + "parse": function(test) { + try { + var parser = new ProtoBuf.DotProto.Parser(ProtoBuf.Util.fetch(__dirname+"/options.proto")); + var root = parser.parse(); + test.equal(root["package"], "My"); + test.strictEqual(root["options"]["(toplevel_1)"], 10); + test.equal(root["options"]["(toplevel_2)"], "Hello world!"); + test.equal(root["messages"][0]["fields"][0]["options"]["default"], "Max"); + test.equal(root["messages"][0]["options"]["(inmessage)"], "My.Test") + } catch (e) { + fail(e); + } + test.done(); + }, + + "export": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/options.proto"); + var My = builder.build("My"); + test.deepEqual(My.$options, { + "(toplevel_1)": 10, + "(toplevel_2)": "Hello world!" + }); + test.strictEqual(My.$options['(toplevel_1)'], 10); + test.deepEqual(My.Test.$options, { + "(inmessage)": "My.Test" // TODO: Options are not resolved, yet. + }); + } catch (e) { + fail(e); + } + test.done(); + } + }, + + // Comments + "comments": function(test) { + try { + var tn = new ProtoBuf.DotProto.Tokenizer(ProtoBuf.Util.fetch(__dirname+'/comments.proto')); + var token, tokens = []; + do { + token = tn.next(); + tokens.push(token); + } while (token !== null); + test.deepEqual(tokens, ['message', 'TestC', '{', 'required', 'int32', 'a', '=', '1', ';', '}', null]); + } catch (e) { + fail(e); + } + test.done(); + }, + + // A more or less complex proto with type references + "complexProto": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/complex.proto"); + validateComplex(test, builder.build("Game")); + var TCars = builder.lookup("Game.Cars"); + test.strictEqual(TCars.fqn(), ".Game.Cars"); + } catch(e) { + fail(e); + } + test.done(); + }, + + // The same created without calling upon the parser to do so (noparse) + "complexJSON": function(test) { + try { + var builder = ProtoBuf.loadJsonFile(__dirname+"/complex.json"); + validateComplex(test, builder.build("Game")); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Builder reused to add definitions from multiple sources + "multiBuilder": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/example1.proto"); + ProtoBuf.loadProtoFile(__dirname+"/example2.proto", builder); + var ns = builder.build(); + test.ok(!!ns.Test1); + test.ok(!!ns.Test2); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Inner messages test + "repeated": { + "legacy": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/repeated.proto"); + var root = builder.build(); + var Outer = root.Outer; + var Inner = root.Inner; + var outer = new Outer({ inner: [new Inner(1), new Inner(2)] }); + var bb = new ByteBuffer(8); + outer.encode(bb); + test.equal("<0A 02 08 01 0A 02 08 02>", bb.toString("debug")); + var douter = Outer.decode(bb); + test.ok(douter.inner instanceof Array); + test.equal(douter.inner.length, 2); + test.equal(douter.inner[0].inner_value, 1); + test.equal(douter.inner[1].inner_value, 2); + test.ok(douter.innerPacked instanceof Array); + test.equal(douter.innerPacked.length, 0); + } catch (e) { + fail(e); + } + test.done(); + }, + + "packed": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/repeated.proto"); + var root = builder.build(); + var Outer = root.Outer; + var Inner = root.Inner; + var outer = new Outer({ innerPacked: [new Inner(1), new Inner(2)] }); + var bb = new ByteBuffer(8); + outer.encode(bb); + test.equal("<12 06 02 08 01 02 08 02>", bb.toString("debug")); + var douter = Outer.decode(bb); + test.ok(douter.inner instanceof Array); + test.equal(douter.inner.length, 0); + test.ok(douter.innerPacked instanceof Array); + test.equal(douter.innerPacked.length, 2); + test.equal(douter.innerPacked[0].inner_value, 1); + test.equal(douter.innerPacked[1].inner_value, 2); + } catch (e) { + fail(e); + } + test.done(); + }, + + "both": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/repeated.proto"); + var root = builder.build(); + var Outer = root.Outer; + var Inner = root.Inner; + var outer = new Outer({ inner: [new Inner(1), new Inner(2)], innerPacked: [new Inner(3), new Inner(4)] }); + var bb = new ByteBuffer(16); + outer.encode(bb); + test.equal("<0A 02 08 01 0A 02 08 02 12 06 02 08 03 02 08 04>", bb.toString("debug")); + var douter = Outer.decode(bb); + test.ok(douter.inner instanceof Array); + test.equal(douter.inner.length, 2); + test.equal(douter.inner[0].inner_value, 1); + test.equal(douter.inner[1].inner_value, 2); + test.ok(douter.innerPacked instanceof Array); + test.equal(douter.innerPacked.length, 2); + test.equal(douter.innerPacked[0].inner_value, 3); + test.equal(douter.innerPacked[1].inner_value, 4); + } catch (e) { + fail(e); + } + test.done(); + }, + + "none": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/repeated.proto"); + var Outer = builder.build("Outer"); + var outer = new Outer(); + var bb = new ByteBuffer(1); + outer.encode(bb); + test.equal("|00 ", bb.toString("debug")); + var douter = Outer.decode(bb); + test.ok(douter.inner instanceof Array); + test.equal(douter.inner.length, 0); + test.ok(douter.innerPacked instanceof Array); + test.equal(douter.innerPacked.length, 0); + } catch (e) { + fail(e); + } + test.done(); + } + }, + + "x64Fixed": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/x64.proto"); + var Test = builder.build("Test"); + var myTest = new Test(); + test.ok(myTest.val instanceof ByteBuffer.Long); + test.equal(myTest.val.unsigned, false); + test.equal(myTest.val.toNumber(), -1); + test.ok(myTest.uval instanceof ByteBuffer.Long); + test.equal(myTest.uval.unsigned, true); + test.equal(myTest.uval.toNumber(), 1); + + myTest.setVal(-2); + myTest.setUval(2); + var bb = new ByteBuffer(18); // 2x tag + 2x 64bit + myTest.encode(bb); + test.equal(bb.toString("debug"), "<09 FE FF FF FF FF FF FF FF 11 02 00 00 00 00 00 00 00>"); + // ^ wireType=1, id=1 ^ wireType=1, id=2 + myTest = Test.decode(bb); + test.ok(myTest.val instanceof ByteBuffer.Long); + test.equal(myTest.val.unsigned, false); + test.equal(myTest.val.toNumber(), -2); + test.ok(myTest.uval instanceof ByteBuffer.Long); + test.equal(myTest.uval.unsigned, true); + test.equal(myTest.uval.toNumber(), 2); + } catch (e) { + fail(e); + } + test.done(); + }, + + "x64Varint": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/x64.proto"); + var Test = builder.build("Test2"); + var myTest = new Test(); + test.ok(myTest.val instanceof ByteBuffer.Long); + test.equal(myTest.val.unsigned, false); + test.equal(myTest.val.toNumber(), -1); + test.ok(myTest.uval instanceof ByteBuffer.Long); + test.equal(myTest.uval.unsigned, true); + test.equal(myTest.uval.toNumber(), 1); + test.ok(myTest.sval instanceof ByteBuffer.Long); + test.equal(myTest.sval.unsigned, false); + test.equal(myTest.sval.toNumber(), -2); + + myTest.setVal(-2); + myTest.setUval(2); + myTest.setSval(-3); + var bb = new ByteBuffer(3+10+2); // 3x tag + 1x varint 10byte + 2x varint 1byte + myTest.encode(bb); + test.equal(bb.toString("debug"), "<08 FE FF FF FF FF FF FF FF FF 01 10 02 18 05>"); + // 08: wireType=0, id=1, 18: wireType=0, id=2, ?: wireType=0, id=3 + myTest = Test.decode(bb); + test.ok(myTest.val instanceof ByteBuffer.Long); + test.equal(myTest.val.unsigned, false); + test.equal(myTest.val.toNumber(), -2); + test.ok(myTest.uval instanceof ByteBuffer.Long); + test.equal(myTest.uval.unsigned, true); + test.equal(myTest.uval.toNumber(), 2); + test.ok(myTest.sval instanceof ByteBuffer.Long); + test.equal(myTest.sval.unsigned, false); + test.equal(myTest.sval.toNumber(), -3); + } catch (e) { + fail(e); + } + test.done(); + }, + + "imports": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/imports.proto"); + var root = builder.build(); + test.ok(!!root.Test1); + test.ok(!!root.Test2); + test.ok(!!root.My.Test2); + test.notEqual(root.Test2, root.My.Test2); + } catch (e) { + fail(e); + } + test.done(); + }, + + "toplevel": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/toplevel.proto"); + var My = builder.build("My"); + test.ok(!!My.MyEnum); + test.equal(My.MyEnum.ONE, 1); + test.equal(My.MyEnum.TWO, 2); + test.ok(!!My.Test); + var myTest = new My.Test(); + test.equal(myTest.num, My.MyEnum.ONE); + } catch (e) { + fail(e); + } + test.done(); + }, + + "importsToplevel": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/imports-toplevel.proto"); + var My = builder.build("My"); + test.ok(!!My.MyEnum); + test.equal(My.MyEnum1.ONE, 1); + test.equal(My.MyEnum1.TWO, 2); + test.ok(!!My.Test1); + var myTest = new My.Test1(); + test.equal(myTest.num, My.MyEnum.ONE); + test.equal(myTest.num1, My.MyEnum1.ONE); + } catch (e) { + fail(e); + } + test.done(); + }, + + "importDuplicate": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/import_a.proto"); + test.doesNotThrow(function() { + ProtoBuf.loadProtoFile(__dirname+"/import_b.proto", builder); + }); + var root = builder.build(); + test.ok(root.A); + test.ok(root.B); + test.ok(root.Common); + } catch (e) { + fail(e); + } + test.done(); + }, + + "importDuplicateDifferentBuilder": function(test) { + try { + var builderA = ProtoBuf.loadProtoFile(__dirname+"/import_a.proto"); + var builderB; + test.doesNotThrow(function() { + builderB = ProtoBuf.loadProtoFile(__dirname+"/import_b.proto"); + }); + var rootA = builderA.build(); + var rootB = builderB.build(); + test.ok(rootA.A); + test.ok(rootB.B); + test.ok(rootA.Common); + test.ok(rootB.Common); + } catch (e) { + fail(e); + } + test.done(); + }, + + "importRoot": function(test) { + try { + var builder = ProtoBuf.loadProtoFile({ + root: __dirname, + file: "importRoot/file1.proto" + }); + var Test = builder.build("Test"); + test.ok(new Test() instanceof ProtoBuf.Builder.Message); + } catch (e) { + fail(e); + } + test.done(); + }, + + "extend": function(test) { + try { + var ast = new ProtoBuf.DotProto.Parser(fs.readFileSync(__dirname+"/extend.proto")).parse(); + test.deepEqual(ast, { + "package": null, + "messages": [ + { + "ref": "google.protobuf.MessageOptions", + "fields": [ + { + "rule": "optional", + "type": "int32", + "name": "foo", + "id": 123, + "options": {} + } + ] + }, + { + "name": "Foo", + "fields": [], + "enums": [], + "messages": [], + "options": {}, + "extensions": [2,536870911] + }, + { + "ref": "Foo", + "fields":[ + { + "rule": "optional", + "type": "string", + "name": "bar", + "id": 2, + "options": {} + } + ] + }, + { + "name": "Bar", + "fields": [], + "enums": [], + "messages": [ + { + "ref": "Foo", + "fields": [ + { + "rule": "optional", + "type": "Bar", + "name": "bar2", + "id": 3, + "options": {} + } + ] + } + ], + "options": {} + } + ], + "enums": [], + "imports": [ + "google/protobuf/descriptor.proto" + ], + "options": {}, + "services": [] + }); + + var builder = ProtoBuf.loadProtoFile(__dirname+"/extend.proto"); + var TFoo = builder.lookup("Foo"), + TBar = builder.lookup("Bar"), + fields = TFoo.getChildren(ProtoBuf.Reflect.Message.Field); + test.strictEqual(fields.length, 2); + test.strictEqual(fields[0].name, "bar"); + test.strictEqual(fields[0].id, 2); + test.strictEqual(fields[1].name, "bar2"); + test.strictEqual(fields[1].id, 3); + test.deepEqual(TFoo.extensions, [2, ProtoBuf.Lang.ID_MAX]); // Defined + test.deepEqual(TBar.extensions, [ProtoBuf.Lang.ID_MIN, ProtoBuf.Lang.ID_MAX]); // Undefined + // test.strictEqual(TBar.getChildren(ProtoBuf.Reflect.Message.Field).length, 0); + var root = builder.build(); + var foo = new root.Foo(), + bar = new root.Bar(); + test.ok(typeof foo.setBar === 'function'); + // test.ok(foo instanceof root.Bar.Foo); + foo.bar = "123"; + foo.bar2 = bar; + test.equal(foo.encode().compact().toString("debug"), "<12 03 31 32 33 1A 00>"); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Custom options on all levels + // victorr (https://github.com/victorr) + "customOptions": function(test) { + try { + var parser = new ProtoBuf.DotProto.Parser(ProtoBuf.Util.fetch(__dirname+"/custom-options.proto")); + var root = parser.parse(); + test.equal(root["options"]["(my_file_option)"], "Hello world!"); + test.equal(root["messages"][7]["options"]["(my_message_option)"], 1234); + test.equal(root["messages"][7]["fields"][0]["options"]["(my_field_option)"], 4.5); + // test.equal(root["services"]["MyService"]["options"]["my_service_option"], "FOO"); + // TODO: add tests for my_enum_option, my_enum_value_option + } catch (e) { + fail(e); + } + test.done(); + }, + + "services": function(test) { + try { + var parser = new ProtoBuf.DotProto.Parser(ProtoBuf.Util.fetch(__dirname+"/custom-options.proto")); + var root = parser.parse(); + test.deepEqual(root["services"], [{ + "name": "MyService", + "rpc": { + "MyMethod": { + "request": "RequestType", + "response": "ResponseType", + "options": { + "(my_method_option).foo": 567, + "(my_method_option).bar": "Some string" + } + } + }, + "options": { + "(my_service_option)": "FOO" + } + }]); + + var builder = ProtoBuf.loadProtoFile(__dirname+"/custom-options.proto"); + var root = builder.build(), + MyService = root.MyService, + RequestType = root.RequestType, + ResponseType = root.ResponseType, + called = false; + + test.deepEqual(MyService.$options, { + "(my_service_option)": "FOO" + }); + test.deepEqual(MyService.MyMethod.$options, { + "(my_method_option).foo": 567, + "(my_method_option).bar": "Some string" + }); + + // Provide the service with your actual RPC implementation based on whatever framework you like most. + var myService = new MyService(function(method, req, callback) { + test.strictEqual(method, ".MyService.MyMethod"); + test.ok(req instanceof RequestType); + called = true; + + // In this case we just return no error and our pre-built response. This must be properly async! + setTimeout(callback.bind(this, null, (new ResponseType()).encode() /* as raw bytes for debugging */ )); + }); + + test.deepEqual(myService.$options, MyService.$options); + test.deepEqual(myService.MyMethod.$options, MyService.MyMethod.$options); + + // Call the service with your request message and provide a callback. This will call your actual service + // implementation to perform the request and gather a response before calling the callback. If the + // request or response type is invalid i.e. not an instance of RequestType or ResponseType, your + // implementation will not be called as ProtoBuf.js handles this case internally and directly hands the + // error to your callback below. + myService.MyMethod(new RequestType(), function(err, res) { + // We get: err = null, res = our prebuilt response. And that's it. + if (err !== null) { + fail(err); + } + test.strictEqual(called, true); + test.ok(res instanceof ResponseType); + test.done(); + }); + } catch (e) { + fail(e); + } + }, + + // Properly ignore "syntax" and "extensions" keywords + "gtfs-realtime": function(test) { + try { + test.doesNotThrow(function() { + ProtoBuf.loadProtoFile(__dirname+"/gtfs-realtime.proto"); + }); + } catch (e) { + fail(e); + } + test.done(); + }, + + "fields": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/optional.proto"); + var Test1 = builder.build("Test1"); + var test1 = new Test1(); + test.strictEqual(test1.a, null); + test.deepEqual(Object.keys(test1), ['a']); + var bb = test1.encode(); + test1 = Test1.decode(bb); + test.strictEqual(test1.a, null); + test.deepEqual(Object.keys(test1), ['a']); + } catch (e) { + fail(e); + } + test.done(); + }, + + "fieldsToCamelCase": function(test) { + try { + ProtoBuf.convertFieldsToCamelCase = true; + var builder = ProtoBuf.loadProtoFile(__dirname+"/camelcase.proto"); + var Test = builder.build("Test"), + TTest = builder.lookup("Test"); + var msg = new Test(); + + // Reverted collision on 1st + test.strictEqual(msg.some_field, null); + test.strictEqual(msg.someField, null); + test.equal(TTest.getChild("some_field").id, 1); + test.equal(TTest.getChild("someField").id, 2); + + + // Reverted collision on 2nd + test.strictEqual(msg.aField, null); + test.strictEqual(msg.a_field, null); + test.equal(TTest.getChild("aField").id, 3); + test.equal(TTest.getChild("a_field").id, 4); + + // No collision + test.strictEqual(msg.itsAField, null); + test.equal(TTest.getChild("itsAField").id, 5); + + test.ok(typeof msg.set_its_a_field === "function"); + test.ok(typeof msg.setItsAField === "function"); + + ProtoBuf.convertFieldsToCamelCase = false; + } catch (e) { + ProtoBuf.convertFieldsToCamelCase = false; + fail(e); + } + test.done(); + }, + + "setarray": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/setarray.proto"); + var root = builder.build(), + Outer = root.Outer, + Inner = root.Inner, + inners = []; + + // Array of repeated messages + inners.push(new Inner("a"), new Inner("b"), new Inner("c")); + var outer = new Outer(); + outer.setInners(inners); + test.deepEqual(outer.inners, inners); + + // Array of repeated message objects + inners = []; + inners.push({ str: 'a' }, { str: 'b' }, { str: 'c' }); + outer.setInners(inners); // Converts + test.ok(outer.inners[0] instanceof Inner); + test.deepEqual(outer.inners, inners); + } catch (e) { + fail(e); + } + test.done(); + }, + + + // Make sure that our example at https://github.com/dcodeIO/ProtoBuf.js/wiki is not nonsense + "pingexample": function(test) { + try { + var builder = ProtoBuf.loadProtoFile(__dirname+"/PingExample.proto"); + var Message = builder.build("Message"); + var msg = new Message(); + msg.ping = new Message.Ping(123456789); + var bb = msg.encode(); + test.strictEqual(bb.length, 7); + msg = Message.decode(bb); + test.ok(msg.ping); + test.notOk(msg.pong); + test.strictEqual(msg.ping.time, 123456789); + } catch (e) { + fail(e); + } + test.done(); + }, + + "negEnumId": function(test) { + try { + test.doesNotThrow(function() { + var builder = ProtoBuf.loadProtoFile(__dirname+"/negid.proto"); + var Test = builder.build("Test"); + test.strictEqual(Test.LobbyType.INVALID, -1); + var t = new Test(Test.LobbyType.INVALID); + test.strictEqual(t.type, -1); + var bb = t.encode(); + t = Test.decode(bb); + test.strictEqual(t.type, -1); + }); + } catch (e) { + fail(e); + } + test.done(); + }, + + "base64": function(test) { + try { + var Message = ProtoBuf.loadProto("message Message { required string s = 1; }").build("Message"); + var msg = new Message("ProtoBuf.js"); + var b64 = msg.toBase64(); + test.strictEqual(b64, "CgtQcm90b0J1Zi5qcw=="); + var msg2 = Message.decode64(b64); + test.deepEqual(msg, msg2); + msg2 = Message.decode(b64, "base64"); + test.deepEqual(msg, msg2); + } catch (e) { + fail(e); + } + test.done(); + }, + + "hex": function(test) { + try { + var Message = ProtoBuf.loadProto("message Message { required string s = 1; }").build("Message"); + var msg = new Message("ProtoBuf.js"); + var hex = msg.toHex(); + test.strictEqual(hex, "0A0B50726F746F4275662E6A73"); + var msg2 = Message.decodeHex(hex); + test.deepEqual(msg, msg2); + msg2 = Message.decode(hex, "hex"); + test.deepEqual(msg, msg2); + } catch (e) { + fail(e); + } + test.done(); + }, + + "forwardComp": function(test) { + try { + var Message = ProtoBuf.loadProto("message Message { required int32 a = 1; required string b = 2; required float c = 3; }").build("Message"); + var msg = new Message(123, "abc", 0.123); + var bb = msg.encode(); + Message = ProtoBuf.loadProto("message Message {}").build("Message"); + test.doesNotThrow(function() { + Message.decode(bb); + }); + test.strictEqual(bb.offset, bb.length); + } catch (e) { + fail(e); + } + test.done(); + }, + + "tokenizerLine": function(test) { + try { + var parser = new ProtoBuf.DotProto.Parser("package test;\n\nmessage Message {\n\trequired string invalid = 1;}ERROR\n"), + ast = null, err = null; + try { + ast = parser.parse(); + } catch (caught) { + err = caught; + } + test.ok(err); + test.notOk(ast); + test.ok(err.message.indexOf("line 4:") >= 0); + } catch (e) { + fail(e); + } + test.done(); + }, + + "excludeFields": function(test) { + try { + var builder = ProtoBuf.loadProto("message A { required int32 i = 1; } message B { required A A = 1; }"); + builder.build(); + } catch (e) { + fail(e); + } + test.done(); + }, + + "proto2jsExtend": function(test) { + try { + var builder = ProtoBuf.loadJsonFile(__dirname+"/proto2js/Bar.json"); + builder.build(); + } catch (e) { + fail(e); + } + test.done(); + }, + + "emptyMessage": function(test) { + try { + var builder = ProtoBuf.loadProto("message EmptyMessage {}"), + EmptyMessage = builder.build("EmptyMessage"); + + var msg = new EmptyMessage(), + ab = msg.toArrayBuffer(); + test.strictEqual(ab.byteLength, 0); + } catch (e) { + fail(e); + } + test.done(); + }, + + // Node.js only + "loaders": BROWSER ? {} : { + + "commonjs": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + module: { + exports: {} + }, + require: (function() { + function require(mod) { + if (mod == 'bytebuffer') require.called = true; + return ByteBuffer; + } + require.called = false; + return require; + })() + }); + vm.runInNewContext(code, sandbox, "ProtoBuf.js in CommonJS-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.module.exports == 'object'); + test.ok(typeof sandbox.require != 'undefined' && sandbox.require.called); + test.done(); + }, + + "amd": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + define: (function() { + function define() { + define.called = true; + } + define.amd = true; + define.called = false; + return define; + })() + }); + vm.runInNewContext(code, sandbox, "ProtoBuf.js in AMD-VM"); + // console.log(util.inspect(sandbox)); + test.ok(sandbox.define.called == true); + test.done(); + }, + + "shim": function(test) { + var fs = require("fs") + , vm = require("vm") + , util = require('util'); + + var code = fs.readFileSync(__dirname+"/../"+FILE); + var sandbox = new Sandbox({ + dcodeIO: { + ByteBuffer: ByteBuffer + } + }); + vm.runInNewContext(code, sandbox, "ProtoBuf.js in shim-VM"); + // console.log(util.inspect(sandbox)); + test.ok(typeof sandbox.dcodeIO != 'undefined' && typeof sandbox.dcodeIO.ProtoBuf != 'undefined'); + test.done(); + } + } + }; + + if (typeof module != 'undefined' && module.exports) { + module.exports = suite; + } else { + global["suite"] = suite; + } + +})(this); diff --git a/javascript/node_modules/protobufjs/tests/toplevel.proto b/javascript/node_modules/protobufjs/tests/toplevel.proto new file mode 100644 index 0000000..eec948e --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/toplevel.proto @@ -0,0 +1,10 @@ +package My; + +enum MyEnum { + ONE = 1; + TWO = 2; +} + +message Test { + required MyEnum num = 1 [default=ONE]; +} diff --git a/javascript/node_modules/protobufjs/tests/x64.proto b/javascript/node_modules/protobufjs/tests/x64.proto new file mode 100644 index 0000000..18ea2d3 --- /dev/null +++ b/javascript/node_modules/protobufjs/tests/x64.proto @@ -0,0 +1,10 @@ +message Test { + required sfixed64 val = 1 [default=-1]; + required fixed64 uval = 2 [default=1]; +} + +message Test2 { + required int64 val = 1 [default=-1]; + required uint64 uval = 2 [default=1]; + required sint64 sval = 3 [default=-2]; +} diff --git a/javascript/step_implementation.js b/javascript/step_implementation.js new file mode 100644 index 0000000..9d28ca3 --- /dev/null +++ b/javascript/step_implementation.js @@ -0,0 +1,15 @@ + +var twist = require("./twist") + +twist.step("test step", function() { + console.log("inside step implementation"); +}); + +twist.step("test step with {arg0} and {arg1}", function(arg0, arg1) { + console.log("inside step implementation with args"); + console.log(arg0); + console.log(arg1); +}); + +var util = require('util'); + diff --git a/javascript/twist.js b/javascript/twist.js new file mode 100755 index 0000000..9ab3c5f --- /dev/null +++ b/javascript/twist.js @@ -0,0 +1,126 @@ + +var steps = {} +var messageProcessor = {}; + +module.exports.step = function (steptext, callback) { + steps[steptext] = callback; +} + +require('./step_implementation') + +var protoBuf = require("protobufjs"); +var builder = protoBuf.loadProtoFile("../messages.proto"); + + +var s = require('net').Socket(); +s.connect(8888, 'localhost'); + +// function dispatchMessage(message) { + +// } + +var util = require('util'); +var ByteBuffer = require("bytebuffer"); +var message = builder.build("main.Message"); + +var ExecutionStarting = 0; +var ExecuteStep = 1; +var ExecuteStepResponse = 2; +var ExecutionEnding = 3; +var StepValidateRequest = 4; +var StepValidateResponse = 5; + +messageProcessor[ExecutionStarting] = function (request) { + return request; +}; + +messageProcessor[StepValidateRequest] = function (request) { + var stepImpl = steps[request.stepValidateRequest.stepText]; + var response = null; + if (stepImpl) { + response = new message({messageId: request.messageId, messageType: StepValidateResponse, stepValidateResponse: { + isValid: true + }}); + } + else { + response = new message({messageId: request.messageId, messageType: StepValidateResponse, stepValidateResponse: { + isValid: false + }}); + } + + return response; +}; + +messageProcessor[ExecuteStep] = function (request) { + var stepImpl = steps[request.executeStepRequest.stepText]; + var response = null; + if (stepImpl) { + try { + var args = request.executeStepRequest.args; + if (args.length == 0) + stepImpl(); + else + stepImpl.apply(this, args); + + response = new message({messageId: request.messageId, messageType: ExecuteStepResponse, executeStepResponse: { + passed: true + }}); + } + catch (e) { + response = new message({messageId: request.messageId, messageType: ExecuteStepResponse, executeStepResponse: { + passed: false, recoverableError: false, errorMessage: e.message + }}); + if (e.stack) { + response.executeStepResponse.stackTrace = e.stack; + } + } + } + else { + console.log("step not implemented"); + } + + return response; +} + +messageProcessor[ExecutionEnding] = function (request) { + s.end(); +}; + +function writeResponse(response) { + var encoded = response.encode().toBuffer(); + + // finding the message length + var messageLengthEncoded = new ByteBuffer(); + messageLengthEncoded.writeVarint64(encoded.length); + var messageLengthEncodedBuffer = messageLengthEncoded.toBuffer(); + + var bufferToWrite = new Buffer(messageLengthEncodedBuffer.length + encoded.length); + messageLengthEncodedBuffer.copy(bufferToWrite); + encoded.copy(bufferToWrite, messageLengthEncodedBuffer.length); + + s.write(bufferToWrite); +} + +s.on('data', function(d){ + var bb = ByteBuffer.wrap(d) + var messageLength = bb.readVarint64(0); + + // Take the remaining part as the actual message + var data = d.slice(messageLength.length, messageLength.value.low + 1); + + var request = message.decode(data); + if (request.messageType == ExecutionEnding) { + writeResponse(request); + s.end(); + } + else { + var response = messageProcessor[request.messageType](request); + writeResponse(response); + } +}); + + + + + + diff --git a/javascript/twist.sh b/javascript/twist.sh new file mode 100755 index 0000000..f198b5e --- /dev/null +++ b/javascript/twist.sh @@ -0,0 +1,2 @@ +#!/bin/sh +cd javascript && node twist.js \ No newline at end of file diff --git a/manifest.json b/manifest.json index d56d9d8..3e544be 100644 --- a/manifest.json +++ b/manifest.json @@ -1,3 +1,3 @@ { - "language": "java" -} \ No newline at end of file + "language": "js" +} diff --git a/runner/js.json b/runner/js.json new file mode 100644 index 0000000..c60273c --- /dev/null +++ b/runner/js.json @@ -0,0 +1,6 @@ +{ + "name": "Ruby runner", + "command": { + "darwin": "javascript/twist.sh" + } +} \ No newline at end of file