From eb9303f8106d063f01854c96ac88607ee8e01d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Sun, 10 Jul 2016 11:55:38 +0200 Subject: [PATCH] Squashed '3rdparty/machinetalk-protobuf/' changes from 4e534c6..314b080 314b080 Merge pull request #62 from mhaberler/master 017ce0a Makefile: make template path configurable, depend on all moving parts 05de663 Merge pull request #60 from machinekit/ArcEye-patch-1 b30e223 Update asciidoc.mustache a292fb0 Merge pull request #58 from strahlex/python-examples 31afa09 Update README.md c123a4a add Python examples and install README dc8c822 Merge pull request #57 from mhaberler/asciidoc-support 72d6749 scripts/asciidoc.mustache: a start - this is still markdown 522d981 Makefile: support different output formats a2494ab Merge pull request #55 from strahlex/doc-fix 7864694 fix automatic build of documentation e56f95d Merge pull request #51 from strahlex/preview-doc 59180cd added some documentation for preview.proto 5621140 Merge pull request #50 from strahlex/small-clean 3f5125c updated js bundle 860a798 types.proto: added generic full and incremental update f2b21dd status.proto: fix case incosistency 8ecfe22 Merge pull request #49 from strahlex/js-bundle e552450 added bundled JavaScript files for browser 0caef9c js: added scripts to create bundle with browserify a52ae93 Merge pull request #46 from strahlex/doc 7efd4b5 Merge pull request #48 from bobvanderlinden/nodejs a289f8b changed the way nodejs packages are created fe0c77d generating single doc file with defined templated 57b2205 Merge pull request #32 from strahlex/unit-cleanup 773843b added machine unit fields b449530 Merge pull request #36 from strahlex/python-setup 517a13e fix protojs paths and disabling of protojs 81a4623 added protobuf folder and module __init__ to git d8e02cc added install rules for .proto and .h files 0ae22d8 create separate build directory to hold all ouputs b3d8036 build C++, Python, Js, objects all with namespace directories 41ebbcc initial work for Python packaging 9b30785 Merge pull request #35 from strahlex/doc 9d8ad18 Merge pull request #38 from bobvanderlinden/fix-qeueue 126b476 fixed typo in INTERP_QEUEUE_WAIT to INTERP_QUEUE_WAIT 5c1a401 Merge pull request #37 from bobvanderlinden/python-environment c5c2737 use python from environment 2de4ee6 Added documenation for status.proto a38a012 Added doc generator 5900be6 Merge pull request #33 from strahlex/tool-table-offset a4ca021 machinetalk-protobuf: replaced tool table offset fields 621f595 Merge pull request #31 from strahlex/python2_3 cae23c4 fix backwards compatibility with Python2 e653531 Merge pull request #29 from strahlex/origin-fix f73e663 Merge pull request #30 from strahlex/emccmd-feedback 80dc355 added types for command feedback f00172a OriginIndex: added ORIGIN_UNKNOWN field: 348d0a9 Merge pull request #23 from bobvanderlinden/unicode-fix b8dda44 protoc-gen-depends: treat stdin/stdout as byte-streams, not as text-streams c00f3a6 Merge pull request #21 from mhaberler/master f2105a1 Update README.md 762b3ad Merge pull request #20 from mhaberler/master 10aad18 Update README.md 7724509 rtapicommand: add task creation flags git-subtree-dir: 3rdparty/machinetalk-protobuf git-subtree-split: 314b0803559666489a794d6518a51215de93cc00 --- .gitignore | 4 +- .npmignore | 6 + Makefile | 171 +- README.javascript | 37 - README.md | 86 +- dist/README.md | 21 + dist/machinetalk-protobuf.js | 50311 ++++++++++++++++ dist/machinetalk-protobuf.min.js | 61 + dist/machinetalk-protobuf.min.js.gz | Bin 0 -> 70104 bytes dist/machinetalk-protobuf.min.map.json | 1 + js/examples/decoding_message_container.js | 9 + js/examples/encoding_message_container.js | 15 + js/index.js | 1 + js/scripts/bundle.js | 60 + js/scripts/install.js | 49 + package.json | 33 + proto/preview.proto | 115 - proto/status.proto | 378 - python/examples/decode_message_container.py | 13 + python/examples/encode_message_container.py | 15 + python/machinetalk/__init__.py | 1 + python/machinetalk/protobuf/__init__.py | 1 + python/setup.py | 133 + scripts/asciidoc.mustache | 45 + scripts/markdown.mustache | 56 + scripts/protoc-gen-depends | 17 +- {proto => src}/README.msgid | 0 .../machinetalk/protobuf}/canon.proto | 8 +- .../machinetalk/protobuf}/config.proto | 2 +- .../machinetalk/protobuf}/emcclass.proto | 2 +- {proto => src/machinetalk/protobuf}/log.proto | 4 +- .../machinetalk/protobuf}/message.proto | 28 +- .../machinetalk/protobuf}/motcmds.proto | 4 +- .../machinetalk/protobuf}/nanopb.proto | 0 .../machinetalk/protobuf}/object.proto | 4 +- src/machinetalk/protobuf/preview.proto | 127 + .../machinetalk/protobuf}/rtapi_message.proto | 4 +- .../machinetalk/protobuf}/rtapicommand.proto | 3 +- src/machinetalk/protobuf/status.proto | 492 + .../machinetalk/protobuf}/task.proto | 4 +- .../machinetalk/protobuf}/test.proto | 4 +- .../machinetalk/protobuf}/types.proto | 13 +- .../machinetalk/protobuf}/value.proto | 6 +- 43 files changed, 51684 insertions(+), 660 deletions(-) create mode 100644 .npmignore delete mode 100644 README.javascript create mode 100644 dist/README.md create mode 100644 dist/machinetalk-protobuf.js create mode 100644 dist/machinetalk-protobuf.min.js create mode 100644 dist/machinetalk-protobuf.min.js.gz create mode 100644 dist/machinetalk-protobuf.min.map.json create mode 100644 js/examples/decoding_message_container.js create mode 100644 js/examples/encoding_message_container.js create mode 100644 js/index.js create mode 100755 js/scripts/bundle.js create mode 100755 js/scripts/install.js create mode 100644 package.json delete mode 100644 proto/preview.proto delete mode 100644 proto/status.proto create mode 100644 python/examples/decode_message_container.py create mode 100644 python/examples/encode_message_container.py create mode 100644 python/machinetalk/__init__.py create mode 100644 python/machinetalk/protobuf/__init__.py create mode 100644 python/setup.py create mode 100644 scripts/asciidoc.mustache create mode 100644 scripts/markdown.mustache rename {proto => src}/README.msgid (100%) rename {proto => src/machinetalk/protobuf}/canon.proto (96%) rename {proto => src/machinetalk/protobuf}/config.proto (98%) rename {proto => src/machinetalk/protobuf}/emcclass.proto (96%) rename {proto => src/machinetalk/protobuf}/log.proto (81%) rename {proto => src/machinetalk/protobuf}/message.proto (94%) rename {proto => src/machinetalk/protobuf}/motcmds.proto (99%) rename {proto => src/machinetalk/protobuf}/nanopb.proto (100%) rename {proto => src/machinetalk/protobuf}/object.proto (98%) create mode 100644 src/machinetalk/protobuf/preview.proto rename {proto => src/machinetalk/protobuf}/rtapi_message.proto (85%) rename {proto => src/machinetalk/protobuf}/rtapicommand.proto (89%) create mode 100644 src/machinetalk/protobuf/status.proto rename {proto => src/machinetalk/protobuf}/task.proto (96%) rename {proto => src/machinetalk/protobuf}/test.proto (87%) rename {proto => src/machinetalk/protobuf}/types.proto (98%) rename {proto => src/machinetalk/protobuf}/value.proto (87%) diff --git a/.gitignore b/.gitignore index 84e19c8fe..b914a3bd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -objects/* -js/*.js +build +node_modules diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..1eb34d7c2 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +* +!js +!build/js/** +!package.json +!README* +!LICENSE* diff --git a/Makefile b/Makefile index 942eb871a..8f02f1752 100644 --- a/Makefile +++ b/Makefile @@ -24,37 +24,35 @@ else endif ECHO := @echo +DESTDIR := /usr/local # all protobuf definitions live here -PROTODIR := proto +NAMESPACEDIR := machinetalk/protobuf +SRCDIR := src +SRCDIRINV := $(shell realpath --relative-to=$(SRCDIR) .) +PROTODIR := $(SRCDIR)/$(NAMESPACEDIR) +BUILDDIR := build # generated C++ headers + source files -CXXGEN := generated +CXXGEN := $(BUILDDIR)/cpp # generated Python files -PYGEN := python +PYGEN := $(BUILDDIR)/python -# disable protobuf.js per default -PROTOBUFJS := 0 +# generated Documentation files +# default to asciidoc template +# for mk-docs formatting, pass in TEMPLATE pointing to the mk-docs template +TEMPLATE := $(SRCDIRINV)/scripts/asciidoc.mustache +DOCFORMAT := asciidoc +DOCEXT := asciidoc +#DOCFORMAT := markdown +#DOCEXT := md -# directory for ProtoBuf.js generated files -PROTOBUFJS_GEN := js - -# the proto2js compiler -PROTOJS := $(shell which proto2js) +DOCGEN := $(BUILDDIR)/doc # pkg-config PKG_CONFIG := $(shell which pkg-config) -# proto2js options - namespace -#PROTOBUFJS_OPT := -commonjs=pb -# http://en.wikipedia.org/wiki/Asynchronous_module_definition -#PROTOBUFJS_OPT := -amd -PROTOBUFJS_OPT := -class - -# protobuf namespace; all protos except nanopb.proto -JSNAMESPACE := =pb - # the set of all proto specs generated files depend on PROTO_SPECS := $(wildcard $(PROTODIR)/*.proto) @@ -66,67 +64,71 @@ GPBINCLUDE := $(shell $(PKG_CONFIG) --variable=includedir protobuf) DESCDIR := $(GPBINCLUDE)/google/protobuf # object files generated during dependency resolving -OBJDIR := objects +OBJDIR := $(BUILDDIR)/objects # search path for .proto files # see note on PBDEP_OPT below vpath %.proto $(PROTODIR):$(GPBINCLUDE):$(DESCDIR)/compiler # machinetalk/proto/*.proto derived Python bindings -PROTO_PY_TARGETS += $(subst $(PROTODIR)/, \ - $(PYGEN)/, \ - $(patsubst %.proto, %_pb2.py, $(PROTO_SPECS))) +PROTO_PY_TARGETS := ${PROTO_SPECS:$(SRCDIR)/%.proto=$(PYGEN)/%_pb2.py} +PROTO_PY_EXTRAS := $(PYGEN)/setup.py $(PYGEN)/machinetalk/__init__.py $(PYGEN)/machinetalk/protobuf/__init__.py # generated C++ includes -PROTO_CXX_INCS := $(subst $(PROTODIR)/, \ - $(CXXGEN)/, \ - $(patsubst %.proto, %.pb.h, $(PROTO_SPECS))) +PROTO_CXX_INCS := ${PROTO_SPECS:$(SRCDIR)/%.proto=$(CXXGEN)/%.pb.h} # generated C++ sources -PROTO_CXX_SRCS := $(subst $(PROTODIR)/, \ - $(CXXGEN)/, \ - $(patsubst %.proto, %.pb.cc, $(PROTO_SPECS))) +PROTO_CXX_SRCS := ${PROTO_SPECS:$(SRCDIR)/%.proto=$(CXXGEN)/%.pb.cc} +# generated doc file +DOC_TARGET := $(DOCGEN)/machinetalk-protobuf.$(DOCEXT) # ---- generate dependcy files for .proto files # # the list of .d dep files for .proto files: -PROTO_DEPS := $(patsubst %,$(OBJDIR)/%,$(patsubst %.proto,%.d,$(PROTO_SPECS))) +PROTO_DEPS := ${PROTO_SPECS:$(SRCDIR)/%.proto=$(OBJDIR)/%.d} + # # options to the dependency generator protoc plugin PBDEP_OPT := #PBDEP_OPT += --debug PBDEP_OPT += --cgen=$(CXXGEN) PBDEP_OPT += --pygen=$(PYGEN) -PBDEP_OPT += --jsgen=$(PROTOBUFJS_GEN) # this path must match the vpath arrangement exactly or the deps will be wrong # unfortunately there is no way to extract the proto path in the code # generator plugin -PBDEP_OPT += --vpath=$(PROTODIR) +PBDEP_OPT += --vpath=$(SRCDIR) PBDEP_OPT += --vpath=$(GPBINCLUDE) PBDEP_OPT += --vpath=$(DESCDIR)/compiler -$(OBJDIR)/$(PROTODIR)/%.d: $(PROTODIR)/%.proto + +GENERATED += \ + $(PROTO_CXX_SRCS)\ + $(PROTO_CXX_INCS) \ + $(PROTO_PY_TARGETS) \ + $(PROTO_PY_EXTRAS) + +$(OBJDIR)/%.d: $(SRCDIR)/%.proto $(ECHO) "protoc create dependencies for $<" - @mkdir -p $(OBJDIR)/$(PROTODIR) + @mkdir -p $(OBJDIR)/ $(Q)$(PROTOC) \ - --plugin=protoc-gen-depends=scripts/protoc-gen-depends \ - --proto_path=$(PROTODIR)/ \ - --proto_path=$(GPBINCLUDE)/ \ - --depends_out="$(PBDEP_OPT)":$(OBJDIR)/$(PROTODIR)/ \ - $< + --plugin=protoc-gen-depends=scripts/protoc-gen-depends \ + --proto_path=$(SRCDIR)/ \ + --proto_path=$(GPBINCLUDE)/ \ + --depends_out="$(PBDEP_OPT)":$(OBJDIR)/ \ + $< #---------- C++ rules ----------- # # generate .cc/.h from proto files # for command.proto, generated files are: command.pb.cc command.pb.h -$(CXXGEN)/%.pb.cc $(CXXGEN)/%.pb.h: %.proto +$(CXXGEN)/%.pb.cc $(CXXGEN)/%.pb.h: $(SRCDIR)/%.proto $(ECHO) "protoc create $@ from $<" @mkdir -p $(CXXGEN) $(Q)$(PROTOC) $(PROTOCXX_FLAGS) \ - --proto_path=$(PROTODIR)/ \ + --proto_path=$(SRCDIR)/ \ --proto_path=$(GPBINCLUDE)/ \ - --cpp_out=$(CXXGEN)/ \ + --cpp_out=$(CXXGEN) \ $< # ------------- Python rules ------------ @@ -135,61 +137,58 @@ $(CXXGEN)/%.pb.cc $(CXXGEN)/%.pb.h: %.proto # adapt here if using one of the accelerated methods # # generate Python modules from proto files -$(PYGEN)/%_pb2.py: %.proto +$(PYGEN)/%_pb2.py: $(SRCDIR)/%.proto $(ECHO) "protoc create $@ from $<" @mkdir -p $(PYGEN) $(Q)$(PROTOC) $(PROTOC_FLAGS) \ - --proto_path=$(PROTODIR)/ \ - --proto_path=$(GPBINCLUDE)/ \ - --python_out=$(PYGEN)/ \ - $< - -# ------------- ProtoBuf.js rules ------------ -# -# see https://github.com/dcodeIO/ProtoBuf.js -# -# generate Javascript modules from proto files -#=$(filter-out %/butterfly.ngc,$(call GLOB,../nc_files/*)) - -$(PROTOBUFJS_GEN)/%.js: %.proto - $(ECHO) $(PROTOJS)" create $@ from $<" - @mkdir -p $(PROTOBUFJS_GEN) - $(Q)$(PROTOJS) $< \ - $(PROTOBUFJS_OPT)$(JSNAMESPACE) \ - > $@ - -# nanopb.proto needs different opts - no namespace argument -$(PROTOBUFJS_GEN)/nanopb.js: $(PROTODIR)/nanopb.proto - $(ECHO) $(PROTOJS)" create $@ from $<" - @mkdir -p $(PROTOBUFJS_GEN) - $(Q)$(PROTOJS) $< \ - $(PROTOBUFJS_OPT) \ - > $@ - -# generated Javasript sources -# everything is namespace pb except nanopb.proto -PROTO_PROTOBUFJS_SRCS := $(subst $(PROTODIR)/, \ - $(PROTOBUFJS_GEN)/, \ - $(filter-out $(PROTODIR)/nanopb.js, $(patsubst %.proto, %.js, $(PROTO_SPECS)))) - - -GENERATED += $(PROTO_PY_TARGETS) \ - $(PROTO_CXX_SRCS)\ - $(PROTO_CXX_INCS) - + --proto_path=$(SRCDIR)/ \ + --proto_path=$(GPBINCLUDE)/ \ + --python_out=$(PYGEN)/ \ + $< -ifeq ($(PROTOBUFJS),1) -GENERATED += $(PROTO_PROTOBUFJS_SRCS) $(PROTOBUFJS_GEN)/nanopb.js -endif +$(PYGEN)/%.py: python/%.py + cp "$<" "$@" # force create of %.proto-dependent files and their deps Makefile: $(GENERATED) $(PROTO_DEPS) -include $(PROTO_DEPS) +# ------------- protoc-gen-doc rules ------------ +# +# see https://github.com/estan/protoc-gen-doc +# +# generate $(DOCFORMAT) files from proto files +$(DOC_TARGET): $(wildcard $(SRCDIR)/*.proto) $(TEMPLATE) Makefile +#doc_base: + $(ECHO) "protoc create $@ from *.proto" + @mkdir -p $(DOCGEN) + $(Q)cd $(SRCDIR); \ + $(PROTOC) $(PROTOC_FLAGS) \ + --proto_path=./ \ + --proto_path=$(GPBINCLUDE)/ \ + --doc_out=$(TEMPLATE),$(SRCDIRINV)/$@:./ \ + $(NAMESPACEDIR)/*.proto + +all: $(GENERATED) $(PROTO_DEPS) + ios_replace: sh scripts/ios-replace.sh $(CXXGEN) -all: $(PROTO_DEPS) $(GENERATED) +docs: $(PROTO_DEPS) $(DOC_TARGET) clean: - rm -rf $(OBJDIR) $(CXXGEN) $(PYGEN) $(PROTO_PROTOBUFJS_SRCS) + rm -rf build + +install_proto: $(PROTO_SPECS) + mkdir -p $(DESTDIR)/include/$(NAMESPACEDIR) + for proto in $(PROTO_SPECS); do \ + install -m 0644 $$proto $(DESTDIR)/include/$(NAMESPACEDIR); \ + done + +install_cpp: $(PROTO_CXX_INCS) + mkdir -p $(DESTDIR)/include/$(NAMESPACEDIR) + for headerfile in $(PROTO_CXX_INCS); do \ + install -m 0644 $$headerfile $(DESTDIR)/include/$(NAMESPACEDIR); \ + done + +install: install_proto install_cpp diff --git a/README.javascript b/README.javascript deleted file mode 100644 index 3e884f42f..000000000 --- a/README.javascript +++ /dev/null @@ -1,37 +0,0 @@ -Experimental Javascript bindings, using ProtoBuf.js: -=================================================== - -see https://github.com/dcodeIO/ProtoBuf.js/wiki - -install nodejs - see https://github.com/joyent/node/wiki/installing-node.js-via-package-manager - - sudo curl -sL https://deb.nodesource.com/setup | bash - - sudo apt-get install nodejs - - npm install bytebuffer - npm install ascli - - git clone https://github.com/dcodeIO/ProtoBuf.js.git - - add /ProtoBuf.js/bin to the PATH - - -then create the Javascript classes: - - make PROTOBUFJS=1 - -browser code fragment: - - - - - - - - - var msg = new pb.Container(); - msg.set_type(pb.ContainerType.MT_PING); - msg.set_note(text.value); - socket.send(msg.toArrayBuffer()); - console.log("hex: " + msg.toHex()+"\n"); - diff --git a/README.md b/README.md index 5313db0c9..841171184 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,92 @@ Protobuf declarations for machinekit messages This repo is integrated into github.com/machinekit/machinekit as a git subtree. -To change message definitions, send a PR against this repo, then update the subtree in the machinekit repo. +To change/add to message definitions: +* send a PR against this repo +* add a new remote in your machinekit repo referring to here +* update the subtree in your machinekit repo like so +``` +git remote add machinetalk-protobuf git://github.com/machinekit/machinetalk-protobuf.git +git fetch machinetalk-protobuf +git subtree merge --prefix=src/machinetalk/proto machinetalk-protobuf/master --squash +``` +Now create a PR against the machinekit repo. +## Python + +### Installation + +To use the Machinetalk protobuf Python modules in your projects, use: + +```sh +cd python +python setup.py build +sudo python setup.py install +``` + +### Usage +See [examples](python/examples). + +## JavaScript (NPM/NodeJS) + +### Installation + +To use machinetalk protobuf definitions in your npm-based projects, use: + +```sh +npm install --save machinetalk-protobuf +``` + +### Usage + +See [examples](js/examples). If you want to try these examples, be sure to first run `npm install` in this repository. + +#### Encoding + +```js +var machinetalkProtobuf = require('machinetalk-protobuf'); +var messageContainer = { + type: machinetalkProtobuf.message.ContainerType.MT_PING +}; +var encodedMessageContainer = machinetalkProtobuf.message.Container.encode(messageContainer); +``` +This results in a buffer that starts with `0x08 0xd2 0x01`. + +#### Decoding + +```js +var machinetalkProtobuf = require('machinetalk-protobuf'); +var encodedBuffer = new Buffer([0x08, 0xd2, 0x01]); +var decodedMessageContainer = machinetalkProtobuf.message.Container.decode(encodedBuffer); +``` +This results in a messageContainer like the one defined in [Encoding](#Encoding). + +## JavaScript (Browser) + +### CDN usage +```html + +``` +With `VERSION` replaced by [a valid tag](https://github.com/machinekit/machinetalk-protobuf/releases) or just `master` for testing +the latest master build. + +### Encoding + +```js +var messageContainer = { + type: machinetalk.protobuf.message.ContainerType.MT_PING +}; +var encodedMessageContainer = machinetalk.protobuf.message.Container.encode(messageContainer); +``` +This results in a buffer that starts with `0x08 0xd2 0x01`. + +#### Decoding + +```js +var encodedBuffer = new ArrayBuffer([0x08, 0xd2, 0x01]); +var decodedMessageContainer = machinetalk.protobuf.message.Container.decode(encodedBuffer); +``` +This results in a messageContainer like the one defined in [Encoding](#Encoding). diff --git a/dist/README.md b/dist/README.md new file mode 100644 index 000000000..2516bd28b --- /dev/null +++ b/dist/README.md @@ -0,0 +1,21 @@ +Distributions +============= + +machinetalk-protobuf.js is available either only with ProtoBuf.js included. + +### Full build including ProtoBuf.js + +* **[machinetalk-protobuf.js](https://raw.githubusercontent.com/machinekit/machinetalk-protobuf/master/dist/machinetalk-protobuf.js)** + contains the commented source code. + +* **[machinetalk-protobuf.min.js](https://raw.githubusercontent.com/machinekit/machinetalk-protobuf/master/dist/machinetalk-protobuf.min.js)** + has been compiled with Closure Compiler. + +* **[machinetalk-protobuf.min.js.gz](https://raw.githubusercontent.com/machinekit/machinetalk-protobuf/master/dist/machinetalk-protobuf.min.js.gz)** + has also been gzipped using `-9`. + +* **[machinetalk-protobuf.min.map](https://raw.githubusercontent.com/machinekit/machinetalk-protobuf/master/dist/machinetalk-protobuf.min.map)** + is the source map generated by Closure Compiler. + +When sending pull requests, please note that these files have been automatically generated from the sources located in +[src/](https://github.com/machinekit/machinekit-protobuf/tree/master/src). diff --git a/dist/machinetalk-protobuf.js b/dist/machinetalk-protobuf.js new file mode 100644 index 000000000..501adeaaa --- /dev/null +++ b/dist/machinetalk-protobuf.js @@ -0,0 +1,50311 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.machinetalk || (g.machinetalk = {})).protobuf = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + setTimeout(drainQueue, 0); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],21:[function(require,module,exports){ +(function (process){ +/* + 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, factory) { + + /* AMD */ if (typeof define === 'function' && define["amd"]) + define(["bytebuffer"], factory); + /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"]) + module["exports"] = factory(require("bytebuffer"), true); + /* Global */ else + (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]); + +})(this, function(ByteBuffer, isCommonJS) { + "use strict"; + + /** + * The ProtoBuf namespace. + * @exports ProtoBuf + * @namespace + * @expose + */ + var ProtoBuf = {}; + + /** + * @type {!function(new: ByteBuffer, ...[*])} + * @expose + */ + ProtoBuf.ByteBuffer = ByteBuffer; + + /** + * @type {?function(new: Long, ...[*])} + * @expose + */ + ProtoBuf.Long = ByteBuffer.Long || null; + + /** + * ProtoBuf.js version. + * @type {string} + * @const + * @expose + */ + ProtoBuf.VERSION = "5.0.0"; + + /** + * 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 + * @expose + */ + ProtoBuf.WIRE_TYPES.STARTGROUP = 3; + + /** + * End group wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.ENDGROUP = 4; + + /** + * Fixed 32 bits wire type. + * @type {number} + * @const + * @expose + */ + ProtoBuf.WIRE_TYPES.BITS32 = 5; + + /** + * Packable wire types. + * @type {!Array.} + * @const + * @expose + */ + ProtoBuf.PACKABLE_WIRE_TYPES = [ + ProtoBuf.WIRE_TYPES.VARINT, + ProtoBuf.WIRE_TYPES.BITS64, + ProtoBuf.WIRE_TYPES.BITS32 + ]; + + /** + * Types. + * @dict + * @type {!Object.} + * @const + * @expose + */ + ProtoBuf.TYPES = { + // According to the protobuf spec. + "int32": { + name: "int32", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: 0 + }, + "uint32": { + name: "uint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: 0 + }, + "sint32": { + name: "sint32", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: 0 + }, + "int64": { + name: "int64", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined + }, + "uint64": { + name: "uint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined + }, + "sint64": { + name: "sint64", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined + }, + "bool": { + name: "bool", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: false + }, + "double": { + name: "double", + wireType: ProtoBuf.WIRE_TYPES.BITS64, + defaultValue: 0 + }, + "string": { + name: "string", + wireType: ProtoBuf.WIRE_TYPES.LDELIM, + defaultValue: "" + }, + "bytes": { + name: "bytes", + wireType: ProtoBuf.WIRE_TYPES.LDELIM, + defaultValue: null // overridden in the code, must be a unique instance + }, + "fixed32": { + name: "fixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32, + defaultValue: 0 + }, + "sfixed32": { + name: "sfixed32", + wireType: ProtoBuf.WIRE_TYPES.BITS32, + defaultValue: 0 + }, + "fixed64": { + name: "fixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64, + defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined + }, + "sfixed64": { + name: "sfixed64", + wireType: ProtoBuf.WIRE_TYPES.BITS64, + defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined + }, + "float": { + name: "float", + wireType: ProtoBuf.WIRE_TYPES.BITS32, + defaultValue: 0 + }, + "enum": { + name: "enum", + wireType: ProtoBuf.WIRE_TYPES.VARINT, + defaultValue: 0 + }, + "message": { + name: "message", + wireType: ProtoBuf.WIRE_TYPES.LDELIM, + defaultValue: null + }, + "group": { + name: "group", + wireType: ProtoBuf.WIRE_TYPES.STARTGROUP, + defaultValue: null + } + }; + + /** + * Valid map key types. + * @type {!Array.>} + * @const + * @expose + */ + ProtoBuf.MAP_KEY_TYPES = [ + ProtoBuf.TYPES["int32"], + ProtoBuf.TYPES["sint32"], + ProtoBuf.TYPES["sfixed32"], + ProtoBuf.TYPES["uint32"], + ProtoBuf.TYPES["fixed32"], + ProtoBuf.TYPES["int64"], + ProtoBuf.TYPES["sint64"], + ProtoBuf.TYPES["sfixed64"], + ProtoBuf.TYPES["uint64"], + ProtoBuf.TYPES["fixed64"], + ProtoBuf.TYPES["bool"], + ProtoBuf.TYPES["string"], + ProtoBuf.TYPES["bytes"] + ]; + + /** + * Minimum field id. + * @type {number} + * @const + * @expose + */ + ProtoBuf.ID_MIN = 1; + + /** + * Maximum field id. + * @type {number} + * @const + * @expose + */ + ProtoBuf.ID_MAX = 0x1FFFFFFF; + + /** + * 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; + + /** + * By default, messages are populated with (setX, set_x) accessors for each field. This can be disabled by + * setting this to `false` prior to building messages. + * @type {boolean} + * @expose + */ + ProtoBuf.populateAccessors = true; + + /** + * By default, messages are populated with default values if a field is not present on the wire. To disable + * this behavior, set this setting to `false`. + * @type {boolean} + * @expose + */ + ProtoBuf.populateDefaults = true; + + /** + * @alias ProtoBuf.Util + * @expose + */ + ProtoBuf.Util = (function() { + "use strict"; + + /** + * ProtoBuf utilities. + * @exports ProtoBuf.Util + * @namespace + */ + var Util = {}; + + /** + * Flag if running in node or not. + * @type {boolean} + * @const + * @expose + */ + Util.IS_NODE = !!( + typeof process === 'object' && process+'' === '[object process]' && !process['browser'] + ); + + /** + * 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} + * @expose + */ + ProtoBuf.Lang = { + + // Characters always ending a statement + DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g, + + // Field rules + RULE: /^(?:required|optional|repeated|map)$/, + + // Field types + TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/, + + // Names + NAME: /^[a-zA-Z_][a-zA-Z_0-9]*$/, + + // Type definitions + TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/, + + // Type references + TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/, + + // Fully qualified type references + FQTYPEREF: /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/, + + // All numbers + NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/, + + // Decimal numbers + NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/, + + // Hexadecimal numbers + NUMBER_HEX: /^0[xX][0-9a-fA-F]+$/, + + // Octal numbers + NUMBER_OCT: /^0[0-7]+$/, + + // Floating point numbers + NUMBER_FLT: /^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/, + + // Booleans + BOOL: /^(?:true|false)$/i, + + // Id numbers + ID: /^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/, + + // Negative id numbers (enum values) + NEGID: /^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/, + + // Whitespaces + WHITESPACE: /\s/, + + // All strings + STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g, + + // Double quoted strings + STRING_DQ: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g, + + // Single quoted strings + STRING_SQ: /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g + }; + + /** + * @alias ProtoBuf.DotProto + * @expose + */ + ProtoBuf.DotProto = (function(ProtoBuf, Lang) { + "use strict"; + + /** + * Utilities to parse .proto files. + * @exports ProtoBuf.DotProto + * @namespace + */ + var DotProto = {}; + + /** + * Constructs a new Tokenizer. + * @exports ProtoBuf.DotProto.Tokenizer + * @class prototype 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; + + /** + * Token stack. + * @type {!Array.} + * @expose + */ + this.stack = []; + + /** + * Opening character of the current string read, if any. + * @type {?string} + * @private + */ + this._stringOpen = null; + }; + + /** + * @alias ProtoBuf.DotProto.Tokenizer.prototype + * @inner + */ + var TokenizerPrototype = Tokenizer.prototype; + + /** + * Reads a string beginning at the current index. + * @return {string} + * @private + */ + TokenizerPrototype._readString = function() { + var re = this._stringOpen === '"' + ? Lang.STRING_DQ + : Lang.STRING_SQ; + re.lastIndex = this.index - 1; // Include the open quote + var match = re.exec(this.source); + if (!match) + throw Error("unterminated string"); + this.index = re.lastIndex; + this.stack.push(this._stringOpen); + this._stringOpen = null; + return match[1]; + }; + + /** + * Gets the next token and advances by one. + * @return {?string} Token or `null` on EOF + * @expose + */ + TokenizerPrototype.next = function() { + if (this.stack.length > 0) + return this.stack.shift(); + if (this.index >= this.source.length) + return null; + if (this._stringOpen !== null) + return this._readString(); + + var repeat, + prev, + next; + do { + repeat = false; + + // Strip white spaces + while (Lang.WHITESPACE.test(next = this.source.charAt(this.index))) { + if (next === '\n') + ++this.line; + if (++this.index === this.source.length) + return null; + } + + // Strip comments + if (this.source.charAt(this.index) === '/') { + ++this.index; + if (this.source.charAt(this.index) === '/') { // Line + while (this.source.charAt(++this.index) !== '\n') + if (this.index == this.source.length) + return null; + ++this.index; + ++this.line; + repeat = true; + } else if ((next = this.source.charAt(this.index)) === '*') { /* Block */ + do { + if (next === '\n') + ++this.line; + if (++this.index === this.source.length) + return null; + prev = next; + next = this.source.charAt(this.index); + } while (prev !== '*' || next !== '/'); + ++this.index; + repeat = true; + } else + return '/'; + } + } 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) + while(end < this.source.length && !Lang.DELIM.test(this.source.charAt(end))) + ++end; + var token = this.source.substring(this.index, this.index = end); + if (token === '"' || token === "'") + this._stringOpen = token; + return token; + }; + + /** + * Peeks for the next token. + * @return {?string} Token or `null` on EOF + * @expose + */ + TokenizerPrototype.peek = function() { + if (this.stack.length === 0) { + var token = this.next(); + if (token === null) + return null; + this.stack.push(token); + } + return this.stack[0]; + }; + + /** + * Skips a specific token and throws if it differs. + * @param {string} expected Expected token + * @throws {Error} If the actual token differs + */ + TokenizerPrototype.skip = function(expected) { + var actual = this.next(); + if (actual !== expected) + throw Error("illegal '"+actual+"', '"+expected+"' expected"); + }; + + /** + * Omits an optional token. + * @param {string} expected Expected optional token + * @returns {boolean} `true` if the token exists + */ + TokenizerPrototype.omit = function(expected) { + if (this.peek() === expected) { + this.next(); + return true; + } + return false; + }; + + /** + * Returns a string representation of this object. + * @return {string} String representation as of "Tokenizer(index/length)" + * @expose + */ + TokenizerPrototype.toString = function() { + return "Tokenizer ("+this.index+"/"+this.source.length+" at line "+this.line+")"; + }; + + /** + * @alias ProtoBuf.DotProto.Tokenizer + * @expose + */ + DotProto.Tokenizer = Tokenizer; + + /** + * Constructs a new Parser. + * @exports ProtoBuf.DotProto.Parser + * @class prototype parser + * @param {string} source Source + * @constructor + */ + var Parser = function(source) { + + /** + * Tokenizer. + * @type {!ProtoBuf.DotProto.Tokenizer} + * @expose + */ + this.tn = new Tokenizer(source); + + /** + * Whether parsing proto3 or not. + * @type {boolean} + */ + this.proto3 = false; + }; + + /** + * @alias ProtoBuf.DotProto.Parser.prototype + * @inner + */ + var ParserPrototype = Parser.prototype; + + /** + * Parses the source. + * @returns {!Object} + * @throws {Error} If the source cannot be parsed + * @expose + */ + ParserPrototype.parse = function() { + var topLevel = { + "name": "[ROOT]", // temporary + "package": null, + "messages": [], + "enums": [], + "imports": [], + "options": {}, + "services": [] + // "syntax": undefined + }; + var token, + head = true; + try { + while (token = this.tn.next()) { + switch (token) { + case 'package': + if (!head || topLevel["package"] !== null) + throw Error("unexpected 'package'"); + token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) + throw Error("illegal package name: " + token); + this.tn.skip(";"); + topLevel["package"] = token; + break; + case 'import': + if (!head) + throw Error("unexpected 'import'"); + token = this.tn.peek(); + if (token === "public") // ignored + this.tn.next(); + token = this._readString(); + this.tn.skip(";"); + topLevel["imports"].push(token); + break; + case 'syntax': + if (!head) + throw Error("unexpected 'syntax'"); + this.tn.skip("="); + if ((topLevel["syntax"] = this._readString()) === "proto3") + this.proto3 = true; + this.tn.skip(";"); + break; + case 'message': + this._parseMessage(topLevel, null); + head = false; + break; + case 'enum': + this._parseEnum(topLevel); + head = false; + break; + case 'option': + this._parseOption(topLevel); + break; + case 'service': + this._parseService(topLevel); + break; + case 'extend': + this._parseExtend(topLevel); + break; + default: + throw Error("unexpected '" + token + "'"); + } + } + } catch (e) { + e.message = "Parse error at line "+this.tn.line+": " + e.message; + throw e; + } + delete topLevel["name"]; + return topLevel; + }; + + /** + * Parses the specified source. + * @returns {!Object} + * @throws {Error} If the source cannot be parsed + * @expose + */ + Parser.parse = function(source) { + return new Parser(source).parse(); + }; + + // ----- Conversion ------ + + /** + * Converts a numerical string to an id. + * @param {string} value + * @param {boolean=} mayBeNegative + * @returns {number} + * @inner + */ + function mkId(value, mayBeNegative) { + var id = -1, + sign = 1; + if (value.charAt(0) == '-') { + sign = -1; + value = value.substring(1); + } + if (Lang.NUMBER_DEC.test(value)) + id = parseInt(value); + else if (Lang.NUMBER_HEX.test(value)) + id = parseInt(value.substring(2), 16); + else if (Lang.NUMBER_OCT.test(value)) + id = parseInt(value.substring(1), 8); + else + throw Error("illegal id value: " + (sign < 0 ? '-' : '') + value); + id = (sign*id)|0; // Force to 32bit + if (!mayBeNegative && id < 0) + throw Error("illegal id value: " + (sign < 0 ? '-' : '') + value); + return id; + } + + /** + * Converts a numerical string to a number. + * @param {string} val + * @returns {number} + * @inner + */ + function mkNumber(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 (val === 'inf') + return sign * Infinity; + else if (val === 'nan') + return NaN; + else if (Lang.NUMBER_FLT.test(val)) + return sign * parseFloat(val); + throw Error("illegal number value: " + (sign < 0 ? '-' : '') + val); + } + + // ----- Reading ------ + + /** + * Reads a string. + * @returns {string} + * @private + */ + ParserPrototype._readString = function() { + var value = "", + token, + delim; + do { + delim = this.tn.next(); + if (delim !== "'" && delim !== '"') + throw Error("illegal string delimiter: "+delim); + value += this.tn.next(); + this.tn.skip(delim); + token = this.tn.peek(); + } while (token === '"' || token === '"'); // multi line? + return value; + }; + + /** + * Reads a value. + * @param {boolean=} mayBeTypeRef + * @returns {number|boolean|string} + * @private + */ + ParserPrototype._readValue = function(mayBeTypeRef) { + var token = this.tn.peek(), + value; + if (token === '"' || token === "'") + return this._readString(); + this.tn.next(); + if (Lang.NUMBER.test(token)) + return mkNumber(token); + if (Lang.BOOL.test(token)) + return (token.toLowerCase() === 'true'); + if (mayBeTypeRef && Lang.TYPEREF.test(token)) + return token; + throw Error("illegal value: "+token); + + }; + + // ----- Parsing constructs ----- + + /** + * Parses a namespace option. + * @param {!Object} parent Parent definition + * @param {boolean=} isList + * @private + */ + ParserPrototype._parseOption = function(parent, isList) { + var token = this.tn.next(), + custom = false; + if (token === '(') { + custom = true; + token = this.tn.next(); + } + if (!Lang.TYPEREF.test(token)) + // we can allow options of the form google.protobuf.* since they will just get ignored anyways + // if (!/google\.protobuf\./.test(token)) // FIXME: Why should that not be a valid typeref? + throw Error("illegal option name: "+token); + var name = token; + if (custom) { // (my_method_option).foo, (my_method_option), some_method_option, (foo.my_option).bar + this.tn.skip(')'); + name = '('+name+')'; + token = this.tn.peek(); + if (Lang.FQTYPEREF.test(token)) { + name += token; + this.tn.next(); + } + } + this.tn.skip('='); + this._parseOptionValue(parent, name); + if (!isList) + this.tn.skip(";"); + }; + + /** + * Sets an option on the specified options object. + * @param {!Object.} options + * @param {string} name + * @param {string|number|boolean} value + * @inner + */ + function setOption(options, name, value) { + if (typeof options[name] === 'undefined') + options[name] = value; + else { + if (!Array.isArray(options[name])) + options[name] = [ options[name] ]; + options[name].push(value); + } + } + + /** + * Parses an option value. + * @param {!Object} parent + * @param {string} name + * @private + */ + ParserPrototype._parseOptionValue = function(parent, name) { + var token = this.tn.peek(); + if (token !== '{') { // Plain value + setOption(parent["options"], name, this._readValue(true)); + } else { // Aggregate options + this.tn.skip("{"); + while ((token = this.tn.next()) !== '}') { + if (!Lang.NAME.test(token)) + throw Error("illegal option name: " + name + "." + token); + if (this.tn.omit(":")) + setOption(parent["options"], name + "." + token, this._readValue(true)); + else + this._parseOptionValue(parent, name + "." + token); + } + } + }; + + /** + * Parses a service definition. + * @param {!Object} parent Parent definition + * @private + */ + ParserPrototype._parseService = function(parent) { + var token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal service name at line "+this.tn.line+": "+token); + var name = token; + var svc = { + "name": name, + "rpc": {}, + "options": {} + }; + this.tn.skip("{"); + while ((token = this.tn.next()) !== '}') { + if (token === "option") + this._parseOption(svc); + else if (token === 'rpc') + this._parseServiceRPC(svc); + else + throw Error("illegal service token: "+token); + } + this.tn.omit(";"); + parent["services"].push(svc); + }; + + /** + * Parses a RPC service definition of the form ['rpc', name, (request), 'returns', (response)]. + * @param {!Object} svc Service definition + * @private + */ + ParserPrototype._parseServiceRPC = function(svc) { + var type = "rpc", + token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal rpc service method name: "+token); + var name = token; + var method = { + "request": null, + "response": null, + "request_stream": false, + "response_stream": false, + "options": {} + }; + this.tn.skip("("); + token = this.tn.next(); + if (token.toLowerCase() === "stream") { + method["request_stream"] = true; + token = this.tn.next(); + } + if (!Lang.TYPEREF.test(token)) + throw Error("illegal rpc service request type: "+token); + method["request"] = token; + this.tn.skip(")"); + token = this.tn.next(); + if (token.toLowerCase() !== "returns") + throw Error("illegal rpc service request type delimiter: "+token); + this.tn.skip("("); + token = this.tn.next(); + if (token.toLowerCase() === "stream") { + method["response_stream"] = true; + token = this.tn.next(); + } + method["response"] = token; + this.tn.skip(")"); + token = this.tn.peek(); + if (token === '{') { + this.tn.next(); + while ((token = this.tn.next()) !== '}') { + if (token === 'option') + this._parseOption(method); + else + throw Error("illegal rpc service token: " + token); + } + this.tn.omit(";"); + } else + this.tn.skip(";"); + if (typeof svc[type] === 'undefined') + svc[type] = {}; + svc[type][name] = method; + }; + + /** + * Parses a message definition. + * @param {!Object} parent Parent definition + * @param {!Object=} fld Field definition if this is a group + * @returns {!Object} + * @private + */ + ParserPrototype._parseMessage = function(parent, fld) { + var isGroup = !!fld, + token = this.tn.next(); + var msg = { + "name": "", + "fields": [], + "enums": [], + "messages": [], + "options": {}, + "services": [], + "oneofs": {} + // "extensions": undefined + }; + if (!Lang.NAME.test(token)) + throw Error("illegal "+(isGroup ? "group" : "message")+" name: "+token); + msg["name"] = token; + if (isGroup) { + this.tn.skip("="); + fld["id"] = mkId(this.tn.next()); + msg["isGroup"] = true; + } + token = this.tn.peek(); + if (token === '[' && fld) + this._parseFieldOptions(fld); + this.tn.skip("{"); + while ((token = this.tn.next()) !== '}') { + if (Lang.RULE.test(token)) + this._parseMessageField(msg, token); + else if (token === "oneof") + this._parseMessageOneOf(msg); + else if (token === "enum") + this._parseEnum(msg); + else if (token === "message") + this._parseMessage(msg); + else if (token === "option") + this._parseOption(msg); + else if (token === "service") + this._parseService(msg); + else if (token === "extensions") + this._parseExtensions(msg); + else if (token === "extend") + this._parseExtend(msg); + else if (token === "reserved") + this._parseMessageReserved(msg); + else if (Lang.TYPEREF.test(token)) { + if (!this.proto3) + throw Error("illegal field rule: "+token); + this._parseMessageField(msg, "optional", token); + } else + throw Error("illegal message token: "+token); + } + this.tn.omit(";"); + parent["messages"].push(msg); + return msg; + }; + + /** + * Parses a message's reserved ids / names statement. + * @param {!Object} msg Message definition + * @private + */ + ParserPrototype._parseMessageReserved = function(msg) { + // TODO: This currently just skips a reserved statement for compatibility. + // Valid formats are + // reserved 2, 15, 9 to 11; + // for reserved ids or + // reserved "foo", "bar"; + // for reserved names. + while (this.tn.peek() !== ';') + this.tn.next(); + this.tn.skip(";"); + }; + + /** + * Parses a message field. + * @param {!Object} msg Message definition + * @param {string} rule Field rule + * @param {string=} type Field type if already known (never known for maps) + * @returns {!Object} Field descriptor + * @private + */ + ParserPrototype._parseMessageField = function(msg, rule, type) { + if (!Lang.RULE.test(rule)) + throw Error("illegal message field rule: "+rule); + var fld = { + "rule": rule, + "type": "", + "name": "", + "options": {}, + "id": 0 + }; + var token; + if (rule === "map") { + + if (type) + throw Error("illegal type: " + type); + this.tn.skip('<'); + token = this.tn.next(); + if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token)) + throw Error("illegal message field type: " + token); + fld["keytype"] = token; + this.tn.skip(','); + token = this.tn.next(); + if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token)) + throw Error("illegal message field: " + token); + fld["type"] = token; + this.tn.skip('>'); + token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal message field name: " + token); + fld["name"] = token; + this.tn.skip("="); + fld["id"] = mkId(this.tn.next()); + token = this.tn.peek(); + if (token === '[') + this._parseFieldOptions(fld); + this.tn.skip(";"); + + } else { + + type = typeof type !== 'undefined' ? type : this.tn.next(); + + if (type === "group") { + + // "A [legacy] group simply combines a nested message type and a field into a single declaration. In your + // code, you can treat this message just as if it had a Result type field called result (the latter name is + // converted to lower-case so that it does not conflict with the former)." + var grp = this._parseMessage(msg, fld); + if (!/^[A-Z]/.test(grp["name"])) + throw Error('illegal group name: '+grp["name"]); + fld["type"] = grp["name"]; + fld["name"] = grp["name"].toLowerCase(); + this.tn.omit(";"); + + } else { + + if (!Lang.TYPE.test(type) && !Lang.TYPEREF.test(type)) + throw Error("illegal message field type: " + type); + fld["type"] = type; + token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal message field name: " + token); + fld["name"] = token; + this.tn.skip("="); + fld["id"] = mkId(this.tn.next()); + token = this.tn.peek(); + if (token === "[") + this._parseFieldOptions(fld); + this.tn.skip(";"); + + } + } + msg["fields"].push(fld); + return fld; + }; + + /** + * Parses a message oneof. + * @param {!Object} msg Message definition + * @private + */ + ParserPrototype._parseMessageOneOf = function(msg) { + var token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal oneof name: "+token); + var name = token, + fld; + var fields = []; + this.tn.skip("{"); + while ((token = this.tn.next()) !== "}") { + fld = this._parseMessageField(msg, "optional", token); + fld["oneof"] = name; + fields.push(fld["id"]); + } + this.tn.omit(";"); + msg["oneofs"][name] = fields; + }; + + /** + * Parses a set of field option definitions. + * @param {!Object} fld Field definition + * @private + */ + ParserPrototype._parseFieldOptions = function(fld) { + this.tn.skip("["); + var token, + first = true; + while ((token = this.tn.peek()) !== ']') { + if (!first) + this.tn.skip(","); + this._parseOption(fld, true); + first = false; + } + this.tn.next(); + }; + + /** + * Parses an enum. + * @param {!Object} msg Message definition + * @private + */ + ParserPrototype._parseEnum = function(msg) { + var enm = { + "name": "", + "values": [], + "options": {} + }; + var token = this.tn.next(); + if (!Lang.NAME.test(token)) + throw Error("illegal name: "+token); + enm["name"] = token; + this.tn.skip("{"); + while ((token = this.tn.next()) !== '}') { + if (token === "option") + this._parseOption(enm); + else { + if (!Lang.NAME.test(token)) + throw Error("illegal name: "+token); + this.tn.skip("="); + var val = { + "name": token, + "id": mkId(this.tn.next(), true) + }; + token = this.tn.peek(); + if (token === "[") + this._parseFieldOptions({ "options": {} }); + this.tn.skip(";"); + enm["values"].push(val); + } + } + this.tn.omit(";"); + msg["enums"].push(enm); + }; + + /** + * Parses an extensions statement. + * @param {!Object} msg Message object + * @private + */ + ParserPrototype._parseExtensions = function(msg) { + var token = this.tn.next(), + range = []; + if (token === "min") + range.push(ProtoBuf.ID_MIN); + else if (token === "max") + range.push(ProtoBuf.ID_MAX); + else + range.push(mkNumber(token)); + this.tn.skip("to"); + token = this.tn.next(); + if (token === "min") + range.push(ProtoBuf.ID_MIN); + else if (token === "max") + range.push(ProtoBuf.ID_MAX); + else + range.push(mkNumber(token)); + this.tn.skip(";"); + msg["extensions"] = range; + }; + + /** + * Parses an extend block. + * @param {!Object} parent Parent object + * @private + */ + ParserPrototype._parseExtend = function(parent) { + var token = this.tn.next(); + if (!Lang.TYPEREF.test(token)) + throw Error("illegal extend reference: "+token); + var ext = { + "ref": token, + "fields": [] + }; + this.tn.skip("{"); + while ((token = this.tn.next()) !== '}') { + if (Lang.RULE.test(token)) + this._parseMessageField(ext, token); + else if (Lang.TYPEREF.test(token)) { + if (!this.proto3) + throw Error("illegal field rule: "+token); + this._parseMessageField(ext, "optional", token); + } else + throw Error("illegal extend token: "+token); + } + this.tn.omit(";"); + parent["messages"].push(ext); + return ext; + }; + + // ----- General ----- + + /** + * Returns a string representation of this parser. + * @returns {string} + */ + ParserPrototype.toString = function() { + return "Parser at line "+this.tn.line; + }; + + /** + * @alias ProtoBuf.DotProto.Parser + * @expose + */ + DotProto.Parser = Parser; + + return DotProto; + + })(ProtoBuf, ProtoBuf.Lang); + + /** + * @alias ProtoBuf.Reflect + * @expose + */ + ProtoBuf.Reflect = (function(ProtoBuf) { + "use strict"; + + /** + * Reflection types. + * @exports ProtoBuf.Reflect + * @namespace + */ + var Reflect = {}; + + /** + * Constructs a Reflect base class. + * @exports ProtoBuf.Reflect.T + * @constructor + * @abstract + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {?ProtoBuf.Reflect.T} parent Parent object + * @param {string} name Object name + */ + var T = function(builder, parent, name) { + + /** + * Builder reference. + * @type {!ProtoBuf.Builder} + * @expose + */ + this.builder = builder; + + /** + * Parent object. + * @type {?ProtoBuf.Reflect.T} + * @expose + */ + this.parent = parent; + + /** + * Object name in namespace. + * @type {string} + * @expose + */ + this.name = name; + + /** + * Fully qualified class name + * @type {string} + * @expose + */ + this.className; + }; + + /** + * @alias ProtoBuf.Reflect.T.prototype + * @inner + */ + var TPrototype = T.prototype; + + /** + * Returns the fully qualified name of this object. + * @returns {string} Fully qualified name as of ".PATH.TO.THIS" + * @expose + */ + TPrototype.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 + */ + TPrototype.toString = function(includeClass) { + return (includeClass ? this.className + " " : "") + this.fqn(); + }; + + /** + * Builds this type. + * @throws {Error} If this type cannot be built directly + * @expose + */ + TPrototype.build = function() { + throw 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.Builder} builder Builder reference + * @param {?ProtoBuf.Reflect.Namespace} parent Namespace parent + * @param {string} name Namespace name + * @param {Object.=} options Namespace options + * @param {string?} syntax The syntax level of this definition (e.g., proto3) + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Namespace = function(builder, parent, name, options, syntax) { + T.call(this, builder, parent, name); + + /** + * @override + */ + this.className = "Namespace"; + + /** + * Children inside the namespace. + * @type {!Array.} + */ + this.children = []; + + /** + * Options. + * @type {!Object.} + */ + this.options = options || {}; + + /** + * Syntax level (e.g., proto2 or proto3). + * @type {!string} + */ + this.syntax = syntax || "proto2"; + }; + + /** + * @alias ProtoBuf.Reflect.Namespace.prototype + * @inner + */ + var NamespacePrototype = 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 + */ + NamespacePrototype.getChildren = function(type) { + type = type || null; + if (type == null) + return this.children.slice(); + var children = []; + for (var i=0, k=this.children.length; i} qn Qualified name to resolve + * @param {boolean=} excludeNonNamespace Excludes non-namespace types, defaults to `false` + * @return {?ProtoBuf.Reflect.Namespace} The resolved type or null if not found + * @expose + */ + NamespacePrototype.resolve = function(qn, excludeNonNamespace) { + var part = typeof qn === 'string' ? qn.split(".") : qn, + ptr = this, + i = 0; + if (part[i] === "") { // Fully qualified name, e.g. ".My.Message' + while (ptr.parent !== null) + ptr = ptr.parent; + i++; + } + var child; + do { + do { + if (!(ptr instanceof Reflect.Namespace)) { + ptr = null; + break; + } + child = ptr.getChild(part[i]); + if (!child || !(child instanceof Reflect.T) || (excludeNonNamespace && !(child instanceof Reflect.Namespace))) { + ptr = null; + break; + } + ptr = child; i++; + } while (i < part.length); + if (ptr != null) + break; // Found + // Else search the parent + if (this.parent !== null) + return this.parent.resolve(qn, excludeNonNamespace); + } while (ptr != null); + return ptr; + }; + + /** + * Determines the shortest qualified name of the specified type, if any, relative to this namespace. + * @param {!ProtoBuf.Reflect.T} t Reflection type + * @returns {string} The shortest qualified name or, if there is none, the fqn + * @expose + */ + NamespacePrototype.qn = function(t) { + var part = [], ptr = t; + do { + part.unshift(ptr.name); + ptr = ptr.parent; + } while (ptr !== null); + for (var len=1; len <= part.length; len++) { + var qn = part.slice(part.length-len); + if (t === this.resolve(qn, t instanceof Reflect.Namespace)) + return qn.join("."); + } + return t.fqn(); + }; + + /** + * Builds the namespace and returns the runtime counterpart. + * @return {Object.} Runtime namespace + * @expose + */ + NamespacePrototype.build = function() { + /** @dict */ + var ns = {}; + var children = this.children; + for (var i=0, k=children.length, child; i} + */ + NamespacePrototype.buildOpt = function() { + var opt = {}, + keys = Object.keys(this.options); + for (var i=0, k=keys.length; i}null} Option value or NULL if there is no such option + */ + NamespacePrototype.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 Element implementation that checks and converts values for a + * particular field type, as appropriate. + * + * An Element represents a single value: either the value of a singular field, + * or a value contained in one entry of a repeated field or map field. This + * class does not implement these higher-level concepts; it only encapsulates + * the low-level typechecking and conversion. + * + * @exports ProtoBuf.Reflect.Element + * @param {{name: string, wireType: number}} type Resolved data type + * @param {ProtoBuf.Reflect.T|null} resolvedType Resolved type, if relevant + * (e.g. submessage field). + * @param {boolean} isMapKey Is this element a Map key? The value will be + * converted to string form if so. + * @param {string} syntax Syntax level of defining message type, e.g., + * proto2 or proto3. + * @constructor + */ + var Element = function(type, resolvedType, isMapKey, syntax) { + + /** + * Element type, as a string (e.g., int32). + * @type {{name: string, wireType: number}} + */ + this.type = type; + + /** + * Element type reference to submessage or enum definition, if needed. + * @type {ProtoBuf.Reflect.T|null} + */ + this.resolvedType = resolvedType; + + /** + * Element is a map key. + * @type {boolean} + */ + this.isMapKey = isMapKey; + + /** + * Syntax level of defining message type, e.g., proto2 or proto3. + * @type {string} + */ + this.syntax = syntax; + + if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0) + throw Error("Invalid map key type: " + type.name); + }; + + var ElementPrototype = Element.prototype; + + /** + * Obtains a (new) default value for the specified type. + * @param type {string|{name: string, wireType: number}} Field type + * @returns {*} Default value + * @inner + */ + function mkDefault(type) { + if (typeof type === 'string') + type = ProtoBuf.TYPES[type]; + if (typeof type.defaultValue === 'undefined') + throw Error("default value for type "+type.name+" is not supported"); + if (type == ProtoBuf.TYPES["bytes"]) + return new ByteBuffer(0); + return type.defaultValue; + } + + /** + * Returns the default value for this field in proto3. + * @function + * @param type {string|{name: string, wireType: number}} the field type + * @returns {*} Default value + */ + Element.defaultFieldValue = mkDefault; + + /** + * Makes a Long from a value. + * @param {{low: number, high: number, unsigned: boolean}|string|number} value Value + * @param {boolean=} unsigned Whether unsigned or not, defaults to reuse it from Long-like objects or to signed for + * strings and numbers + * @returns {!Long} + * @throws {Error} If the value cannot be converted to a Long + * @inner + */ + function mkLong(value, unsigned) { + if (value && typeof value.low === 'number' && typeof value.high === 'number' && typeof value.unsigned === 'boolean' + && value.low === value.low && value.high === value.high) + return new ProtoBuf.Long(value.low, value.high, typeof unsigned === 'undefined' ? value.unsigned : unsigned); + if (typeof value === 'string') + return ProtoBuf.Long.fromString(value, unsigned || false, 10); + if (typeof value === 'number') + return ProtoBuf.Long.fromNumber(value, unsigned || false); + throw Error("not convertible to Long"); + } + + /** + * Checks if the given value can be set for an element of this type (singular + * field or one element of a repeated field or map). + * @param {*} value Value to check + * @return {*} Verified, maybe adjusted, value + * @throws {Error} If the value cannot be verified for this element slot + * @expose + */ + ElementPrototype.verifyValue = function(value) { + var fail = function(val, msg) { + throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")"); + }.bind(this); + switch (this.type) { + // Signed 32bit + case ProtoBuf.TYPES["int32"]: + case ProtoBuf.TYPES["sint32"]: + case ProtoBuf.TYPES["sfixed32"]: + // Account for !NaN: value === value + if (typeof value !== 'number' || (value === value && value % 1 !== 0)) + fail(typeof value, "not an integer"); + return value > 4294967295 ? value | 0 : value; + + // Unsigned 32bit + case ProtoBuf.TYPES["uint32"]: + case ProtoBuf.TYPES["fixed32"]: + if (typeof value !== 'number' || (value === value && value % 1 !== 0)) + fail(typeof value, "not an integer"); + return value < 0 ? value >>> 0 : value; + + // Signed 64bit + case ProtoBuf.TYPES["int64"]: + case ProtoBuf.TYPES["sint64"]: + case ProtoBuf.TYPES["sfixed64"]: { + if (ProtoBuf.Long) + try { + return mkLong(value, false); + } catch (e) { + fail(typeof value, e.message); + } + else + fail(typeof value, "requires Long.js"); + } + + // Unsigned 64bit + case ProtoBuf.TYPES["uint64"]: + case ProtoBuf.TYPES["fixed64"]: { + if (ProtoBuf.Long) + try { + return mkLong(value, true); + } catch (e) { + fail(typeof value, e.message); + } + else + fail(typeof value, "requires Long.js"); + } + + // Bool + case ProtoBuf.TYPES["bool"]: + if (typeof value !== 'boolean') + fail(typeof value, "not a boolean"); + return value; + + // Float + case ProtoBuf.TYPES["float"]: + case ProtoBuf.TYPES["double"]: + if (typeof value !== 'number') + fail(typeof value, "not a number"); + return value; + + // Length-delimited string + case ProtoBuf.TYPES["string"]: + if (typeof value !== 'string' && !(value && value instanceof String)) + fail(typeof value, "not a string"); + return ""+value; // Convert String object to string + + // Length-delimited bytes + case ProtoBuf.TYPES["bytes"]: + if (ByteBuffer.isByteBuffer(value)) + return value; + return ByteBuffer.wrap(value, "base64"); + + // Constant enum value + case ProtoBuf.TYPES["enum"]: { + var values = this.resolvedType.getChildren(ProtoBuf.Reflect.Enum.Value); + for (i=0; i 4294967295 || value < 0) + fail(typeof value, "not in range for uint32") + return value; + } else { + // proto2 requires enum values to be valid. + fail(value, "not a valid enum value"); + } + } + // Embedded message + case ProtoBuf.TYPES["group"]: + case ProtoBuf.TYPES["message"]: { + if (!value || typeof value !== 'object') + fail(typeof value, "object expected"); + if (value instanceof this.resolvedType.clazz) + return value; + if (value instanceof ProtoBuf.Builder.Message) { + // Mismatched type: Convert to object (see: https://github.com/dcodeIO/ProtoBuf.js/issues/180) + var obj = {}; + for (var i in value) + if (value.hasOwnProperty(i)) + obj[i] = value[i]; + value = obj; + } + // Else let's try to construct one from a key-value object + return new (this.resolvedType.clazz)(value); // May throw for a hundred of reasons + } + } + + // We should never end here + throw Error("[INTERNAL] Illegal value for "+this.toString(true)+": "+value+" (undefined type "+this.type+")"); + }; + + /** + * Calculates the byte length of an element on the wire. + * @param {number} id Field number + * @param {*} value Field value + * @returns {number} Byte length + * @throws {Error} If the value cannot be calculated + * @expose + */ + ElementPrototype.calculateLength = function(id, value) { + if (value === null) return 0; // Nothing to encode + // Tag has already been written + var n; + switch (this.type) { + case ProtoBuf.TYPES["int32"]: + return value < 0 ? ByteBuffer.calculateVarint64(value) : ByteBuffer.calculateVarint32(value); + case ProtoBuf.TYPES["uint32"]: + return ByteBuffer.calculateVarint32(value); + case ProtoBuf.TYPES["sint32"]: + return ByteBuffer.calculateVarint32(ByteBuffer.zigZagEncode32(value)); + case ProtoBuf.TYPES["fixed32"]: + case ProtoBuf.TYPES["sfixed32"]: + case ProtoBuf.TYPES["float"]: + return 4; + case ProtoBuf.TYPES["int64"]: + case ProtoBuf.TYPES["uint64"]: + return ByteBuffer.calculateVarint64(value); + case ProtoBuf.TYPES["sint64"]: + return ByteBuffer.calculateVarint64(ByteBuffer.zigZagEncode64(value)); + case ProtoBuf.TYPES["fixed64"]: + case ProtoBuf.TYPES["sfixed64"]: + return 8; + case ProtoBuf.TYPES["bool"]: + return 1; + case ProtoBuf.TYPES["enum"]: + return ByteBuffer.calculateVarint32(value); + case ProtoBuf.TYPES["double"]: + return 8; + case ProtoBuf.TYPES["string"]: + n = ByteBuffer.calculateUTF8Bytes(value); + return ByteBuffer.calculateVarint32(n) + n; + case ProtoBuf.TYPES["bytes"]: + if (value.remaining() < 0) + throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining"); + return ByteBuffer.calculateVarint32(value.remaining()) + value.remaining(); + case ProtoBuf.TYPES["message"]: + n = this.resolvedType.calculate(value); + return ByteBuffer.calculateVarint32(n) + n; + case ProtoBuf.TYPES["group"]: + n = this.resolvedType.calculate(value); + return n + ByteBuffer.calculateVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP); + } + // We should never end here + throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)"); + }; + + /** + * Encodes a value to the specified buffer. Does not encode the key. + * @param {number} id Field number + * @param {*} value Field value + * @param {ByteBuffer} buffer ByteBuffer to encode to + * @return {ByteBuffer} The ByteBuffer for chaining + * @throws {Error} If the value cannot be encoded + * @expose + */ + ElementPrototype.encodeValue = function(id, value, buffer) { + if (value === null) return buffer; // Nothing to encode + // Tag has already been written + + switch (this.type) { + // 32bit signed varint + case ProtoBuf.TYPES["int32"]: + // "If you use int32 or int64 as the type for a negative number, the resulting varint is always ten bytes + // long – it is, effectively, treated like a very large unsigned integer." (see #122) + if (value < 0) + buffer.writeVarint64(value); + else + buffer.writeVarint32(value); + break; + + // 32bit unsigned varint + case ProtoBuf.TYPES["uint32"]: + buffer.writeVarint32(value); + break; + + // 32bit varint zig-zag + case ProtoBuf.TYPES["sint32"]: + buffer.writeVarint32ZigZag(value); + break; + + // Fixed unsigned 32bit + case ProtoBuf.TYPES["fixed32"]: + buffer.writeUint32(value); + break; + + // Fixed signed 32bit + case ProtoBuf.TYPES["sfixed32"]: + buffer.writeInt32(value); + break; + + // 64bit varint as-is + case ProtoBuf.TYPES["int64"]: + case ProtoBuf.TYPES["uint64"]: + buffer.writeVarint64(value); // throws + break; + + // 64bit varint zig-zag + case ProtoBuf.TYPES["sint64"]: + buffer.writeVarint64ZigZag(value); // throws + break; + + // Fixed unsigned 64bit + case ProtoBuf.TYPES["fixed64"]: + buffer.writeUint64(value); // throws + break; + + // Fixed signed 64bit + case ProtoBuf.TYPES["sfixed64"]: + buffer.writeInt64(value); // throws + break; + + // Bool + case ProtoBuf.TYPES["bool"]: + if (typeof value === 'string') + buffer.writeVarint32(value.toLowerCase() === 'false' ? 0 : !!value); + else + buffer.writeVarint32(value ? 1 : 0); + break; + + // Constant enum value + case ProtoBuf.TYPES["enum"]: + buffer.writeVarint32(value); + break; + + // 32bit float + case ProtoBuf.TYPES["float"]: + buffer.writeFloat32(value); + break; + + // 64bit float + case ProtoBuf.TYPES["double"]: + buffer.writeFloat64(value); + break; + + // Length-delimited string + case ProtoBuf.TYPES["string"]: + buffer.writeVString(value); + break; + + // Length-delimited bytes + case ProtoBuf.TYPES["bytes"]: + if (value.remaining() < 0) + throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining"); + var prevOffset = value.offset; + buffer.writeVarint32(value.remaining()); + buffer.append(value); + value.offset = prevOffset; + break; + + // Embedded message + case ProtoBuf.TYPES["message"]: + var bb = new ByteBuffer().LE(); + this.resolvedType.encode(value, bb); + buffer.writeVarint32(bb.offset); + buffer.append(bb.flip()); + break; + + // Legacy group + case ProtoBuf.TYPES["group"]: + this.resolvedType.encode(value, buffer); + buffer.writeVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP); + break; + + default: + // We should never end here + throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)"); + } + return buffer; + }; + + /** + * Decode one element value from the specified buffer. + * @param {ByteBuffer} buffer ByteBuffer to decode from + * @param {number} wireType The field wire type + * @param {number} id The field number + * @return {*} Decoded value + * @throws {Error} If the field cannot be decoded + * @expose + */ + ElementPrototype.decode = function(buffer, wireType, id) { + if (wireType != this.type.wireType) + throw Error("Unexpected wire type for element"); + + var value, nBytes; + switch (this.type) { + // 32bit signed varint + case ProtoBuf.TYPES["int32"]: + return buffer.readVarint32() | 0; + + // 32bit unsigned varint + case ProtoBuf.TYPES["uint32"]: + return buffer.readVarint32() >>> 0; + + // 32bit signed varint zig-zag + case ProtoBuf.TYPES["sint32"]: + return buffer.readVarint32ZigZag() | 0; + + // Fixed 32bit unsigned + case ProtoBuf.TYPES["fixed32"]: + return buffer.readUint32() >>> 0; + + case ProtoBuf.TYPES["sfixed32"]: + return buffer.readInt32() | 0; + + // 64bit signed varint + case ProtoBuf.TYPES["int64"]: + return buffer.readVarint64(); + + // 64bit unsigned varint + case ProtoBuf.TYPES["uint64"]: + return buffer.readVarint64().toUnsigned(); + + // 64bit signed varint zig-zag + case ProtoBuf.TYPES["sint64"]: + return buffer.readVarint64ZigZag(); + + // Fixed 64bit unsigned + case ProtoBuf.TYPES["fixed64"]: + return buffer.readUint64(); + + // Fixed 64bit signed + case ProtoBuf.TYPES["sfixed64"]: + return buffer.readInt64(); + + // Bool varint + case ProtoBuf.TYPES["bool"]: + return !!buffer.readVarint32(); + + // Constant enum value (varint) + case ProtoBuf.TYPES["enum"]: + // The following Builder.Message#set will already throw + return buffer.readVarint32(); + + // 32bit float + case ProtoBuf.TYPES["float"]: + return buffer.readFloat(); + + // 64bit float + case ProtoBuf.TYPES["double"]: + return buffer.readDouble(); + + // Length-delimited string + case ProtoBuf.TYPES["string"]: + return buffer.readVString(); + + // Length-delimited bytes + case ProtoBuf.TYPES["bytes"]: { + nBytes = buffer.readVarint32(); + if (buffer.remaining() < nBytes) + throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining()); + value = buffer.clone(); // Offset already set + value.limit = value.offset+nBytes; + buffer.offset += nBytes; + return value; + } + + // Length-delimited embedded message + case ProtoBuf.TYPES["message"]: { + nBytes = buffer.readVarint32(); + return this.resolvedType.decode(buffer, nBytes); + } + + // Legacy group + case ProtoBuf.TYPES["group"]: + return this.resolvedType.decode(buffer, -1, id); + } + + // We should never end here + throw Error("[INTERNAL] Illegal decode type"); + }; + + /** + * Converts a value from a string to the canonical element type. + * + * Legal only when isMapKey is true. + * + * @param {string} str The string value + * @returns {*} The value + */ + ElementPrototype.valueFromString = function(str) { + if (!this.isMapKey) { + throw Error("valueFromString() called on non-map-key element"); + } + + switch (this.type) { + case ProtoBuf.TYPES["int32"]: + case ProtoBuf.TYPES["sint32"]: + case ProtoBuf.TYPES["sfixed32"]: + case ProtoBuf.TYPES["uint32"]: + case ProtoBuf.TYPES["fixed32"]: + return this.verifyValue(parseInt(str)); + + case ProtoBuf.TYPES["int64"]: + case ProtoBuf.TYPES["sint64"]: + case ProtoBuf.TYPES["sfixed64"]: + case ProtoBuf.TYPES["uint64"]: + case ProtoBuf.TYPES["fixed64"]: + // Long-based fields support conversions from string already. + return this.verifyValue(str); + + case ProtoBuf.TYPES["bool"]: + return str === "true"; + + case ProtoBuf.TYPES["string"]: + return this.verifyValue(str); + + case ProtoBuf.TYPES["bytes"]: + return ByteBuffer.fromBinary(str); + } + }; + + /** + * Converts a value from the canonical element type to a string. + * + * It should be the case that `valueFromString(valueToString(val))` returns + * a value equivalent to `verifyValue(val)` for every legal value of `val` + * according to this element type. + * + * This may be used when the element must be stored or used as a string, + * e.g., as a map key on an Object. + * + * Legal only when isMapKey is true. + * + * @param {*} val The value + * @returns {string} The string form of the value. + */ + ElementPrototype.valueToString = function(value) { + if (!this.isMapKey) { + throw Error("valueToString() called on non-map-key element"); + } + + if (this.type === ProtoBuf.TYPES["bytes"]) { + return value.toString("binary"); + } else { + return value.toString(); + } + }; + + /** + * @alias ProtoBuf.Reflect.Element + * @expose + */ + Reflect.Element = Element; + + /** + * Constructs a new Message. + * @exports ProtoBuf.Reflect.Message + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.Namespace} parent Parent message or namespace + * @param {string} name Message name + * @param {Object.=} options Message options + * @param {boolean=} isGroup `true` if this is a legacy group + * @param {string?} syntax The syntax level of this definition (e.g., proto3) + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Message = function(builder, parent, name, options, isGroup, syntax) { + Namespace.call(this, builder, parent, name, options, syntax); + + /** + * @override + */ + this.className = "Message"; + + /** + * Extensions range. + * @type {!Array.} + * @expose + */ + this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX]; + + /** + * Runtime message class. + * @type {?function(new:ProtoBuf.Builder.Message)} + * @expose + */ + this.clazz = null; + + /** + * Whether this is a legacy group or not. + * @type {boolean} + * @expose + */ + this.isGroup = !!isGroup; + + // The following cached collections are used to efficiently iterate over or look up fields when decoding. + + /** + * Cached fields. + * @type {?Array.} + * @private + */ + this._fields = null; + + /** + * Cached fields by id. + * @type {?Object.} + * @private + */ + this._fieldsById = null; + + /** + * Cached fields by name. + * @type {?Object.} + * @private + */ + this._fieldsByName = null; + }; + + /** + * @alias ProtoBuf.Reflect.Message.prototype + * @inner + */ + var MessagePrototype = 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 + */ + MessagePrototype.build = function(rebuild) { + if (this.clazz && !rebuild) + return this.clazz; + + // Create the runtime Message class in its own scope + var clazz = (function(ProtoBuf, T) { + + var fields = T.getChildren(ProtoBuf.Reflect.Message.Field), + oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf); + + /** + * Constructs a new runtime Message. + * @name ProtoBuf.Builder.Message + * @class Barebone of all runtime messages. + * @param {!Object.|string} values Preset values + * @param {...string} var_args + * @constructor + * @throws {Error} If the message cannot be created + */ + var Message = function(values, var_args) { + ProtoBuf.Builder.Message.call(this); + + // Create virtual oneof properties + for (var i=0, k=oneofs.length; i 0) { + var value; + // Set field values from a values object + if (arguments.length === 1 && values !== null && typeof values === 'object' && + /* not _another_ Message */ (typeof values.encode !== 'function' || values instanceof Message) && + /* not a repeated field */ !Array.isArray(values) && + /* not a Map */ !(values instanceof ProtoBuf.Map) && + /* not a ByteBuffer */ !ByteBuffer.isByteBuffer(values) && + /* not an ArrayBuffer */ !(values instanceof ArrayBuffer) && + /* not a Long */ !(ProtoBuf.Long && values instanceof ProtoBuf.Long)) { + this.$set(values); + } else // Set field values from arguments, in declaration order + for (i=0, k=arguments.length; i} keyOrObj String key or plain object holding multiple values + * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted + * @param {boolean=} noAssert Whether to not assert for an actual field / proper value type, defaults to `false` + * @returns {!ProtoBuf.Builder.Message} this + * @throws {Error} If the value cannot be set + * @expose + */ + MessagePrototype.set = function(keyOrObj, value, noAssert) { + if (keyOrObj && typeof keyOrObj === 'object') { + noAssert = value; + for (var ikey in keyOrObj) + if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined') + this.$set(ikey, value, noAssert); + return this; + } + var field = T._fieldsByName[keyOrObj]; + if (!noAssert) { + if (!field) + throw Error(this+"#"+keyOrObj+" is not a field: undefined"); + if (!(field instanceof ProtoBuf.Reflect.Message.Field)) + throw Error(this+"#"+keyOrObj+" is not a field: "+field.toString(true)); + this[field.name] = (value = field.verifyValue(value)); // May throw + } else + this[keyOrObj] = value; + if (field && field.oneof) { // Field is part of an OneOf (not a virtual OneOf field) + var currentField = this[field.oneof.name]; // Virtual field references currently set field + if (value !== null) { + if (currentField !== null && currentField !== field.name) + this[currentField] = null; // Clear currently set field + this[field.oneof.name] = field.name; // Point virtual field at this field + } else if (/* value === null && */currentField === keyOrObj) + this[field.oneof.name] = null; // Clear virtual field (current field explicitly cleared) + } + return this; + }; + + /** + * Sets a field's value. This is an alias for [@link ProtoBuf.Builder.Message#set}. + * @name ProtoBuf.Builder.Message#$set + * @function + * @param {string|!Object.} keyOrObj String key or plain object holding multiple values + * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted + * @param {boolean=} noAssert Whether to not assert the value, defaults to `false` + * @throws {Error} If the value cannot be set + * @expose + */ + MessagePrototype.$set = MessagePrototype.set; + + /** + * Gets a field's value. + * @name ProtoBuf.Builder.Message#get + * @function + * @param {string} key Key + * @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false` + * @return {*} Value + * @throws {Error} If there is no such field + * @expose + */ + MessagePrototype.get = function(key, noAssert) { + if (noAssert) + return this[key]; + var field = T._fieldsByName[key]; + if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field)) + throw Error(this+"#"+key+" is not a field: undefined"); + if (!(field instanceof ProtoBuf.Reflect.Message.Field)) + throw Error(this+"#"+key+" is not a field: "+field.toString(true)); + return this[field.name]; + }; + + /** + * Gets a field's value. This is an alias for {@link ProtoBuf.Builder.Message#$get}. + * @name ProtoBuf.Builder.Message#$get + * @function + * @param {string} key Key + * @return {*} Value + * @throws {Error} If there is no such field + * @expose + */ + MessagePrototype.$get = MessagePrototype.get; + + // Getters and setters + + for (var i=0; i} data Data payload + * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted. + * @param {boolean=} noVerify Whether to not verify field values, defaults to `false` + * @return {!ByteBuffer} Encoded message as a ByteBuffer + * @expose + */ + Message.encode = function(data, buffer, noVerify) { + return new Message(data).encode(buffer, noVerify); + }; + + /** + * Calculates the byte length of the message. + * @name ProtoBuf.Builder.Message#calculate + * @function + * @returns {number} Byte length + * @throws {Error} If the message cannot be calculated or if required fields are missing. + * @expose + */ + MessagePrototype.calculate = function() { + return T.calculate(this); + }; + + /** + * Encodes the varint32 length-delimited message. + * @name ProtoBuf.Builder.Message#encodeDelimited + * @function + * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted. + * @return {!ByteBuffer} Encoded message as a ByteBuffer + * @throws {Error} 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. + * @expose + */ + MessagePrototype.encodeDelimited = function(buffer) { + var isNew = false; + if (!buffer) + buffer = new ByteBuffer(), + isNew = true; + var enc = new ByteBuffer().LE(); + T.encode(this, enc).flip(); + buffer.writeVarint32(enc.remaining()); + buffer.append(enc); + return isNew ? buffer.flip() : buffer; + }; + + /** + * Directly encodes the message to an ArrayBuffer. + * @name ProtoBuf.Builder.Message#encodeAB + * @function + * @return {ArrayBuffer} Encoded message as ArrayBuffer + * @throws {Error} 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. + * @expose + */ + MessagePrototype.encodeAB = function() { + try { + return this.encode().toArrayBuffer(); + } catch (e) { + if (e["encoded"]) e["encoded"] = e["encoded"].toArrayBuffer(); + throw(e); + } + }; + + /** + * Returns the message as an ArrayBuffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeAB}. + * @name ProtoBuf.Builder.Message#toArrayBuffer + * @function + * @return {ArrayBuffer} Encoded message as ArrayBuffer + * @throws {Error} 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. + * @expose + */ + MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB; + + /** + * Directly encodes the message to a node Buffer. + * @name ProtoBuf.Builder.Message#encodeNB + * @function + * @return {!Buffer} + * @throws {Error} 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. + * @expose + */ + MessagePrototype.encodeNB = function() { + try { + return this.encode().toBuffer(); + } catch (e) { + if (e["encoded"]) e["encoded"] = e["encoded"].toBuffer(); + throw(e); + } + }; + + /** + * Returns the message as a node Buffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeNB}. + * @name ProtoBuf.Builder.Message#toBuffer + * @function + * @return {!Buffer} + * @throws {Error} 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. + * @expose + */ + MessagePrototype.toBuffer = MessagePrototype.encodeNB; + + /** + * Directly encodes the message to a base64 encoded string. + * @name ProtoBuf.Builder.Message#encode64 + * @function + * @return {string} Base64 encoded string + * @throws {Error} 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. + * @expose + */ + MessagePrototype.encode64 = function() { + try { + return this.encode().toBase64(); + } catch (e) { + if (e["encoded"]) e["encoded"] = e["encoded"].toBase64(); + throw(e); + } + }; + + /** + * Returns the message as a base64 encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encode64}. + * @name ProtoBuf.Builder.Message#toBase64 + * @function + * @return {string} Base64 encoded string + * @throws {Error} 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. + * @expose + */ + MessagePrototype.toBase64 = MessagePrototype.encode64; + + /** + * Directly encodes the message to a hex encoded string. + * @name ProtoBuf.Builder.Message#encodeHex + * @function + * @return {string} Hex encoded string + * @throws {Error} 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. + * @expose + */ + MessagePrototype.encodeHex = function() { + try { + return this.encode().toHex(); + } catch (e) { + if (e["encoded"]) e["encoded"] = e["encoded"].toHex(); + throw(e); + } + }; + + /** + * Returns the message as a hex encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encodeHex}. + * @name ProtoBuf.Builder.Message#toHex + * @function + * @return {string} Hex encoded string + * @throws {Error} 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. + * @expose + */ + MessagePrototype.toHex = MessagePrototype.encodeHex; + + /** + * Clones a message object or field value to a raw object. + * @param {*} obj Object to clone + * @param {boolean} binaryAsBase64 Whether to include binary data as base64 strings or as a buffer otherwise + * @param {boolean} longsAsStrings Whether to encode longs as strings + * @param {!ProtoBuf.Reflect.T=} resolvedType The resolved field type if a field + * @returns {*} Cloned object + * @inner + */ + function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) { + if (obj === null || typeof obj !== 'object') { + // Convert enum values to their respective names + if (resolvedType && resolvedType instanceof ProtoBuf.Reflect.Enum) { + var name = ProtoBuf.Reflect.Enum.getName(resolvedType.object, obj); + if (name !== null) + return name; + } + // Pass-through string, number, boolean, null... + return obj; + } + // Convert ByteBuffers to raw buffer or strings + if (ByteBuffer.isByteBuffer(obj)) + return binaryAsBase64 ? obj.toBase64() : obj.toBuffer(); + // Convert Longs to proper objects or strings + if (ProtoBuf.Long.isLong(obj)) + return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj); + var clone; + // Clone arrays + if (Array.isArray(obj)) { + clone = []; + obj.forEach(function(v, k) { + clone[k] = cloneRaw(v, binaryAsBase64, longsAsStrings, resolvedType); + }); + return clone; + } + clone = {}; + // Convert maps to objects + if (obj instanceof ProtoBuf.Map) { + var it = obj.entries(); + for (var e = it.next(); !e.done; e = it.next()) + clone[obj.keyElem.valueToString(e.value[0])] = cloneRaw(e.value[1], binaryAsBase64, longsAsStrings, obj.valueElem.resolvedType); + return clone; + } + // Everything else is a non-null object + var type = obj.$type, + field = undefined; + for (var i in obj) + if (obj.hasOwnProperty(i)) { + if (type && (field = type.getChild(i))) + clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings, field.resolvedType); + else + clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings); + } + return clone; + } + + /** + * Returns the message's raw payload. + * @param {boolean=} binaryAsBase64 Whether to include binary data as base64 strings instead of Buffers, defaults to `false` + * @param {boolean} longsAsStrings Whether to encode longs as strings + * @returns {Object.} Raw payload + * @expose + */ + MessagePrototype.toRaw = function(binaryAsBase64, longsAsStrings) { + return cloneRaw(this, !!binaryAsBase64, !!longsAsStrings, this.$type); + }; + + /** + * Encodes a message to JSON. + * @returns {string} JSON string + * @expose + */ + MessagePrototype.encodeJSON = function() { + return JSON.stringify( + cloneRaw(this, + /* binary-as-base64 */ true, + /* longs-as-strings */ true, + this.$type + ) + ); + }; + + /** + * Decodes a message from the specified buffer or string. + * @name ProtoBuf.Builder.Message.decode + * @function + * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from + * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64 + * @return {!ProtoBuf.Builder.Message} Decoded message + * @throws {Error} 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. + * @expose + * @see ProtoBuf.Builder.Message.decode64 + * @see ProtoBuf.Builder.Message.decodeHex + */ + Message.decode = function(buffer, enc) { + if (typeof buffer === 'string') + buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64"); + buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw + var le = buffer.littleEndian; + try { + var msg = T.decode(buffer.LE()); + buffer.LE(le); + return msg; + } catch (e) { + buffer.LE(le); + throw(e); + } + }; + + /** + * Decodes a varint32 length-delimited message from the specified buffer or string. + * @name ProtoBuf.Builder.Message.decodeDelimited + * @function + * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from + * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64 + * @return {ProtoBuf.Builder.Message} Decoded message or `null` if not enough bytes are available yet + * @throws {Error} 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. + * @expose + */ + Message.decodeDelimited = function(buffer, enc) { + if (typeof buffer === 'string') + buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64"); + buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw + if (buffer.remaining() < 1) + return null; + var off = buffer.offset, + len = buffer.readVarint32(); + if (buffer.remaining() < len) { + buffer.offset = off; + return null; + } + try { + var msg = T.decode(buffer.slice(buffer.offset, buffer.offset + len).LE()); + buffer.offset += len; + return msg; + } catch (err) { + buffer.offset += len; + throw err; + } + }; + + /** + * Decodes the message from the specified base64 encoded string. + * @name ProtoBuf.Builder.Message.decode64 + * @function + * @param {string} str String to decode from + * @return {!ProtoBuf.Builder.Message} Decoded message + * @throws {Error} 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. + * @expose + */ + Message.decode64 = function(str) { + return Message.decode(str, "base64"); + }; + + /** + * Decodes the message from the specified hex encoded string. + * @name ProtoBuf.Builder.Message.decodeHex + * @function + * @param {string} str String to decode from + * @return {!ProtoBuf.Builder.Message} Decoded message + * @throws {Error} 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. + * @expose + */ + Message.decodeHex = function(str) { + return Message.decode(str, "hex"); + }; + + /** + * Decodes the message from a JSON string. + * @name ProtoBuf.Builder.Message.decodeJSON + * @function + * @param {string} str String to decode from + * @return {!ProtoBuf.Builder.Message} Decoded message + * @throws {Error} If the message cannot be decoded or if required fields are + * missing. + * @expose + */ + Message.decodeJSON = function(str) { + return new Message(JSON.parse(str)); + }; + + // Utility + + /** + * Returns a string representation of this Message. + * @name ProtoBuf.Builder.Message#toString + * @function + * @return {string} String representation as of ".Fully.Qualified.MessageName" + * @expose + */ + MessagePrototype.toString = function() { + return T.toString(); + }; + + // Properties + + /** + * Message options. + * @name ProtoBuf.Builder.Message.$options + * @type {Object.} + * @expose + */ + var $optionsS; // cc needs this + + /** + * Message options. + * @name ProtoBuf.Builder.Message#$options + * @type {Object.} + * @expose + */ + var $options; + + /** + * Reflection type. + * @name ProtoBuf.Builder.Message.$type + * @type {!ProtoBuf.Reflect.Message} + * @expose + */ + var $typeS; + + /** + * Reflection type. + * @name ProtoBuf.Builder.Message#$type + * @type {!ProtoBuf.Reflect.Message} + * @expose + */ + var $type; + + if (Object.defineProperty) + Object.defineProperty(Message, '$options', { "value": T.buildOpt() }), + Object.defineProperty(MessagePrototype, "$options", { "value": Message["$options"] }), + Object.defineProperty(Message, "$type", { "value": T }), + Object.defineProperty(MessagePrototype, "$type", { "value": T }); + + return Message; + + })(ProtoBuf, this); + + // Static enums and prototyped sub-messages / cached collections + this._fields = []; + this._fieldsById = {}; + this._fieldsByName = {}; + for (var i=0, k=this.children.length, child; i>> 3; + switch (wireType) { + case ProtoBuf.WIRE_TYPES.VARINT: + do tag = buf.readUint8(); + while ((tag & 0x80) === 0x80); + break; + case ProtoBuf.WIRE_TYPES.BITS64: + buf.offset += 8; + break; + case ProtoBuf.WIRE_TYPES.LDELIM: + tag = buf.readVarint32(); // reads the varint + buf.offset += tag; // skips n bytes + break; + case ProtoBuf.WIRE_TYPES.STARTGROUP: + skipTillGroupEnd(id, buf); + break; + case ProtoBuf.WIRE_TYPES.ENDGROUP: + if (id === expectedId) + return false; + else + throw Error("Illegal GROUPEND after unknown group: "+id+" ("+expectedId+" expected)"); + case ProtoBuf.WIRE_TYPES.BITS32: + buf.offset += 4; + break; + default: + throw Error("Illegal wire type in unknown group "+expectedId+": "+wireType); + } + return true; + } + + /** + * Decodes an encoded message and returns the decoded message. + * @param {ByteBuffer} buffer ByteBuffer to decode from + * @param {number=} length Message length. Defaults to decode all the available data. + * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group + * @return {ProtoBuf.Builder.Message} Decoded message + * @throws {Error} If the message cannot be decoded + * @expose + */ + MessagePrototype.decode = function(buffer, length, expectedGroupEndId) { + length = typeof length === 'number' ? length : -1; + var start = buffer.offset, + msg = new (this.clazz)(), + tag, wireType, id, field; + while (buffer.offset < start+length || (length === -1 && buffer.remaining() > 0)) { + tag = buffer.readVarint32(); + wireType = tag & 0x07; + id = tag >>> 3; + if (wireType === ProtoBuf.WIRE_TYPES.ENDGROUP) { + if (id !== expectedGroupEndId) + throw Error("Illegal group end indicator for "+this.toString(true)+": "+id+" ("+(expectedGroupEndId ? expectedGroupEndId+" expected" : "not a group")+")"); + break; + } + if (!(field = this._fieldsById[id])) { + // "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; + case ProtoBuf.WIRE_TYPES.STARTGROUP: + while (skipTillGroupEnd(id, buffer)) {} + break; + default: + throw Error("Illegal wire type for unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType); + } + continue; + } + if (field.repeated && !field.options["packed"]) { + msg[field.name].push(field.decode(wireType, buffer)); + } else if (field.map) { + var keyval = field.decode(wireType, buffer); + msg[field.name].set(keyval[0], keyval[1]); + } else { + msg[field.name] = field.decode(wireType, buffer); + if (field.oneof) { // Field is part of an OneOf (not a virtual OneOf field) + var currentField = msg[field.oneof.name]; // Virtual field references currently set field + if (currentField !== null && currentField !== field.name) + msg[currentField] = null; // Clear currently set field + msg[field.oneof.name] = field.name; // Point virtual field at this field + } + } + } + + // Check if all required fields are present and set default values for optional fields that are not + for (var i=0, k=this._fields.length; i=} options Options + * @param {!ProtoBuf.Reflect.Message.OneOf=} oneof Enclosing OneOf + * @param {string?} syntax The syntax level of this definition (e.g., proto3) + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Field = function(builder, message, rule, keytype, type, name, id, options, oneof, syntax) { + T.call(this, builder, message, name); + + /** + * @override + */ + this.className = "Message.Field"; + + /** + * Message field required flag. + * @type {boolean} + * @expose + */ + this.required = rule === "required"; + + /** + * Message field repeated flag. + * @type {boolean} + * @expose + */ + this.repeated = rule === "repeated"; + + /** + * Message field map flag. + * @type {boolean} + * @expose + */ + this.map = rule === "map"; + + /** + * Message field key type. Type reference string if unresolved, protobuf + * type if resolved. Valid only if this.map === true, null otherwise. + * @type {string|{name: string, wireType: number}|null} + * @expose + */ + this.keyType = keytype || null; + + /** + * Message field type. Type reference string if unresolved, protobuf type if + * resolved. In a map field, this is the value type. + * @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 || {}; + + /** + * Default value. + * @type {*} + * @expose + */ + this.defaultValue = null; + + /** + * Enclosing OneOf. + * @type {?ProtoBuf.Reflect.Message.OneOf} + * @expose + */ + this.oneof = oneof || null; + + /** + * Syntax level of this definition (e.g., proto3). + * @type {string} + * @expose + */ + this.syntax = syntax || 'proto2'; + + /** + * Original field name. + * @type {string} + * @expose + */ + this.originalName = this.name; // Used to revert camelcase transformation on naming collisions + + /** + * Element implementation. Created in build() after types are resolved. + * @type {ProtoBuf.Element} + * @expose + */ + this.element = null; + + /** + * Key element implementation, for map fields. Created in build() after + * types are resolved. + * @type {ProtoBuf.Element} + * @expose + */ + this.keyElement = null; + + // Convert field names to camel case notation if the override is set + if (this.builder.options['convertFieldsToCamelCase'] && !(this instanceof Message.ExtensionField)) + this.name = ProtoBuf.Util.toCamelCase(this.name); + }; + + /** + * @alias ProtoBuf.Reflect.Message.Field.prototype + * @inner + */ + var FieldPrototype = Field.prototype = Object.create(T.prototype); + + /** + * Builds the field. + * @override + * @expose + */ + FieldPrototype.build = function() { + this.element = new Element(this.type, this.resolvedType, false, this.syntax); + if (this.map) + this.keyElement = new Element(this.keyType, undefined, true, this.syntax); + + // In proto3, fields do not have field presence, and every field is set to + // its type's default value ("", 0, 0.0, or false). + if (this.syntax === 'proto3' && !this.repeated && !this.map) + this.defaultValue = Element.defaultFieldValue(this.type); + + // Otherwise, default values are present when explicitly specified + else if (typeof this.options['default'] !== 'undefined') + this.defaultValue = this.verifyValue(this.options['default']); + }; + + /** + * 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 + */ + FieldPrototype.verifyValue = function(value, skipRepeated) { + skipRepeated = skipRepeated || false; + var fail = function(val, msg) { + throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")"); + }.bind(this); + if (value === null) { // NULL values for optional fields + if (this.required) + fail(typeof value, "required"); + if (this.syntax === 'proto3' && this.type !== ProtoBuf.TYPES["message"]) + fail(typeof value, "proto3 field without field presence cannot be null"); + return null; + } + var i; + if (this.repeated && !skipRepeated) { // Repeated values as arrays + if (!Array.isArray(value)) + value = [value]; + var res = []; + for (i=0; i 0; + + case ProtoBuf.TYPES["bytes"]: + return value.remaining() > 0; + + case ProtoBuf.TYPES["enum"]: + return value !== 0; + + case ProtoBuf.TYPES["message"]: + return value !== null; + default: + return true; + } + }; + + /** + * Encodes the specified field value to the specified buffer. + * @param {*} value Verified field value + * @param {ByteBuffer} buffer ByteBuffer to encode to + * @param {!ProtoBuf.Builder.Message} message Runtime message + * @return {ByteBuffer} The ByteBuffer for chaining + * @throws {Error} If the field cannot be encoded + * @expose + */ + FieldPrototype.encode = function(value, buffer, message) { + if (this.type === null || typeof this.type !== 'object') + throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type); + if (value === null || (this.repeated && value.length == 0)) + return buffer; // Optional omitted + try { + if (this.repeated) { + var i; + // "Only repeated fields of primitive numeric types (types which use the varint, 32-bit, or 64-bit wire + // types) can be declared 'packed'." + if (this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) { + // "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." + buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM); + buffer.ensureCapacity(buffer.offset += 1); // We do not know the length yet, so let's assume a varint of length 1 + var start = buffer.offset; // Remember where the contents begin + 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= 0) { + n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM); + ni = 0; + for (i=0; i= 0) { + 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... + } + + // Handle maps. + if (this.map) { + // Read one (key, value) submessage, and return [key, value] + var key = Element.defaultFieldValue(this.keyType); + value = Element.defaultFieldValue(this.type); + + // Read the length + nBytes = buffer.readVarint32(); + if (buffer.remaining() < nBytes) + throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining()); + + // Get a sub-buffer of this key/value submessage + var msgbuf = buffer.clone(); + msgbuf.limit = msgbuf.offset + nBytes; + buffer.offset += nBytes; + + while (msgbuf.remaining() > 0) { + var tag = msgbuf.readVarint32(); + wireType = tag & 0x07; + var id = tag >>> 3; + if (id === 1) { + key = this.keyElement.decode(msgbuf, wireType, id); + } else if (id === 2) { + value = this.element.decode(msgbuf, wireType, id); + } else { + throw Error("Unexpected tag in map field key/value submessage"); + } + } + + return [key, value]; + } + + // Handle singular and non-packed repeated field values. + return this.element.decode(buffer, wireType, this.id); + }; + + /** + * @alias ProtoBuf.Reflect.Message.Field + * @expose + */ + Reflect.Message.Field = Field; + + /** + * Constructs a new Message ExtensionField. + * @exports ProtoBuf.Reflect.Message.ExtensionField + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.Message} message Message reference + * @param {string} rule Rule, one of requried, optional, repeated + * @param {string} type Data type, e.g. int32 + * @param {string} name Field name + * @param {number} id Unique field id + * @param {!Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Message.Field + */ + var ExtensionField = function(builder, message, rule, type, name, id, options) { + Field.call(this, builder, message, rule, /* keytype = */ null, type, name, id, options); + + /** + * Extension reference. + * @type {!ProtoBuf.Reflect.Extension} + * @expose + */ + this.extension; + }; + + // Extends Field + ExtensionField.prototype = Object.create(Field.prototype); + + /** + * @alias ProtoBuf.Reflect.Message.ExtensionField + * @expose + */ + Reflect.Message.ExtensionField = ExtensionField; + + /** + * Constructs a new Message OneOf. + * @exports ProtoBuf.Reflect.Message.OneOf + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.Message} message Message reference + * @param {string} name OneOf name + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var OneOf = function(builder, message, name) { + T.call(this, builder, message, name); + + /** + * Enclosed fields. + * @type {!Array.} + * @expose + */ + this.fields = []; + }; + + /** + * @alias ProtoBuf.Reflect.Message.OneOf + * @expose + */ + Reflect.Message.OneOf = OneOf; + + /** + * Constructs a new Enum. + * @exports ProtoBuf.Reflect.Enum + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object + * @param {string} name Enum name + * @param {Object.=} options Enum options + * @param {string?} syntax The syntax level (e.g., proto3) + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Enum = function(builder, parent, name, options, syntax) { + Namespace.call(this, builder, parent, name, options, syntax); + + /** + * @override + */ + this.className = "Enum"; + + /** + * Runtime enum object. + * @type {Object.|null} + * @expose + */ + this.object = null; + }; + + /** + * Gets the string name of an enum value. + * @param {!ProtoBuf.Builder.Enum} enm Runtime enum + * @param {number} value Enum value + * @returns {?string} Name or `null` if not present + * @expose + */ + Enum.getName = function(enm, value) { + var keys = Object.keys(enm); + for (var i=0, key; i} + * @expose + */ + EnumPrototype.build = function(rebuild) { + if (this.object && !rebuild) + return this.object; + var enm = new ProtoBuf.Builder.Enum(), + values = this.getChildren(Enum.Value); + for (var i=0, k=values.length; i=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Namespace + */ + var Service = function(builder, root, name, options) { + Namespace.call(this, builder, root, name, options); + + /** + * @override + */ + this.className = "Service"; + + /** + * Built runtime service class. + * @type {?function(new:ProtoBuf.Builder.Service)} + */ + this.clazz = null; + }; + + /** + * @alias ProtoBuf.Reflect.Service.prototype + * @inner + */ + var ServicePrototype = 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 + */ + ServicePrototype.build = function(rebuild) { + if (this.clazz && !rebuild) + return this.clazz; + + // Create the runtime Service class in its own scope + 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, Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0); // Must be async! + }; + }; + + /** + * @alias ProtoBuf.Builder.Service.prototype + * @inner + */ + var ServicePrototype = Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype); + + /** + * 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(ProtoBuf.Reflect.Service.RPCMethod); + for (var i=0; i} + * @expose + */ + var $optionsS; // cc needs this + + /** + * Service options. + * @name ProtoBuf.Builder.Service#$options + * @type {Object.} + * @expose + */ + var $options; + + /** + * Reflection type. + * @name ProtoBuf.Builder.Service.$type + * @type {!ProtoBuf.Reflect.Service} + * @expose + */ + var $typeS; + + /** + * Reflection type. + * @name ProtoBuf.Builder.Service#$type + * @type {!ProtoBuf.Reflect.Service} + * @expose + */ + var $type; + + if (Object.defineProperty) + Object.defineProperty(Service, "$options", { "value": T.buildOpt() }), + Object.defineProperty(ServicePrototype, "$options", { "value": Service["$options"] }), + Object.defineProperty(Service, "$type", { "value": T }), + Object.defineProperty(ServicePrototype, "$type", { "value": T }); + + return Service; + + })(ProtoBuf, this); + }; + + /** + * @alias ProtoBuf.Reflect.Service + * @expose + */ + Reflect.Service = Service; + + /** + * Abstract service method. + * @exports ProtoBuf.Reflect.Service.Method + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.Service} svc Service + * @param {string} name Method name + * @param {Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.T + */ + var Method = function(builder, svc, name, options) { + T.call(this, builder, svc, name); + + /** + * @override + */ + this.className = "Service.Method"; + + /** + * Options. + * @type {Object.} + * @expose + */ + this.options = options || {}; + }; + + /** + * @alias ProtoBuf.Reflect.Service.Method.prototype + * @inner + */ + var MethodPrototype = Method.prototype = Object.create(T.prototype); + + /** + * Builds the method's '$options' property. + * @name ProtoBuf.Reflect.Service.Method#buildOpt + * @function + * @return {Object.} + */ + MethodPrototype.buildOpt = NamespacePrototype.buildOpt; + + /** + * @alias ProtoBuf.Reflect.Service.Method + * @expose + */ + Reflect.Service.Method = Method; + + /** + * RPC service method. + * @exports ProtoBuf.Reflect.Service.RPCMethod + * @param {!ProtoBuf.Builder} builder Builder reference + * @param {!ProtoBuf.Reflect.Service} svc Service + * @param {string} name Method name + * @param {string} request Request message name + * @param {string} response Response message name + * @param {boolean} request_stream Whether requests are streamed + * @param {boolean} response_stream Whether responses are streamed + * @param {Object.=} options Options + * @constructor + * @extends ProtoBuf.Reflect.Service.Method + */ + var RPCMethod = function(builder, svc, name, request, response, request_stream, response_stream, options) { + Method.call(this, builder, svc, name, options); + + /** + * @override + */ + this.className = "Service.RPCMethod"; + + /** + * Request message name. + * @type {string} + * @expose + */ + this.requestName = request; + + /** + * Response message name. + * @type {string} + * @expose + */ + this.responseName = response; + + /** + * Whether requests are streamed + * @type {bool} + * @expose + */ + this.requestStream = request_stream; + + /** + * Whether responses are streamed + * @type {bool} + * @expose + */ + this.responseStream = response_stream; + + /** + * 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. + * @param {Object.=} options Options + * @constructor + */ + var Builder = function(options) { + + /** + * Namespace. + * @type {ProtoBuf.Reflect.Namespace} + * @expose + */ + this.ns = new Reflect.Namespace(this, 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; + + /** + * Options. + * @type {!Object.} + * @expose + */ + this.options = options || {}; + }; + + /** + * @alias ProtoBuf.Builder.prototype + * @inner + */ + var BuilderPrototype = Builder.prototype; + + // ----- Definition tests ----- + + /** + * Tests if a definition most likely describes a message. + * @param {!Object} def + * @returns {boolean} + * @expose + */ + Builder.isMessage = function(def) { + // Messages require a string name + if (typeof def["name"] !== 'string') + return false; + // Messages do not contain values (enum) or rpc methods (service) + if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined') + return false; + return true; + }; + + /** + * Tests if a definition most likely describes a message field. + * @param {!Object} def + * @returns {boolean} + * @expose + */ + Builder.isMessageField = function(def) { + // Message fields require a string rule, name and type and an id + if (typeof def["rule"] !== 'string' || typeof def["name"] !== 'string' || typeof def["type"] !== 'string' || typeof def["id"] === 'undefined') + return false; + return true; + }; + + /** + * Tests if a definition most likely describes an enum. + * @param {!Object} def + * @returns {boolean} + * @expose + */ + Builder.isEnum = function(def) { + // Enums require a string name + if (typeof def["name"] !== 'string') + return false; + // Enums require at least one value + if (typeof def["values"] === 'undefined' || !Array.isArray(def["values"]) || def["values"].length === 0) + return false; + return true; + }; + + /** + * Tests if a definition most likely describes a service. + * @param {!Object} def + * @returns {boolean} + * @expose + */ + Builder.isService = function(def) { + // Services require a string name and an rpc object + if (typeof def["name"] !== 'string' || typeof def["rpc"] !== 'object' || !def["rpc"]) + return false; + return true; + }; + + /** + * Tests if a definition most likely describes an extended message + * @param {!Object} def + * @returns {boolean} + * @expose + */ + Builder.isExtend = function(def) { + // Extends rquire a string ref + if (typeof def["ref"] !== 'string') + return false; + return true; + }; + + // ----- Building ----- + + /** + * Resets the pointer to the root namespace. + * @returns {!ProtoBuf.Builder} this + * @expose + */ + BuilderPrototype.reset = function() { + this.ptr = this.ns; + return this; + }; + + /** + * Defines a namespace on top of the current pointer position and places the pointer on it. + * @param {string} namespace + * @return {!ProtoBuf.Builder} this + * @expose + */ + BuilderPrototype.define = function(namespace) { + if (typeof namespace !== 'string' || !Lang.TYPEREF.test(namespace)) + throw Error("illegal namespace: "+namespace); + namespace.split(".").forEach(function(part) { + var ns = this.ptr.getChild(part); + if (ns === null) // Keep existing + this.ptr.addChild(ns = new Reflect.Namespace(this, this.ptr, part)); + this.ptr = ns; + }, this); + return this; + }; + + /** + * Creates the specified definitions at the current pointer position. + * @param {!Array.} defs Messages, enums or services to create + * @returns {!ProtoBuf.Builder} this + * @throws {Error} If a message definition is invalid + * @expose + */ + BuilderPrototype.create = function(defs) { + if (!defs) + return this; // Nothing to create + if (!Array.isArray(defs)) + defs = [defs]; + else { + if (defs.length === 0) + return this; + defs = defs.slice(); + } + + // It's quite hard to keep track of scopes and memory here, so let's do this iteratively. + var stack = [defs]; + while (stack.length > 0) { + defs = stack.pop(); + + if (!Array.isArray(defs)) // Stack always contains entire namespaces + throw Error("not a valid namespace: "+JSON.stringify(defs)); + + while (defs.length > 0) { + var def = defs.shift(); // Namespaces always contain an array of messages, enums and services + + if (Builder.isMessage(def)) { + var obj = new Reflect.Message(this, this.ptr, def["name"], def["options"], def["isGroup"], def["syntax"]); + + // Create OneOfs + var oneofs = {}; + if (def["oneofs"]) + Object.keys(def["oneofs"]).forEach(function(name) { + obj.addChild(oneofs[name] = new Reflect.Message.OneOf(this, obj, name)); + }, this); + + // Create fields + if (def["fields"]) + def["fields"].forEach(function(fld) { + if (obj.getChild(fld["id"]|0) !== null) + throw Error("duplicate or invalid field id in "+obj.name+": "+fld['id']); + if (fld["options"] && typeof fld["options"] !== 'object') + throw Error("illegal field options in "+obj.name+"#"+fld["name"]); + var oneof = null; + if (typeof fld["oneof"] === 'string' && !(oneof = oneofs[fld["oneof"]])) + throw Error("illegal oneof in "+obj.name+"#"+fld["name"]+": "+fld["oneof"]); + fld = new Reflect.Message.Field(this, obj, fld["rule"], fld["keytype"], fld["type"], fld["name"], fld["id"], fld["options"], oneof, def["syntax"]); + if (oneof) + oneof.fields.push(fld); + obj.addChild(fld); + }, this); + + // Push children to stack + var subObj = []; + if (def["enums"]) + def["enums"].forEach(function(enm) { + subObj.push(enm); + }); + if (def["messages"]) + def["messages"].forEach(function(msg) { + subObj.push(msg); + }); + if (def["services"]) + def["services"].forEach(function(svc) { + subObj.push(svc); + }); + + // Set extension range + if (def["extensions"]) { + obj.extensions = def["extensions"]; + if (obj.extensions[0] < ProtoBuf.ID_MIN) + obj.extensions[0] = ProtoBuf.ID_MIN; + if (obj.extensions[1] > ProtoBuf.ID_MAX) + obj.extensions[1] = ProtoBuf.ID_MAX; + } + + // Create on top of current namespace + this.ptr.addChild(obj); + 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; + + } else if (Builder.isEnum(def)) { + + obj = new Reflect.Enum(this, this.ptr, def["name"], def["options"], def["syntax"]); + def["values"].forEach(function(val) { + obj.addChild(new Reflect.Enum.Value(this, obj, val["name"], val["id"])); + }, this); + this.ptr.addChild(obj); + + } else if (Builder.isService(def)) { + + obj = new Reflect.Service(this, this.ptr, def["name"], def["options"]); + Object.keys(def["rpc"]).forEach(function(name) { + var mtd = def["rpc"][name]; + obj.addChild(new Reflect.Service.RPCMethod(this, obj, name, mtd["request"], mtd["response"], !!mtd["request_stream"], !!mtd["response_stream"], mtd["options"])); + }, this); + this.ptr.addChild(obj); + + } else if (Builder.isExtend(def)) { + + obj = this.ptr.resolve(def["ref"], true); + if (obj) { + def["fields"].forEach(function(fld) { + if (obj.getChild(fld['id']|0) !== null) + throw Error("duplicate extended field id in "+obj.name+": "+fld['id']); + if (fld['id'] < obj.extensions[0] || fld['id'] > obj.extensions[1]) + throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" ("+obj.extensions.join(' to ')+" expected)"); + // Convert extension field names to camel case notation if the override is set + var name = fld["name"]; + if (this.options['convertFieldsToCamelCase']) + name = ProtoBuf.Util.toCamelCase(name); + // see #161: Extensions use their fully qualified name as their runtime key and... + var field = new Reflect.Message.ExtensionField(this, obj, fld["rule"], fld["type"], this.ptr.fqn()+'.'+name, fld["id"], fld["options"]); + // ...are added on top of the current namespace as an extension which is used for + // resolving their type later on (the extension always keeps the original name to + // prevent naming collisions) + var ext = new Reflect.Extension(this, this.ptr, fld["name"], field); + field.extension = ext; + this.ptr.addChild(ext); + obj.addChild(field); + }, this); + + } else if (!/\.?google\.protobuf\./.test(def["ref"])) // Silently skip internal extensions + throw Error("extended message "+def["ref"]+" is not defined"); + + } else + throw Error("not a valid definition: "+JSON.stringify(def)); + + def = null; + obj = null; + } + // Break goes here + defs = null; + this.ptr = this.ptr.parent; // Namespace done, continue at parent + } + this.resolved = false; // Require re-resolve + this.result = null; // Require re-build + return this; + }; + + /** + * Propagates syntax to all children. + * @param {!Object} parent + * @inner + */ + function propagateSyntax(parent) { + if (parent['messages']) { + parent['messages'].forEach(function(child) { + child["syntax"] = parent["syntax"]; + propagateSyntax(child); + }); + } + if (parent['enums']) { + parent['enums'].forEach(function(child) { + child["syntax"] = parent["syntax"]; + }); + } + } + + /** + * Imports another definition into this builder. + * @param {Object.} json Parsed import + * @param {(string|{root: string, file: string})=} filename Imported file name + * @returns {!ProtoBuf.Builder} this + * @throws {Error} If the definition or file cannot be imported + * @expose + */ + BuilderPrototype["import"] = function(json, filename) { + var delim = '/'; + + // Make sure to skip duplicate imports + + if (typeof filename === 'string') { + + if (ProtoBuf.Util.IS_NODE) + filename = require("path")['resolve'](filename); + if (this.files[filename] === true) + return this.reset(); + this.files[filename] = true; + + } else if (typeof filename === 'object') { // Object with root, file. + + var root = filename.root; + if (ProtoBuf.Util.IS_NODE) + root = require("path")['resolve'](root); + if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0) + delim = '\\'; + var fname = root + delim + filename.file; + if (this.files[fname] === true) + return this.reset(); + this.files[fname] = true; + } + + // Import imports + + if (json['imports'] && json['imports'].length > 0) { + var importRoot, + 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)=} path Specifies what to return. If omitted, the entire namespace will be returned. + * @returns {!ProtoBuf.Builder.Message|!Object.} + * @throws {Error} If a type could not be resolved + * @expose + */ + BuilderPrototype.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; + var part = typeof path === 'string' ? path.split(".") : path, + ptr = this.result; // Build namespace pointer (no hasChild etc.) + for (var i=0; i=} contents Initial contents + * @constructor + */ + var Map = function(field, contents) { + if (!field.map) + throw Error("field is not a map"); + + /** + * The field corresponding to this map. + * @type {!ProtoBuf.Reflect.Field} + */ + this.field = field; + + /** + * Element instance corresponding to key type. + * @type {!ProtoBuf.Reflect.Element} + */ + this.keyElem = new Reflect.Element(field.keyType, null, true, field.syntax); + + /** + * Element instance corresponding to value type. + * @type {!ProtoBuf.Reflect.Element} + */ + this.valueElem = new Reflect.Element(field.type, field.resolvedType, false, field.syntax); + + /** + * Internal map: stores mapping of (string form of key) -> (key, value) + * pair. + * + * We provide map semantics for arbitrary key types, but we build on top + * of an Object, which has only string keys. In order to avoid the need + * to convert a string key back to its native type in many situations, + * we store the native key value alongside the value. Thus, we only need + * a one-way mapping from a key type to its string form that guarantees + * uniqueness and equality (i.e., str(K1) === str(K2) if and only if K1 + * === K2). + * + * @type {!Object} + */ + this.map = {}; + + /** + * Returns the number of elements in the map. + */ + Object.defineProperty(this, "size", { + get: function() { return Object.keys(this.map).length; } + }); + + // Fill initial contents from a raw object. + if (contents) { + var keys = Object.keys(contents); + for (var i = 0; i < keys.length; i++) { + var key = this.keyElem.valueFromString(keys[i]); + var val = this.valueElem.verifyValue(contents[keys[i]]); + this.map[this.keyElem.valueToString(key)] = + { key: key, value: val }; + } + } + }; + + var MapPrototype = Map.prototype; + + /** + * Helper: return an iterator over an array. + * @param {!Array<*>} arr the array + * @returns {!Object} an iterator + * @inner + */ + function arrayIterator(arr) { + var idx = 0; + return { + next: function() { + if (idx < arr.length) + return { done: false, value: arr[idx++] }; + return { done: true }; + } + } + } + + /** + * Clears the map. + */ + MapPrototype.clear = function() { + this.map = {}; + }; + + /** + * Deletes a particular key from the map. + * @returns {boolean} Whether any entry with this key was deleted. + */ + MapPrototype["delete"] = function(key) { + var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key)); + var hadKey = keyValue in this.map; + delete this.map[keyValue]; + return hadKey; + }; + + /** + * Returns an iterator over [key, value] pairs in the map. + * @returns {Object} The iterator + */ + MapPrototype.entries = function() { + var entries = []; + var strKeys = Object.keys(this.map); + for (var i = 0, entry; i < strKeys.length; i++) + entries.push([(entry=this.map[strKeys[i]]).key, entry.value]); + return arrayIterator(entries); + }; + + /** + * Returns an iterator over keys in the map. + * @returns {Object} The iterator + */ + MapPrototype.keys = function() { + var keys = []; + var strKeys = Object.keys(this.map); + for (var i = 0; i < strKeys.length; i++) + keys.push(this.map[strKeys[i]].key); + return arrayIterator(keys); + }; + + /** + * Returns an iterator over values in the map. + * @returns {!Object} The iterator + */ + MapPrototype.values = function() { + var values = []; + var strKeys = Object.keys(this.map); + for (var i = 0; i < strKeys.length; i++) + values.push(this.map[strKeys[i]].value); + return arrayIterator(values); + }; + + /** + * Iterates over entries in the map, calling a function on each. + * @param {function(this:*, *, *, *)} cb The callback to invoke with value, key, and map arguments. + * @param {Object=} thisArg The `this` value for the callback + */ + MapPrototype.forEach = function(cb, thisArg) { + var strKeys = Object.keys(this.map); + for (var i = 0, entry; i < strKeys.length; i++) + cb.call(thisArg, (entry=this.map[strKeys[i]]).value, entry.key, this); + }; + + /** + * Sets a key in the map to the given value. + * @param {*} key The key + * @param {*} value The value + * @returns {!ProtoBuf.Map} The map instance + */ + MapPrototype.set = function(key, value) { + var keyValue = this.keyElem.verifyValue(key); + var valValue = this.valueElem.verifyValue(value); + this.map[this.keyElem.valueToString(keyValue)] = + { key: keyValue, value: valValue }; + return this; + }; + + /** + * Gets the value corresponding to a key in the map. + * @param {*} key The key + * @returns {*|undefined} The value, or `undefined` if key not present + */ + MapPrototype.get = function(key) { + var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key)); + if (!(keyValue in this.map)) + return undefined; + return this.map[keyValue].value; + }; + + /** + * Determines whether the given key is present in the map. + * @param {*} key The key + * @returns {boolean} `true` if the key is present + */ + MapPrototype.has = function(key) { + var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key)); + return (keyValue in this.map); + }; + + return Map; + })(ProtoBuf, ProtoBuf.Reflect); + + + /** + * 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 = undefined; + return ProtoBuf.loadJson(ProtoBuf.DotProto.Parser.parse(proto), 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(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and + * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the + * file will be read synchronously and this function will return the Builder. + * @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) + return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) { + if (contents === null) { + callback(Error("Failed to fetch file")); + return; + } + try { + callback(null, ProtoBuf.loadProto(contents, builder, filename)); + } catch (e) { + callback(e); + } + }); + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents === null ? null : ProtoBuf.loadProto(contents, builder, filename); + }; + + /** + * 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(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and + * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the + * file will be read synchronously and this function will return the Builder. + * @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 + + + /** + * Constructs a new empty Builder. + * @param {Object.=} options Builder options, defaults to global options set on ProtoBuf + * @return {!ProtoBuf.Builder} Builder + * @expose + */ + ProtoBuf.newBuilder = function(options) { + options = options || {}; + if (typeof options['convertFieldsToCamelCase'] === 'undefined') + options['convertFieldsToCamelCase'] = ProtoBuf.convertFieldsToCamelCase; + if (typeof options['populateAccessors'] === 'undefined') + options['populateAccessors'] = ProtoBuf.populateAccessors; + return new ProtoBuf.Builder(options); + }; + + /** + * 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(); + 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(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and + * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the + * file will be read synchronously and this function will return the Builder. + * @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) + return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) { + if (contents === null) { + callback(Error("Failed to fetch file")); + return; + } + try { + callback(null, ProtoBuf.loadJson(JSON.parse(contents), builder, filename)); + } catch (e) { + callback(e); + } + }); + var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename); + return contents === null ? null : ProtoBuf.loadJson(JSON.parse(contents), builder, filename); + }; + + return ProtoBuf; +}); + +}).call(this,require('_process')) +},{"_process":20,"bytebuffer":22,"fs":19,"path":19}],22:[function(require,module,exports){ +/* + Copyright 2013-2014 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) 2015 Daniel Wirtz + * Backing buffer: ArrayBuffer, Accessor: Uint8Array + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/bytebuffer.js for details + */ +(function(global, factory) { + + /* AMD */ if (typeof define === 'function' && define["amd"]) + define(["long"], factory); + /* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"]) + module['exports'] = (function() { + var Long; try { Long = require("long"); } catch (e) {} + return factory(Long); + })(); + /* Global */ else + (global["dcodeIO"] = global["dcodeIO"] || {})["ByteBuffer"] = factory(global["dcodeIO"]["Long"]); + +})(this, function(Long) { + "use strict"; + + /** + * Constructs a new ByteBuffer. + * @class The swiss army knife for binary data in JavaScript. + * @exports ByteBuffer + * @constructor + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @expose + */ + var ByteBuffer = function(capacity, littleEndian, noAssert) { + if (typeof capacity === 'undefined') + capacity = ByteBuffer.DEFAULT_CAPACITY; + if (typeof littleEndian === 'undefined') + littleEndian = ByteBuffer.DEFAULT_ENDIAN; + if (typeof noAssert === 'undefined') + noAssert = ByteBuffer.DEFAULT_NOASSERT; + if (!noAssert) { + capacity = capacity | 0; + if (capacity < 0) + throw RangeError("Illegal capacity"); + littleEndian = !!littleEndian; + noAssert = !!noAssert; + } + + /** + * Backing ArrayBuffer. + * @type {!ArrayBuffer} + * @expose + */ + this.buffer = capacity === 0 ? EMPTY_BUFFER : new ArrayBuffer(capacity); + + /** + * Uint8Array utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`. + * @type {?Uint8Array} + * @expose + */ + this.view = capacity === 0 ? null : new Uint8Array(this.buffer); + + /** + * Absolute read/write offset. + * @type {number} + * @expose + * @see ByteBuffer#flip + * @see ByteBuffer#clear + */ + this.offset = 0; + + /** + * Marked offset. + * @type {number} + * @expose + * @see ByteBuffer#mark + * @see ByteBuffer#reset + */ + this.markedOffset = -1; + + /** + * Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation. + * @type {number} + * @expose + * @see ByteBuffer#flip + * @see ByteBuffer#clear + */ + this.limit = capacity; + + /** + * Whether to use little endian byte order, defaults to `false` for big endian. + * @type {boolean} + * @expose + */ + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : false; + + /** + * Whether to skip assertions of offsets and values, defaults to `false`. + * @type {boolean} + * @expose + */ + this.noAssert = !!noAssert; + }; + + /** + * ByteBuffer version. + * @type {string} + * @const + * @expose + */ + ByteBuffer.VERSION = "5.0.0"; + + /** + * Little endian constant that can be used instead of its boolean value. Evaluates to `true`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.LITTLE_ENDIAN = true; + + /** + * Big endian constant that can be used instead of its boolean value. Evaluates to `false`. + * @type {boolean} + * @const + * @expose + */ + ByteBuffer.BIG_ENDIAN = false; + + /** + * Default initial capacity of `16`. + * @type {number} + * @expose + */ + ByteBuffer.DEFAULT_CAPACITY = 16; + + /** + * Default endianess of `false` for big endian. + * @type {boolean} + * @expose + */ + ByteBuffer.DEFAULT_ENDIAN = ByteBuffer.BIG_ENDIAN; + + /** + * Default no assertions flag of `false`. + * @type {boolean} + * @expose + */ + ByteBuffer.DEFAULT_NOASSERT = false; + + /** + * A `Long` class for representing a 64-bit two's-complement integer value. May be `null` if Long.js has not been loaded + * and int64 support is not available. + * @type {?Long} + * @const + * @see https://github.com/dcodeIO/Long.js + * @expose + */ + ByteBuffer.Long = Long || null; + + /** + * @alias ByteBuffer.prototype + * @inner + */ + var ByteBufferPrototype = ByteBuffer.prototype; + + /** + * An indicator used to reliably determine if an object is a ByteBuffer or not. + * @type {boolean} + * @const + * @expose + * @private + */ + ByteBufferPrototype.__isByteBuffer__; + + Object.defineProperty(ByteBufferPrototype, "__isByteBuffer__", { + value: true, + enumerable: false, + configurable: false + }); + + // helpers + + /** + * @type {!ArrayBuffer} + * @inner + */ + var EMPTY_BUFFER = new ArrayBuffer(0); + + /** + * String.fromCharCode reference for compile-time renaming. + * @type {function(...number):string} + * @inner + */ + var stringFromCharCode = String.fromCharCode; + + /** + * Creates a source function for a string. + * @param {string} s String to read from + * @returns {function():number|null} Source function returning the next char code respectively `null` if there are + * no more characters left. + * @throws {TypeError} If the argument is invalid + * @inner + */ + function stringSource(s) { + var i=0; return function() { + return i < s.length ? s.charCodeAt(i++) : null; + }; + } + + /** + * Creates a destination function for a string. + * @returns {function(number=):undefined|string} Destination function successively called with the next char code. + * Returns the final string when called without arguments. + * @inner + */ + function stringDestination() { + var cs = [], ps = []; return function() { + if (arguments.length === 0) + return ps.join('')+stringFromCharCode.apply(String, cs); + if (cs.length + arguments.length > 1024) + ps.push(stringFromCharCode.apply(String, cs)), + cs.length = 0; + Array.prototype.push.apply(cs, arguments); + }; + } + + /** + * Gets the accessor type. + * @returns {Function} `Buffer` under node.js, `Uint8Array` respectively `DataView` in the browser (classes) + * @expose + */ + ByteBuffer.accessor = function() { + return Uint8Array; + }; + /** + * Allocates a new ByteBuffer backed by a buffer of the specified capacity. + * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} + * @expose + */ + ByteBuffer.allocate = function(capacity, littleEndian, noAssert) { + return new ByteBuffer(capacity, littleEndian, noAssert); + }; + + /** + * Concatenates multiple ByteBuffers into one. + * @param {!Array.} buffers Buffers to concatenate + * @param {(string|boolean)=} encoding String encoding if `buffers` contains a string ("base64", "hex", "binary", + * defaults to "utf8") + * @param {boolean=} littleEndian Whether to use little or big endian byte order for the resulting ByteBuffer. Defaults + * to {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values for the resulting ByteBuffer. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} Concatenated ByteBuffer + * @expose + */ + ByteBuffer.concat = function(buffers, encoding, littleEndian, noAssert) { + if (typeof encoding === 'boolean' || typeof encoding !== 'string') { + noAssert = littleEndian; + littleEndian = encoding; + encoding = undefined; + } + var capacity = 0; + for (var i=0, k=buffers.length, length; i 0) capacity += length; + } + if (capacity === 0) + return new ByteBuffer(0, littleEndian, noAssert); + var bb = new ByteBuffer(capacity, littleEndian, noAssert), + bi; + i=0; while (i} buffer Anything that can be wrapped + * @param {(string|boolean)=} encoding String encoding if `buffer` is a string ("base64", "hex", "binary", defaults to + * "utf8") + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} A ByteBuffer wrapping `buffer` + * @expose + */ + ByteBuffer.wrap = function(buffer, encoding, littleEndian, noAssert) { + if (typeof encoding !== 'string') { + noAssert = littleEndian; + littleEndian = encoding; + encoding = undefined; + } + if (typeof buffer === 'string') { + if (typeof encoding === 'undefined') + encoding = "utf8"; + switch (encoding) { + case "base64": + return ByteBuffer.fromBase64(buffer, littleEndian); + case "hex": + return ByteBuffer.fromHex(buffer, littleEndian); + case "binary": + return ByteBuffer.fromBinary(buffer, littleEndian); + case "utf8": + return ByteBuffer.fromUTF8(buffer, littleEndian); + case "debug": + return ByteBuffer.fromDebug(buffer, littleEndian); + default: + throw Error("Unsupported encoding: "+encoding); + } + } + if (buffer === null || typeof buffer !== 'object') + throw TypeError("Illegal buffer"); + var bb; + if (ByteBuffer.isByteBuffer(buffer)) { + bb = ByteBufferPrototype.clone.call(buffer); + bb.markedOffset = -1; + return bb; + } + if (buffer instanceof Uint8Array) { // Extract ArrayBuffer from Uint8Array + bb = new ByteBuffer(0, littleEndian, noAssert); + if (buffer.length > 0) { // Avoid references to more than one EMPTY_BUFFER + bb.buffer = buffer.buffer; + bb.offset = buffer.byteOffset; + bb.limit = buffer.byteOffset + buffer.byteLength; + bb.view = new Uint8Array(buffer.buffer); + } + } else if (buffer instanceof ArrayBuffer) { // Reuse ArrayBuffer + bb = new ByteBuffer(0, littleEndian, noAssert); + if (buffer.byteLength > 0) { + bb.buffer = buffer; + bb.offset = 0; + bb.limit = buffer.byteLength; + bb.view = buffer.byteLength > 0 ? new Uint8Array(buffer) : null; + } + } else if (Object.prototype.toString.call(buffer) === "[object Array]") { // Create from octets + bb = new ByteBuffer(buffer.length, littleEndian, noAssert); + bb.limit = buffer.length; + for (var i=0; i>>= 0; + if (offset < 0 || offset + length > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength); + } + var slice = this.slice(offset, offset + length); + if (relative) this.offset += length; + return slice; + }; + + /** + * Writes a payload of bytes. This is an alias of {@link ByteBuffer#append}. + * @function + * @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to write. If `source` is a ByteBuffer, its offsets + * will be modified according to the performed read operation. + * @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8") + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeBytes = ByteBufferPrototype.append; + + // types/ints/int8 + + /** + * Writes an 8bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeInt8 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value |= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 1; + var capacity0 = this.buffer.byteLength; + if (offset > capacity0) + this.resize((capacity0 *= 2) > offset ? capacity0 : offset); + offset -= 1; + this.view[offset] = value; + if (relative) this.offset += 1; + return this; + }; + + /** + * Writes an 8bit signed integer. This is an alias of {@link ByteBuffer#writeInt8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeByte = ByteBufferPrototype.writeInt8; + + /** + * Reads an 8bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readInt8 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + var value = this.view[offset]; + if ((value & 0x80) === 0x80) value = -(0xFF - value + 1); // Cast to signed + if (relative) this.offset += 1; + return value; + }; + + /** + * Reads an 8bit signed integer. This is an alias of {@link ByteBuffer#readInt8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readByte = ByteBufferPrototype.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} by `1` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeUint8 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value >>>= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 1; + var capacity1 = this.buffer.byteLength; + if (offset > capacity1) + this.resize((capacity1 *= 2) > offset ? capacity1 : offset); + offset -= 1; + this.view[offset] = value; + if (relative) this.offset += 1; + return this; + }; + + /** + * Writes an 8bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint8}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeUInt8 = ByteBufferPrototype.writeUint8; + + /** + * Reads an 8bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readUint8 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + var value = this.view[offset]; + if (relative) this.offset += 1; + return value; + }; + + /** + * Reads an 8bit unsigned integer. This is an alias of {@link ByteBuffer#readUint8}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readUInt8 = ByteBufferPrototype.readUint8; + + // types/ints/int16 + + /** + * 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} by `2` if omitted. + * @throws {TypeError} If `offset` or `value` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.writeInt16 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value |= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 2; + var capacity2 = this.buffer.byteLength; + if (offset > capacity2) + this.resize((capacity2 *= 2) > offset ? capacity2 : offset); + offset -= 2; + if (this.littleEndian) { + this.view[offset+1] = (value & 0xFF00) >>> 8; + this.view[offset ] = value & 0x00FF; + } else { + this.view[offset] = (value & 0xFF00) >>> 8; + this.view[offset+1] = value & 0x00FF; + } + if (relative) this.offset += 2; + return this; + }; + + /** + * Writes a 16bit signed integer. 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} by `2` if omitted. + * @throws {TypeError} If `offset` or `value` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.writeShort = ByteBufferPrototype.writeInt16; + + /** + * Reads a 16bit signed integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. + * @returns {number} Value read + * @throws {TypeError} If `offset` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.readInt16 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 2 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength); + } + var value = 0; + if (this.littleEndian) { + value = this.view[offset ]; + value |= this.view[offset+1] << 8; + } else { + value = this.view[offset ] << 8; + value |= this.view[offset+1]; + } + if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1); // Cast to signed + if (relative) this.offset += 2; + return value; + }; + + /** + * Reads a 16bit signed integer. This is an alias of {@link ByteBuffer#readInt16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. + * @returns {number} Value read + * @throws {TypeError} If `offset` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.readShort = ByteBufferPrototype.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} by `2` if omitted. + * @throws {TypeError} If `offset` or `value` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.writeUint16 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value >>>= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 2; + var capacity3 = this.buffer.byteLength; + if (offset > capacity3) + this.resize((capacity3 *= 2) > offset ? capacity3 : offset); + offset -= 2; + if (this.littleEndian) { + this.view[offset+1] = (value & 0xFF00) >>> 8; + this.view[offset ] = value & 0x00FF; + } else { + this.view[offset] = (value & 0xFF00) >>> 8; + this.view[offset+1] = value & 0x00FF; + } + if (relative) this.offset += 2; + return this; + }; + + /** + * Writes a 16bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint16}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. + * @throws {TypeError} If `offset` or `value` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.writeUInt16 = ByteBufferPrototype.writeUint16; + + /** + * Reads a 16bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. + * @returns {number} Value read + * @throws {TypeError} If `offset` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.readUint16 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 2 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength); + } + var value = 0; + if (this.littleEndian) { + value = this.view[offset ]; + value |= this.view[offset+1] << 8; + } else { + value = this.view[offset ] << 8; + value |= this.view[offset+1]; + } + if (relative) this.offset += 2; + return value; + }; + + /** + * Reads a 16bit unsigned integer. This is an alias of {@link ByteBuffer#readUint16}. + * @function + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. + * @returns {number} Value read + * @throws {TypeError} If `offset` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @expose + */ + ByteBufferPrototype.readUInt16 = ByteBufferPrototype.readUint16; + + // types/ints/int32 + + /** + * Writes a 32bit signed integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @expose + */ + ByteBufferPrototype.writeInt32 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value |= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 4; + var capacity4 = this.buffer.byteLength; + if (offset > capacity4) + this.resize((capacity4 *= 2) > offset ? capacity4 : offset); + offset -= 4; + if (this.littleEndian) { + this.view[offset+3] = (value >>> 24) & 0xFF; + this.view[offset+2] = (value >>> 16) & 0xFF; + this.view[offset+1] = (value >>> 8) & 0xFF; + this.view[offset ] = value & 0xFF; + } else { + this.view[offset ] = (value >>> 24) & 0xFF; + this.view[offset+1] = (value >>> 16) & 0xFF; + this.view[offset+2] = (value >>> 8) & 0xFF; + this.view[offset+3] = value & 0xFF; + } + if (relative) this.offset += 4; + return this; + }; + + /** + * Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @expose + */ + ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32; + + /** + * Reads a 32bit signed integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readInt32 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 4 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength); + } + var value = 0; + if (this.littleEndian) { + value = this.view[offset+2] << 16; + value |= this.view[offset+1] << 8; + value |= this.view[offset ]; + value += this.view[offset+3] << 24 >>> 0; + } else { + value = this.view[offset+1] << 16; + value |= this.view[offset+2] << 8; + value |= this.view[offset+3]; + value += this.view[offset ] << 24 >>> 0; + } + value |= 0; // Cast to signed + if (relative) this.offset += 4; + return value; + }; + + /** + * Reads a 32bit signed integer. This is an alias of {@link ByteBuffer#readInt32}. + * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32; + + /** + * Writes a 32bit unsigned integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @expose + */ + ByteBufferPrototype.writeUint32 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value >>>= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 4; + var capacity5 = this.buffer.byteLength; + if (offset > capacity5) + this.resize((capacity5 *= 2) > offset ? capacity5 : offset); + offset -= 4; + if (this.littleEndian) { + this.view[offset+3] = (value >>> 24) & 0xFF; + this.view[offset+2] = (value >>> 16) & 0xFF; + this.view[offset+1] = (value >>> 8) & 0xFF; + this.view[offset ] = value & 0xFF; + } else { + this.view[offset ] = (value >>> 24) & 0xFF; + this.view[offset+1] = (value >>> 16) & 0xFF; + this.view[offset+2] = (value >>> 8) & 0xFF; + this.view[offset+3] = value & 0xFF; + } + if (relative) this.offset += 4; + return this; + }; + + /** + * Writes a 32bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint32}. + * @function + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @expose + */ + ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32; + + /** + * Reads a 32bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readUint32 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 4 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength); + } + var value = 0; + if (this.littleEndian) { + value = this.view[offset+2] << 16; + value |= this.view[offset+1] << 8; + value |= this.view[offset ]; + value += this.view[offset+3] << 24 >>> 0; + } else { + value = this.view[offset+1] << 16; + value |= this.view[offset+2] << 8; + value |= this.view[offset+3]; + value += this.view[offset ] << 24 >>> 0; + } + if (relative) this.offset += 4; + return value; + }; + + /** + * Reads a 32bit unsigned integer. This is an alias of {@link ByteBuffer#readUint32}. + * @function + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} Value read + * @expose + */ + ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32; + + // types/ints/int64 + + if (Long) { + + /** + * Writes a 64bit signed integer. + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeInt64 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + else if (!(value && value instanceof Long)) + throw TypeError("Illegal value: "+value+" (not an integer or Long)"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + offset += 8; + var capacity6 = this.buffer.byteLength; + if (offset > capacity6) + this.resize((capacity6 *= 2) > offset ? capacity6 : offset); + offset -= 8; + var lo = value.low, + hi = value.high; + if (this.littleEndian) { + this.view[offset+3] = (lo >>> 24) & 0xFF; + this.view[offset+2] = (lo >>> 16) & 0xFF; + this.view[offset+1] = (lo >>> 8) & 0xFF; + this.view[offset ] = lo & 0xFF; + offset += 4; + this.view[offset+3] = (hi >>> 24) & 0xFF; + this.view[offset+2] = (hi >>> 16) & 0xFF; + this.view[offset+1] = (hi >>> 8) & 0xFF; + this.view[offset ] = hi & 0xFF; + } else { + this.view[offset ] = (hi >>> 24) & 0xFF; + this.view[offset+1] = (hi >>> 16) & 0xFF; + this.view[offset+2] = (hi >>> 8) & 0xFF; + this.view[offset+3] = hi & 0xFF; + offset += 4; + this.view[offset ] = (lo >>> 24) & 0xFF; + this.view[offset+1] = (lo >>> 16) & 0xFF; + this.view[offset+2] = (lo >>> 8) & 0xFF; + this.view[offset+3] = lo & 0xFF; + } + if (relative) this.offset += 8; + return this; + }; + + /** + * Writes a 64bit signed integer. This is an alias of {@link ByteBuffer#writeInt64}. + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeLong = ByteBufferPrototype.writeInt64; + + /** + * Reads a 64bit signed integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!Long} + * @expose + */ + ByteBufferPrototype.readInt64 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 8 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength); + } + var lo = 0, + hi = 0; + if (this.littleEndian) { + lo = this.view[offset+2] << 16; + lo |= this.view[offset+1] << 8; + lo |= this.view[offset ]; + lo += this.view[offset+3] << 24 >>> 0; + offset += 4; + hi = this.view[offset+2] << 16; + hi |= this.view[offset+1] << 8; + hi |= this.view[offset ]; + hi += this.view[offset+3] << 24 >>> 0; + } else { + hi = this.view[offset+1] << 16; + hi |= this.view[offset+2] << 8; + hi |= this.view[offset+3]; + hi += this.view[offset ] << 24 >>> 0; + offset += 4; + lo = this.view[offset+1] << 16; + lo |= this.view[offset+2] << 8; + lo |= this.view[offset+3]; + lo += this.view[offset ] << 24 >>> 0; + } + var value = new Long(lo, hi, false); + if (relative) this.offset += 8; + return value; + }; + + /** + * Reads a 64bit signed integer. This is an alias of {@link ByteBuffer#readInt64}. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!Long} + * @expose + */ + ByteBufferPrototype.readLong = ByteBufferPrototype.readInt64; + + /** + * Writes a 64bit unsigned integer. + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeUint64 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + else if (!(value && value instanceof Long)) + throw TypeError("Illegal value: "+value+" (not an integer or Long)"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + offset += 8; + var capacity7 = this.buffer.byteLength; + if (offset > capacity7) + this.resize((capacity7 *= 2) > offset ? capacity7 : offset); + offset -= 8; + var lo = value.low, + hi = value.high; + if (this.littleEndian) { + this.view[offset+3] = (lo >>> 24) & 0xFF; + this.view[offset+2] = (lo >>> 16) & 0xFF; + this.view[offset+1] = (lo >>> 8) & 0xFF; + this.view[offset ] = lo & 0xFF; + offset += 4; + this.view[offset+3] = (hi >>> 24) & 0xFF; + this.view[offset+2] = (hi >>> 16) & 0xFF; + this.view[offset+1] = (hi >>> 8) & 0xFF; + this.view[offset ] = hi & 0xFF; + } else { + this.view[offset ] = (hi >>> 24) & 0xFF; + this.view[offset+1] = (hi >>> 16) & 0xFF; + this.view[offset+2] = (hi >>> 8) & 0xFF; + this.view[offset+3] = hi & 0xFF; + offset += 4; + this.view[offset ] = (lo >>> 24) & 0xFF; + this.view[offset+1] = (lo >>> 16) & 0xFF; + this.view[offset+2] = (lo >>> 8) & 0xFF; + this.view[offset+3] = lo & 0xFF; + } + if (relative) this.offset += 8; + return this; + }; + + /** + * Writes a 64bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint64}. + * @function + * @param {number|!Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeUInt64 = ByteBufferPrototype.writeUint64; + + /** + * Reads a 64bit unsigned integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!Long} + * @expose + */ + ByteBufferPrototype.readUint64 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 8 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength); + } + var lo = 0, + hi = 0; + if (this.littleEndian) { + lo = this.view[offset+2] << 16; + lo |= this.view[offset+1] << 8; + lo |= this.view[offset ]; + lo += this.view[offset+3] << 24 >>> 0; + offset += 4; + hi = this.view[offset+2] << 16; + hi |= this.view[offset+1] << 8; + hi |= this.view[offset ]; + hi += this.view[offset+3] << 24 >>> 0; + } else { + hi = this.view[offset+1] << 16; + hi |= this.view[offset+2] << 8; + hi |= this.view[offset+3]; + hi += this.view[offset ] << 24 >>> 0; + offset += 4; + lo = this.view[offset+1] << 16; + lo |= this.view[offset+2] << 8; + lo |= this.view[offset+3]; + lo += this.view[offset ] << 24 >>> 0; + } + var value = new Long(lo, hi, true); + if (relative) this.offset += 8; + return value; + }; + + /** + * Reads a 64bit unsigned integer. This is an alias of {@link ByteBuffer#readUint64}. + * @function + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!Long} + * @expose + */ + ByteBufferPrototype.readUInt64 = ByteBufferPrototype.readUint64; + + } // Long + + + // types/floats/float32 + + /* + ieee754 - https://github.com/feross/ieee754 + + The MIT License (MIT) + + Copyright (c) Feross Aboukhadijeh + + 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. + */ + + /** + * Reads an IEEE754 float from a byte array. + * @param {!Array} buffer + * @param {number} offset + * @param {boolean} isLE + * @param {number} mLen + * @param {number} nBytes + * @returns {number} + * @inner + */ + function ieee754_read(buffer, offset, isLE, mLen, nBytes) { + var e, m, + eLen = nBytes * 8 - mLen - 1, + eMax = (1 << eLen) - 1, + eBias = eMax >> 1, + nBits = -7, + i = isLE ? (nBytes - 1) : 0, + d = isLE ? -1 : 1, + s = buffer[offset + i]; + + i += d; + + e = s & ((1 << (-nBits)) - 1); + s >>= (-nBits); + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1); + e >>= (-nBits); + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity); + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); + } + + /** + * Writes an IEEE754 float to a byte array. + * @param {!Array} buffer + * @param {number} value + * @param {number} offset + * @param {boolean} isLE + * @param {number} mLen + * @param {number} nBytes + * @inner + */ + function ieee754_write(buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c, + eLen = nBytes * 8 - mLen - 1, + eMax = (1 << eLen) - 1, + eBias = eMax >> 1, + rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), + i = isLE ? 0 : (nBytes - 1), + d = isLE ? 1 : -1, + s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; + + value = Math.abs(value); + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; + } + + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128; + } + + /** + * Writes a 32bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeFloat32 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number') + throw TypeError("Illegal value: "+value+" (not a number)"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 4; + var capacity8 = this.buffer.byteLength; + if (offset > capacity8) + this.resize((capacity8 *= 2) > offset ? capacity8 : offset); + offset -= 4; + ieee754_write(this.view, value, offset, this.littleEndian, 23, 4); + if (relative) this.offset += 4; + return this; + }; + + /** + * Writes a 32bit 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 increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeFloat = ByteBufferPrototype.writeFloat32; + + /** + * Reads a 32bit float. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} + * @expose + */ + ByteBufferPrototype.readFloat32 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 4 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength); + } + var value = ieee754_read(this.view, offset, this.littleEndian, 23, 4); + if (relative) this.offset += 4; + return value; + }; + + /** + * Reads a 32bit float. This is an alias of {@link ByteBuffer#readFloat32}. + * @function + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. + * @returns {number} + * @expose + */ + ByteBufferPrototype.readFloat = ByteBufferPrototype.readFloat32; + + // types/floats/float64 + + /** + * Writes a 64bit float. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeFloat64 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number') + throw TypeError("Illegal value: "+value+" (not a number)"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + offset += 8; + var capacity9 = this.buffer.byteLength; + if (offset > capacity9) + this.resize((capacity9 *= 2) > offset ? capacity9 : offset); + offset -= 8; + ieee754_write(this.view, value, offset, this.littleEndian, 52, 8); + if (relative) this.offset += 8; + return this; + }; + + /** + * Writes a 64bit float. 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 increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64; + + /** + * Reads a 64bit float. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {number} + * @expose + */ + ByteBufferPrototype.readFloat64 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 8 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength); + } + var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8); + if (relative) this.offset += 8; + return value; + }; + + /** + * Reads a 64bit float. This is an alias of {@link ByteBuffer#readFloat64}. + * @function + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted. + * @returns {number} + * @expose + */ + ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64; + + + // types/varints/varint32 + + /** + * Maximum number of bytes required to store a 32bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT32_BYTES = 5; + + /** + * Calculates the actual number of bytes required to store 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 < 1 << 7 ) return 1; + else if (value < 1 << 14) return 2; + else if (value < 1 << 21) return 3; + else if (value < 1 << 28) return 4; + else return 5; + }; + + /** + * Zigzag 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) { + return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; // ref: src/google/protobuf/wire_format_lite.h + }; + + /** + * 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) { + return ((n >>> 1) ^ -(n & 1)) | 0; // // ref: src/google/protobuf/wire_format_lite.h + }; + + /** + * Writes a 32bit base 128 variable-length integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written + * @expose + */ + ByteBufferPrototype.writeVarint32 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value |= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + var size = ByteBuffer.calculateVarint32(value), + b; + offset += size; + var capacity10 = this.buffer.byteLength; + if (offset > capacity10) + this.resize((capacity10 *= 2) > offset ? capacity10 : offset); + offset -= size; + value >>>= 0; + while (value >= 0x80) { + b = (value & 0x7f) | 0x80; + this.view[offset++] = b; + value >>>= 7; + } + this.view[offset++] = value; + if (relative) { + this.offset = offset; + return this; + } + return size; + }; + + /** + * Writes a zig-zag encoded (signed) 32bit base 128 variable-length integer. + * @param {number} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written + * @expose + */ + ByteBufferPrototype.writeVarint32ZigZag = function(value, offset) { + return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset); + }; + + /** + * Reads a 32bit base 128 variable-length integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written 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. Has a property `truncated = true` if there is not enough data available + * to fully decode the varint. + * @expose + */ + ByteBufferPrototype.readVarint32 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + var c = 0, + value = 0 >>> 0, + b; + do { + if (!this.noAssert && offset > this.limit) { + var err = Error("Truncated"); + err['truncated'] = true; + throw err; + } + b = this.view[offset++]; + if (c < 5) + value |= (b & 0x7f) << (7*c); + ++c; + } while ((b & 0x80) !== 0); + value |= 0; + if (relative) { + this.offset = offset; + return value; + } + return { + "value": value, + "length": c + }; + }; + + /** + * Reads a zig-zag encoded (signed) 32bit base 128 variable-length integer. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written 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 + */ + ByteBufferPrototype.readVarint32ZigZag = function(offset) { + var val = this.readVarint32(offset); + if (typeof val === 'object') + val["value"] = ByteBuffer.zigZagDecode32(val["value"]); + else + val = ByteBuffer.zigZagDecode32(val); + return val; + }; + + // types/varints/varint64 + + if (Long) { + + /** + * Maximum number of bytes required to store a 64bit base 128 variable-length integer. + * @type {number} + * @const + * @expose + */ + ByteBuffer.MAX_VARINT64_BYTES = 10; + + /** + * Calculates the actual number of bytes required to store 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) { + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + // ref: src/google/protobuf/io/coded_stream.cc + 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 < 1 << 14) + return part0 < 1 << 7 ? 1 : 2; + else + return part0 < 1 << 21 ? 3 : 4; + } else { + if (part1 < 1 << 14) + return part1 < 1 << 7 ? 5 : 6; + else + return part1 < 1 << 21 ? 7 : 8; + } + } else + return part2 < 1 << 7 ? 9 : 10; + }; + + /** + * Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding. + * @param {number|!Long} value Signed long + * @returns {!Long} Unsigned zigzag encoded long + * @expose + */ + ByteBuffer.zigZagEncode64 = function(value) { + if (typeof value === 'number') + value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); + else if (value.unsigned !== false) value = value.toSigned(); + // ref: src/google/protobuf/wire_format_lite.h + return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned(); + }; + + /** + * Decodes a zigzag encoded signed 64bit integer. + * @param {!Long|number} value Unsigned zigzag encoded long or JavaScript number + * @returns {!Long} Signed long + * @expose + */ + ByteBuffer.zigZagDecode64 = function(value) { + if (typeof value === 'number') + value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); + else if (value.unsigned !== false) value = value.toSigned(); + // ref: src/google/protobuf/wire_format_lite.h + return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned(); + }; + + /** + * Writes a 64bit base 128 variable-length integer. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBufferPrototype.writeVarint64 = function(value, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof value === 'number') + value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); + else if (!(value && value instanceof Long)) + throw TypeError("Illegal value: "+value+" (not an integer or Long)"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + if (typeof value === 'number') + value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); + else if (value.unsigned !== false) value = value.toSigned(); + var size = ByteBuffer.calculateVarint64(value), + part0 = value.toInt() >>> 0, + part1 = value.shiftRightUnsigned(28).toInt() >>> 0, + part2 = value.shiftRightUnsigned(56).toInt() >>> 0; + offset += size; + var capacity11 = this.buffer.byteLength; + if (offset > capacity11) + this.resize((capacity11 *= 2) > offset ? capacity11 : offset); + offset -= size; + switch (size) { + case 10: this.view[offset+9] = (part2 >>> 7) & 0x01; + case 9 : this.view[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F; + case 8 : this.view[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F; + case 7 : this.view[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F; + case 6 : this.view[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F; + case 5 : this.view[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F; + case 4 : this.view[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F; + case 3 : this.view[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F; + case 2 : this.view[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F; + case 1 : this.view[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F; + } + if (relative) { + this.offset += size; + return this; + } else { + return size; + } + }; + + /** + * Writes a zig-zag encoded 64bit base 128 variable-length integer. + * @param {number|Long} value Value to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBufferPrototype.writeVarint64ZigZag = function(value, offset) { + return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset); + }; + + /** + * Reads a 64bit base 128 variable-length integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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 + */ + ByteBufferPrototype.readVarint64 = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + // ref: src/google/protobuf/io/coded_stream.cc + var start = offset, + part0 = 0, + part1 = 0, + part2 = 0, + b = 0; + b = this.view[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) { + b = this.view[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + b = this.view[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { + throw Error("Buffer overrun"); }}}}}}}}}} + var value = Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, false); + if (relative) { + this.offset = offset; + return value; + } else { + return { + 'value': value, + 'length': offset-start + }; + } + }; + + /** + * Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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 + */ + ByteBufferPrototype.readVarint64ZigZag = function(offset) { + var val = this.readVarint64(offset); + if (val && val['value'] instanceof Long) + val["value"] = ByteBuffer.zigZagDecode64(val["value"]); + else + val = ByteBuffer.zigZagDecode64(val); + return val; + }; + + } // Long + + + // types/strings/cstring + + /** + * Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL + * characters itself. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * contained in `str` + 1 if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written + * @expose + */ + ByteBufferPrototype.writeCString = function(str, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + var i, + k = str.length; + if (!this.noAssert) { + if (typeof str !== 'string') + throw TypeError("Illegal str: Not a string"); + for (i=0; i>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + // UTF8 strings do not contain zero bytes in between except for the zero character, so: + k = utfx.calculateUTF16asUTF8(stringSource(str))[1]; + offset += k+1; + var capacity12 = this.buffer.byteLength; + if (offset > capacity12) + this.resize((capacity12 *= 2) > offset ? capacity12 : offset); + offset -= k+1; + utfx.encodeUTF16toUTF8(stringSource(str), function(b) { + this.view[offset++] = b; + }.bind(this)); + this.view[offset++] = 0; + if (relative) { + this.offset = offset; + return this; + } + return k; + }; + + /** + * Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters + * itself. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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. + * @expose + */ + ByteBufferPrototype.readCString = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + var start = offset, + temp; + // UTF8 strings do not contain zero bytes in between except for the zero character itself, so: + var sd, b = -1; + utfx.decodeUTF8toUTF16(function() { + if (b === 0) return null; + if (offset >= this.limit) + throw RangeError("Illegal range: Truncated data, "+offset+" < "+this.limit); + b = this.view[offset++]; + return b === 0 ? null : b; + }.bind(this), sd = stringDestination(), true); + if (relative) { + this.offset = offset; + return sd(); + } else { + return { + "string": sd(), + "length": offset - start + }; + } + }; + + // types/strings/istring + + /** + * Writes a length as uint32 prefixed UTF8 encoded string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written + * @expose + * @see ByteBuffer#writeVarint32 + */ + ByteBufferPrototype.writeIString = function(str, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof str !== 'string') + throw TypeError("Illegal str: Not a string"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + var start = offset, + k; + k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1]; + offset += 4+k; + var capacity13 = this.buffer.byteLength; + if (offset > capacity13) + this.resize((capacity13 *= 2) > offset ? capacity13 : offset); + offset -= 4+k; + if (this.littleEndian) { + this.view[offset+3] = (k >>> 24) & 0xFF; + this.view[offset+2] = (k >>> 16) & 0xFF; + this.view[offset+1] = (k >>> 8) & 0xFF; + this.view[offset ] = k & 0xFF; + } else { + this.view[offset ] = (k >>> 24) & 0xFF; + this.view[offset+1] = (k >>> 16) & 0xFF; + this.view[offset+2] = (k >>> 8) & 0xFF; + this.view[offset+3] = k & 0xFF; + } + offset += 4; + utfx.encodeUTF16toUTF8(stringSource(str), function(b) { + this.view[offset++] = b; + }.bind(this)); + if (offset !== start + 4 + k) + throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+4+k)); + if (relative) { + this.offset = offset; + return this; + } + return offset - start; + }; + + /** + * Reads a length as uint32 prefixed UTF8 encoded string. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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. + * @expose + * @see ByteBuffer#readVarint32 + */ + ByteBufferPrototype.readIString = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 4 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength); + } + var start = offset; + var len = this.readUint32(offset); + var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4); + offset += str['length']; + if (relative) { + this.offset = offset; + return str['string']; + } else { + return { + 'string': str['string'], + 'length': offset - start + }; + } + }; + + // types/strings/utf8string + + /** + * Metrics representing number of UTF8 characters. Evaluates to `c`. + * @type {string} + * @const + * @expose + */ + ByteBuffer.METRICS_CHARS = 'c'; + + /** + * Metrics representing number of bytes. Evaluates to `b`. + * @type {string} + * @const + * @expose + */ + ByteBuffer.METRICS_BYTES = 'b'; + + /** + * Writes an UTF8 encoded string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBufferPrototype.writeUTF8String = function(str, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + var k; + var start = offset; + k = utfx.calculateUTF16asUTF8(stringSource(str))[1]; + offset += k; + var capacity14 = this.buffer.byteLength; + if (offset > capacity14) + this.resize((capacity14 *= 2) > offset ? capacity14 : offset); + offset -= k; + utfx.encodeUTF16toUTF8(stringSource(str), function(b) { + this.view[offset++] = b; + }.bind(this)); + if (relative) { + this.offset = offset; + return this; + } + return offset - start; + }; + + /** + * Writes an UTF8 encoded string. This is an alias of {@link ByteBuffer#writeUTF8String}. + * @function + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted. + * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written. + * @expose + */ + ByteBufferPrototype.writeString = ByteBufferPrototype.writeUTF8String; + + /** + * Calculates the number of UTF8 characters of a string. JavaScript itself uses UTF-16, so that a string's + * `length` property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF. + * @param {string} str String to calculate + * @returns {number} Number of UTF8 characters + * @expose + */ + ByteBuffer.calculateUTF8Chars = function(str) { + return utfx.calculateUTF16asUTF8(stringSource(str))[0]; + }; + + /** + * Calculates the number of UTF8 bytes of a string. + * @param {string} str String to calculate + * @returns {number} Number of UTF8 bytes + * @expose + */ + ByteBuffer.calculateUTF8Bytes = function(str) { + return utfx.calculateUTF16asUTF8(stringSource(str))[1]; + }; + + /** + * Calculates the number of UTF8 bytes of a string. This is an alias of {@link ByteBuffer.calculateUTF8Bytes}. + * @function + * @param {string} str String to calculate + * @returns {number} Number of UTF8 bytes + * @expose + */ + ByteBuffer.calculateString = ByteBuffer.calculateUTF8Bytes; + + /** + * Reads an UTF8 encoded string. + * @param {number} length Number of characters or bytes to read. + * @param {string=} metrics Metrics specifying what `length` is meant to count. Defaults to + * {@link ByteBuffer.METRICS_CHARS}. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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. + * @expose + */ + ByteBufferPrototype.readUTF8String = function(length, metrics, offset) { + if (typeof metrics === 'number') { + offset = metrics; + metrics = undefined; + } + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS; + if (!this.noAssert) { + if (typeof length !== 'number' || length % 1 !== 0) + throw TypeError("Illegal length: "+length+" (not an integer)"); + length |= 0; + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + var i = 0, + start = offset, + sd; + if (metrics === ByteBuffer.METRICS_CHARS) { // The same for node and the browser + sd = stringDestination(); + utfx.decodeUTF8(function() { + return i < length && offset < this.limit ? this.view[offset++] : null; + }.bind(this), function(cp) { + ++i; utfx.UTF8toUTF16(cp, sd); + }); + if (i !== length) + throw RangeError("Illegal range: Truncated data, "+i+" == "+length); + if (relative) { + this.offset = offset; + return sd(); + } else { + return { + "string": sd(), + "length": offset - start + }; + } + } else if (metrics === ByteBuffer.METRICS_BYTES) { + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + length > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength); + } + var k = offset + length; + utfx.decodeUTF8toUTF16(function() { + return offset < k ? this.view[offset++] : null; + }.bind(this), sd = stringDestination(), this.noAssert); + if (offset !== k) + throw RangeError("Illegal range: Truncated data, "+offset+" == "+k); + if (relative) { + this.offset = offset; + return sd(); + } else { + return { + 'string': sd(), + 'length': offset - start + }; + } + } else + throw TypeError("Unsupported metrics: "+metrics); + }; + + /** + * Reads an UTF8 encoded string. This is an alias of {@link ByteBuffer#readUTF8String}. + * @function + * @param {number} length Number of characters or bytes to read + * @param {number=} metrics Metrics specifying what `n` is meant to count. Defaults to + * {@link ByteBuffer.METRICS_CHARS}. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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. + * @expose + */ + ByteBufferPrototype.readString = ByteBufferPrototype.readUTF8String; + + // types/strings/vstring + + /** + * Writes a length as varint32 prefixed UTF8 encoded string. + * @param {string} str String to write + * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written + * @expose + * @see ByteBuffer#writeVarint32 + */ + ByteBufferPrototype.writeVString = function(str, offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof str !== 'string') + throw TypeError("Illegal str: Not a string"); + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + var start = offset, + k, l; + k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1]; + l = ByteBuffer.calculateVarint32(k); + offset += l+k; + var capacity15 = this.buffer.byteLength; + if (offset > capacity15) + this.resize((capacity15 *= 2) > offset ? capacity15 : offset); + offset -= l+k; + offset += this.writeVarint32(k, offset); + utfx.encodeUTF16toUTF8(stringSource(str), function(b) { + this.view[offset++] = b; + }.bind(this)); + if (offset !== start+k+l) + throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+k+l)); + if (relative) { + this.offset = offset; + return this; + } + return offset - start; + }; + + /** + * Reads a length as varint32 prefixed UTF8 encoded string. + * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read 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. + * @expose + * @see ByteBuffer#readVarint32 + */ + ByteBufferPrototype.readVString = function(offset) { + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 1 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength); + } + var start = offset; + var len = this.readVarint32(offset); + var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']); + offset += str['length']; + if (relative) { + this.offset = offset; + return str['string']; + } else { + return { + 'string': str['string'], + 'length': offset - start + }; + } + }; + + + /** + * Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended + * data's length. + * @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to append. If `source` is a ByteBuffer, its offsets + * will be modified according to the performed read operation. + * @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8") + * @param {number=} offset Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. + * @returns {!ByteBuffer} this + * @expose + * @example A relative `<01 02>03.append(<04 05>)` will result in `<01 02 04 05>, 04 05|` + * @example An absolute `<01 02>03.append(04 05>, 1)` will result in `<01 04>05, 04 05|` + */ + ByteBufferPrototype.append = function(source, encoding, offset) { + if (typeof encoding === 'number' || typeof encoding !== 'string') { + offset = encoding; + encoding = undefined; + } + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + if (!(source instanceof ByteBuffer)) + source = ByteBuffer.wrap(source, encoding); + var length = source.limit - source.offset; + if (length <= 0) return this; // Nothing to append + offset += length; + var capacity16 = this.buffer.byteLength; + if (offset > capacity16) + this.resize((capacity16 *= 2) > offset ? capacity16 : offset); + offset -= length; + this.view.set(source.view.subarray(source.offset, source.limit), offset); + source.offset += length; + if (relative) this.offset += length; + return this; + }; + + /** + * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the + specified offset up to the length of this ByteBuffer's data. + * @param {!ByteBuffer} target Target ByteBuffer + * @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * read if omitted. + * @returns {!ByteBuffer} this + * @expose + * @see ByteBuffer#append + */ + ByteBufferPrototype.appendTo = function(target, offset) { + target.append(this, offset); + return this; + }; + + /** + * Enables or disables assertions of argument types and offsets. Assertions are enabled by default but you can opt to + * disable them if your code already makes sure that everything is valid. + * @param {boolean} assert `true` to enable assertions, otherwise `false` + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.assert = function(assert) { + this.noAssert = !assert; + return this; + }; + + /** + * Gets the capacity of this ByteBuffer's backing buffer. + * @returns {number} Capacity of the backing buffer + * @expose + */ + ByteBufferPrototype.capacity = function() { + return this.buffer.byteLength; + }; + /** + * Clears this ByteBuffer's offsets by setting {@link ByteBuffer#offset} to `0` and {@link ByteBuffer#limit} to the + * backing buffer's capacity. Discards {@link ByteBuffer#markedOffset}. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.clear = function() { + this.offset = 0; + this.limit = this.buffer.byteLength; + this.markedOffset = -1; + return this; + }; + + /** + * Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for {@link ByteBuffer#offset}, + * {@link ByteBuffer#markedOffset} and {@link ByteBuffer#limit}. + * @param {boolean=} copy Whether to copy the backing buffer or to return another view on the same, defaults to `false` + * @returns {!ByteBuffer} Cloned instance + * @expose + */ + ByteBufferPrototype.clone = function(copy) { + var bb = new ByteBuffer(0, this.littleEndian, this.noAssert); + if (copy) { + bb.buffer = new ArrayBuffer(this.buffer.byteLength); + bb.view = new Uint8Array(bb.buffer); + } else { + bb.buffer = this.buffer; + bb.view = this.view; + } + bb.offset = this.offset; + bb.markedOffset = this.markedOffset; + bb.limit = this.limit; + return bb; + }; + + /** + * Compacts this ByteBuffer to be backed by a {@link ByteBuffer#buffer} of its contents' length. Contents are the bytes + * between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will set `offset = 0` and `limit = capacity` and + * adapt {@link ByteBuffer#markedOffset} to the same relative position if set. + * @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset} + * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit} + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.compact = function(begin, end) { + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + if (begin === 0 && end === this.buffer.byteLength) + return this; // Already compacted + var len = end - begin; + if (len === 0) { + this.buffer = EMPTY_BUFFER; + this.view = null; + if (this.markedOffset >= 0) this.markedOffset -= begin; + this.offset = 0; + this.limit = 0; + return this; + } + var buffer = new ArrayBuffer(len); + var view = new Uint8Array(buffer); + view.set(this.view.subarray(begin, end)); + this.buffer = buffer; + this.view = view; + if (this.markedOffset >= 0) this.markedOffset -= begin; + this.offset = 0; + this.limit = len; + return this; + }; + + /** + * Creates a copy of this ByteBuffer's contents. Contents are the bytes between {@link ByteBuffer#offset} and + * {@link ByteBuffer#limit}. + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}. + * @returns {!ByteBuffer} Copy + * @expose + */ + ByteBufferPrototype.copy = function(begin, end) { + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + if (begin === end) + return new ByteBuffer(0, this.littleEndian, this.noAssert); + var capacity = end - begin, + bb = new ByteBuffer(capacity, this.littleEndian, this.noAssert); + bb.offset = 0; + bb.limit = capacity; + if (bb.markedOffset >= 0) bb.markedOffset -= begin; + this.copyTo(bb, 0, begin, end); + return bb; + }; + + /** + * Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between {@link ByteBuffer#offset} and + * {@link ByteBuffer#limit}. + * @param {!ByteBuffer} target Target ByteBuffer + * @param {number=} targetOffset Offset to copy to. Will use and increase the target's {@link ByteBuffer#offset} + * by the number of bytes copied if omitted. + * @param {number=} sourceOffset Offset to start copying from. Will use and increase {@link ByteBuffer#offset} by the + * number of bytes copied if omitted. + * @param {number=} sourceLimit Offset to end copying from, defaults to {@link ByteBuffer#limit} + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.copyTo = function(target, targetOffset, sourceOffset, sourceLimit) { + var relative, + targetRelative; + if (!this.noAssert) { + if (!ByteBuffer.isByteBuffer(target)) + throw TypeError("Illegal target: Not a ByteBuffer"); + } + targetOffset = (targetRelative = typeof targetOffset === 'undefined') ? target.offset : targetOffset | 0; + sourceOffset = (relative = typeof sourceOffset === 'undefined') ? this.offset : sourceOffset | 0; + sourceLimit = typeof sourceLimit === 'undefined' ? this.limit : sourceLimit | 0; + + if (targetOffset < 0 || targetOffset > target.buffer.byteLength) + throw RangeError("Illegal target range: 0 <= "+targetOffset+" <= "+target.buffer.byteLength); + if (sourceOffset < 0 || sourceLimit > this.buffer.byteLength) + throw RangeError("Illegal source range: 0 <= "+sourceOffset+" <= "+this.buffer.byteLength); + + var len = sourceLimit - sourceOffset; + if (len === 0) + return target; // Nothing to copy + + target.ensureCapacity(targetOffset + len); + + target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset); + + if (relative) this.offset += len; + if (targetRelative) target.offset += len; + + return this; + }; + + /** + * Makes sure that this ByteBuffer is backed by a {@link ByteBuffer#buffer} of at least the specified capacity. If the + * current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity, + * the required capacity will be used instead. + * @param {number} capacity Required capacity + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.ensureCapacity = function(capacity) { + var current = this.buffer.byteLength; + if (current < capacity) + return this.resize((current *= 2) > capacity ? current : capacity); + return this; + }; + + /** + * Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between + * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. + * @param {number|string} value Byte value to fill with. If given as a string, the first character is used. + * @param {number=} begin Begin offset. Will use and increase {@link ByteBuffer#offset} by the number of bytes + * written if omitted. defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}. + * @returns {!ByteBuffer} this + * @expose + * @example `someByteBuffer.clear().fill(0)` fills the entire backing buffer with zeroes + */ + ByteBufferPrototype.fill = function(value, begin, end) { + var relative = typeof begin === 'undefined'; + if (relative) begin = this.offset; + if (typeof value === 'string' && value.length > 0) + value = value.charCodeAt(0); + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof value !== 'number' || value % 1 !== 0) + throw TypeError("Illegal value: "+value+" (not an integer)"); + value |= 0; + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + if (begin >= end) + return this; // Nothing to fill + while (begin < end) this.view[begin++] = value; + if (relative) this.offset = begin; + return this; + }; + + /** + * Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets `limit = offset` and + * `offset = 0`. Make sure always to flip a ByteBuffer when all relative read or write operations are complete. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.flip = function() { + this.limit = this.offset; + this.offset = 0; + return this; + }; + /** + * Marks an offset on this ByteBuffer to be used later. + * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}. + * @returns {!ByteBuffer} this + * @throws {TypeError} If `offset` is not a valid number + * @throws {RangeError} If `offset` is out of bounds + * @see ByteBuffer#reset + * @expose + */ + ByteBufferPrototype.mark = function(offset) { + offset = typeof offset === 'undefined' ? this.offset : offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + this.markedOffset = offset; + return this; + }; + /** + * Sets the byte order. + * @param {boolean} littleEndian `true` for little endian byte order, `false` for big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.order = function(littleEndian) { + if (!this.noAssert) { + if (typeof littleEndian !== 'boolean') + throw TypeError("Illegal littleEndian: Not a boolean"); + } + this.littleEndian = !!littleEndian; + return this; + }; + + /** + * Switches (to) little endian byte order. + * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.LE = function(littleEndian) { + this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true; + return this; + }; + + /** + * Switches (to) big endian byte order. + * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.BE = function(bigEndian) { + this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false; + return this; + }; + /** + * Prepends some data to this ByteBuffer. This will overwrite any contents before the specified offset up to the + * prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer + * will be resized and its contents moved accordingly. + * @param {!ByteBuffer|string|!ArrayBuffer} source Data to prepend. If `source` is a ByteBuffer, its offset will be + * modified according to the performed read operation. + * @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8") + * @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes + * prepended if omitted. + * @returns {!ByteBuffer} this + * @expose + * @example A relative `00<01 02 03>.prepend(<04 05>)` results in `<04 05 01 02 03>, 04 05|` + * @example An absolute `00<01 02 03>.prepend(<04 05>, 2)` results in `04<05 02 03>, 04 05|` + */ + ByteBufferPrototype.prepend = function(source, encoding, offset) { + if (typeof encoding === 'number' || typeof encoding !== 'string') { + offset = encoding; + encoding = undefined; + } + var relative = typeof offset === 'undefined'; + if (relative) offset = this.offset; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: "+offset+" (not an integer)"); + offset >>>= 0; + if (offset < 0 || offset + 0 > this.buffer.byteLength) + throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); + } + if (!(source instanceof ByteBuffer)) + source = ByteBuffer.wrap(source, encoding); + var len = source.limit - source.offset; + if (len <= 0) return this; // Nothing to prepend + var diff = len - offset; + if (diff > 0) { // Not enough space before offset, so resize + move + var buffer = new ArrayBuffer(this.buffer.byteLength + diff); + var view = new Uint8Array(buffer); + view.set(this.view.subarray(offset, this.buffer.byteLength), len); + this.buffer = buffer; + this.view = view; + this.offset += diff; + if (this.markedOffset >= 0) this.markedOffset += diff; + this.limit += diff; + offset += diff; + } else { + var arrayView = new Uint8Array(this.buffer); + } + this.view.set(source.view.subarray(source.offset, source.limit), offset - len); + + source.offset = source.limit; + if (relative) + this.offset -= len; + return this; + }; + + /** + * Prepends this ByteBuffer to another ByteBuffer. This will overwrite any contents before the specified offset up to the + * prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer + * will be resized and its contents moved accordingly. + * @param {!ByteBuffer} target Target ByteBuffer + * @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes + * prepended if omitted. + * @returns {!ByteBuffer} this + * @expose + * @see ByteBuffer#prepend + */ + ByteBufferPrototype.prependTo = function(target, offset) { + target.prepend(this, offset); + return this; + }; + /** + * Prints debug information about this ByteBuffer's contents. + * @param {function(string)=} out Output function to call, defaults to console.log + * @expose + */ + ByteBufferPrototype.printDebug = function(out) { + if (typeof out !== 'function') out = console.log.bind(console); + out( + this.toString()+"\n"+ + "-------------------------------------------------------------------\n"+ + this.toDebug(/* columns */ true) + ); + }; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between {@link ByteBuffer#offset} and + * {@link ByteBuffer#limit}, so this returns `limit - offset`. + * @returns {number} Remaining readable bytes. May be negative if `offset > limit`. + * @expose + */ + ByteBufferPrototype.remaining = function() { + return this.limit - this.offset; + }; + /** + * Resets this ByteBuffer's {@link ByteBuffer#offset}. If an offset has been marked through {@link ByteBuffer#mark} + * before, `offset` will be set to {@link ByteBuffer#markedOffset}, which will then be discarded. If no offset has been + * marked, sets `offset = 0`. + * @returns {!ByteBuffer} this + * @see ByteBuffer#mark + * @expose + */ + ByteBufferPrototype.reset = function() { + if (this.markedOffset >= 0) { + this.offset = this.markedOffset; + this.markedOffset = -1; + } else { + this.offset = 0; + } + return this; + }; + /** + * Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that + * large or larger. + * @param {number} capacity Capacity required + * @returns {!ByteBuffer} this + * @throws {TypeError} If `capacity` is not a number + * @throws {RangeError} If `capacity < 0` + * @expose + */ + ByteBufferPrototype.resize = function(capacity) { + if (!this.noAssert) { + if (typeof capacity !== 'number' || capacity % 1 !== 0) + throw TypeError("Illegal capacity: "+capacity+" (not an integer)"); + capacity |= 0; + if (capacity < 0) + throw RangeError("Illegal capacity: 0 <= "+capacity); + } + if (this.buffer.byteLength < capacity) { + var buffer = new ArrayBuffer(capacity); + var view = new Uint8Array(buffer); + view.set(this.view); + this.buffer = buffer; + this.view = view; + } + return this; + }; + /** + * Reverses this ByteBuffer's contents. + * @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset} + * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit} + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.reverse = function(begin, end) { + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + if (begin === end) + return this; // Nothing to reverse + Array.prototype.reverse.call(this.view.subarray(begin, end)); + return this; + }; + /** + * Skips the next `length` bytes. This will just advance + * @param {number} length Number of bytes to skip. May also be negative to move the offset back. + * @returns {!ByteBuffer} this + * @expose + */ + ByteBufferPrototype.skip = function(length) { + if (!this.noAssert) { + if (typeof length !== 'number' || length % 1 !== 0) + throw TypeError("Illegal length: "+length+" (not an integer)"); + length |= 0; + } + var offset = this.offset + length; + if (!this.noAssert) { + if (offset < 0 || offset > this.buffer.byteLength) + throw RangeError("Illegal length: 0 <= "+this.offset+" + "+length+" <= "+this.buffer.byteLength); + } + this.offset = offset; + return this; + }; + + /** + * Slices this ByteBuffer by creating a cloned instance with `offset = begin` and `limit = end`. + * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}. + * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}. + * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same {@link ByteBuffer#buffer} + * @expose + */ + ByteBufferPrototype.slice = function(begin, end) { + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + var bb = this.clone(); + bb.offset = begin; + bb.limit = end; + return bb; + }; + /** + * Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between + * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. + * @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory if + * possible. Defaults to `false` + * @returns {!ArrayBuffer} Contents as an ArrayBuffer + * @expose + */ + ByteBufferPrototype.toBuffer = function(forceCopy) { + var offset = this.offset, + limit = this.limit; + if (!this.noAssert) { + if (typeof offset !== 'number' || offset % 1 !== 0) + throw TypeError("Illegal offset: Not an integer"); + offset >>>= 0; + if (typeof limit !== 'number' || limit % 1 !== 0) + throw TypeError("Illegal limit: Not an integer"); + limit >>>= 0; + if (offset < 0 || offset > limit || limit > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+offset+" <= "+limit+" <= "+this.buffer.byteLength); + } + // NOTE: It's not possible to have another ArrayBuffer reference the same memory as the backing buffer. This is + // possible with Uint8Array#subarray only, but we have to return an ArrayBuffer by contract. So: + if (!forceCopy && offset === 0 && limit === this.buffer.byteLength) + return this.buffer; + if (offset === limit) + return EMPTY_BUFFER; + var buffer = new ArrayBuffer(limit - offset); + new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0); + return buffer; + }; + + /** + * Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between + * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. This is an alias of {@link ByteBuffer#toBuffer}. + * @function + * @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory. + * Defaults to `false` + * @returns {!ArrayBuffer} Contents as an ArrayBuffer + * @expose + */ + ByteBufferPrototype.toArrayBuffer = ByteBufferPrototype.toBuffer; + + /** + * Converts the ByteBuffer's contents to a string. + * @param {string=} encoding Output encoding. Returns an informative string representation if omitted but also allows + * direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with + * highlighted offsets. + * @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset} + * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit} + * @returns {string} String representation + * @throws {Error} If `encoding` is invalid + * @expose + */ + ByteBufferPrototype.toString = function(encoding, begin, end) { + if (typeof encoding === 'undefined') + return "ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")"; + if (typeof encoding === 'number') + encoding = "utf8", + begin = encoding, + end = begin; + switch (encoding) { + case "utf8": + return this.toUTF8(begin, end); + case "base64": + return this.toBase64(begin, end); + case "hex": + return this.toHex(begin, end); + case "binary": + return this.toBinary(begin, end); + case "debug": + return this.toDebug(); + case "columns": + return this.toColumns(); + default: + throw Error("Unsupported encoding: "+encoding); + } + }; + + // lxiv-embeddable + + /** + * lxiv-embeddable (c) 2014 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/lxiv for details + */ + var lxiv = function() { + "use strict"; + + /** + * lxiv namespace. + * @type {!Object.} + * @exports lxiv + */ + var lxiv = {}; + + /** + * Character codes for output. + * @type {!Array.} + * @inner + */ + var aout = [ + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, + 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47 + ]; + + /** + * Character codes for input. + * @type {!Array.} + * @inner + */ + var ain = []; + for (var i=0, k=aout.length; i>2)&0x3f]); + t = (b&0x3)<<4; + if ((b = src()) !== null) { + t |= (b>>4)&0xf; + dst(aout[(t|((b>>4)&0xf))&0x3f]); + t = (b&0xf)<<2; + if ((b = src()) !== null) + dst(aout[(t|((b>>6)&0x3))&0x3f]), + dst(aout[b&0x3f]); + else + dst(aout[t&0x3f]), + dst(61); + } else + dst(aout[t&0x3f]), + dst(61), + dst(61); + } + }; + + /** + * Decodes base64 char codes to bytes. + * @param {!function():number|null} src Characters source as a function returning the next char code respectively + * `null` if there are no more characters left. + * @param {!function(number)} dst Bytes destination as a function successively called with the next byte. + * @throws {Error} If a character code is invalid + */ + lxiv.decode = function(src, dst) { + var c, t1, t2; + function fail(c) { + throw Error("Illegal character code: "+c); + } + while ((c = src()) !== null) { + t1 = ain[c]; + if (typeof t1 === 'undefined') fail(c); + if ((c = src()) !== null) { + t2 = ain[c]; + if (typeof t2 === 'undefined') fail(c); + dst((t1<<2)>>>0|(t2&0x30)>>4); + if ((c = src()) !== null) { + t1 = ain[c]; + if (typeof t1 === 'undefined') + if (c === 61) break; else fail(c); + dst(((t2&0xf)<<4)>>>0|(t1&0x3c)>>2); + if ((c = src()) !== null) { + t2 = ain[c]; + if (typeof t2 === 'undefined') + if (c === 61) break; else fail(c); + dst(((t1&0x3)<<6)>>>0|t2); + } + } + } + } + }; + + /** + * Tests if a string is valid base64. + * @param {string} str String to test + * @returns {boolean} `true` if valid, otherwise `false` + */ + lxiv.test = function(str) { + return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str); + }; + + return lxiv; + }(); + + // encodings/base64 + + /** + * Encodes this ByteBuffer's contents to a base64 encoded string. + * @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}. + * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}. + * @returns {string} Base64 encoded string + * @throws {RangeError} If `begin` or `end` is out of bounds + * @expose + */ + ByteBufferPrototype.toBase64 = function(begin, end) { + if (typeof begin === 'undefined') + begin = this.offset; + if (typeof end === 'undefined') + end = this.limit; + begin = begin | 0; end = end | 0; + if (begin < 0 || end > this.capacity || begin > end) + throw RangeError("begin, end"); + var sd; lxiv.encode(function() { + return begin < end ? this.view[begin++] : null; + }.bind(this), sd = stringDestination()); + return sd(); + }; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + * @param {string} str String to decode + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @returns {!ByteBuffer} ByteBuffer + * @expose + */ + ByteBuffer.fromBase64 = function(str, littleEndian) { + if (typeof str !== 'string') + throw TypeError("str"); + var bb = new ByteBuffer(str.length/4*3, littleEndian), + i = 0; + lxiv.decode(stringSource(str), function(b) { + bb.view[i++] = b; + }); + bb.limit = i; + return bb; + }; + + /** + * Encodes a binary string to base64 like `window.btoa` does. + * @param {string} str Binary string + * @returns {string} Base64 encoded string + * @see https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa + * @expose + */ + ByteBuffer.btoa = function(str) { + return ByteBuffer.fromBinary(str).toBase64(); + }; + + /** + * Decodes a base64 encoded string to binary like `window.atob` does. + * @param {string} b64 Base64 encoded string + * @returns {string} Binary string + * @see https://developer.mozilla.org/en-US/docs/Web/API/Window.atob + * @expose + */ + ByteBuffer.atob = function(b64) { + return ByteBuffer.fromBase64(b64).toBinary(); + }; + + // encodings/binary + + /** + * Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes. + * @param {number=} begin Offset to begin at. Defaults to {@link ByteBuffer#offset}. + * @param {number=} end Offset to end at. Defaults to {@link ByteBuffer#limit}. + * @returns {string} Binary encoded string + * @throws {RangeError} If `offset > limit` + * @expose + */ + ByteBufferPrototype.toBinary = function(begin, end) { + if (typeof begin === 'undefined') + begin = this.offset; + if (typeof end === 'undefined') + end = this.limit; + begin |= 0; end |= 0; + if (begin < 0 || end > this.capacity() || begin > end) + throw RangeError("begin, end"); + if (begin === end) + return ""; + var chars = [], + parts = []; + while (begin < end) { + chars.push(this.view[begin++]); + if (chars.length >= 1024) + parts.push(String.fromCharCode.apply(String, chars)), + chars = []; + } + return parts.join('') + String.fromCharCode.apply(String, chars); + }; + + /** + * Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer. + * @param {string} str String to decode + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @returns {!ByteBuffer} ByteBuffer + * @expose + */ + ByteBuffer.fromBinary = function(str, littleEndian) { + if (typeof str !== 'string') + throw TypeError("str"); + var i = 0, + k = str.length, + charCode, + bb = new ByteBuffer(k, littleEndian); + while (i 0xff) + throw RangeError("illegal char code: "+charCode); + bb.view[i++] = charCode; + } + bb.limit = k; + return bb; + }; + + // encodings/debug + + /** + * Encodes this ByteBuffer to a hex encoded string with marked offsets. Offset symbols are: + * * `<` : offset, + * * `'` : markedOffset, + * * `>` : limit, + * * `|` : offset and limit, + * * `[` : offset and markedOffset, + * * `]` : markedOffset and limit, + * * `!` : offset, markedOffset and limit + * @param {boolean=} columns If `true` returns two columns hex + ascii, defaults to `false` + * @returns {string|!Array.} Debug string or array of lines if `asArray = true` + * @expose + * @example `>00'01 02<03` contains four bytes with `limit=0, markedOffset=1, offset=3` + * @example `00[01 02 03>` contains four bytes with `offset=markedOffset=1, limit=4` + * @example `00|01 02 03` contains four bytes with `offset=limit=1, markedOffset=-1` + * @example `|` contains zero bytes with `offset=limit=0, markedOffset=-1` + */ + ByteBufferPrototype.toDebug = function(columns) { + var i = -1, + k = this.buffer.byteLength, + b, + hex = "", + asc = "", + out = ""; + while (i 32 && b < 127 ? String.fromCharCode(b) : '.'; + } + ++i; + if (columns) { + if (i > 0 && i % 16 === 0 && i !== k) { + while (hex.length < 3*16+3) hex += " "; + out += hex+asc+"\n"; + hex = asc = ""; + } + } + if (i === this.offset && i === this.limit) + hex += i === this.markedOffset ? "!" : "|"; + else if (i === this.offset) + hex += i === this.markedOffset ? "[" : "<"; + else if (i === this.limit) + hex += i === this.markedOffset ? "]" : ">"; + else + hex += i === this.markedOffset ? "'" : (columns || (i !== 0 && i !== k) ? " " : ""); + } + if (columns && hex !== " ") { + while (hex.length < 3*16+3) + hex += " "; + out += hex + asc + "\n"; + } + return columns ? out : hex; + }; + + /** + * Decodes a hex encoded string with marked offsets to a ByteBuffer. + * @param {string} str Debug string to decode (not be generated with `columns = true`) + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} ByteBuffer + * @expose + * @see ByteBuffer#toDebug + */ + ByteBuffer.fromDebug = function(str, littleEndian, noAssert) { + var k = str.length, + bb = new ByteBuffer(((k+1)/3)|0, littleEndian, noAssert); + var i = 0, j = 0, ch, b, + rs = false, // Require symbol next + ho = false, hm = false, hl = false, // Already has offset (ho), markedOffset (hm), limit (hl)? + fail = false; + while (i': + if (!noAssert) { + if (hl) { + fail = true; + break; + } + hl = true; + } + bb.limit = j; + rs = false; + break; + case "'": + if (!noAssert) { + if (hm) { + fail = true; + break; + } + hm = true; + } + bb.markedOffset = j; + rs = false; + break; + case ' ': + rs = false; + break; + default: + if (!noAssert) { + if (rs) { + fail = true; + break; + } + } + b = parseInt(ch+str.charAt(i++), 16); + if (!noAssert) { + if (isNaN(b) || b < 0 || b > 255) + throw TypeError("Illegal str: Not a debug encoded string"); + } + bb.view[j++] = b; + rs = true; + } + if (fail) + throw TypeError("Illegal str: Invalid symbol at "+i); + } + if (!noAssert) { + if (!ho || !hl) + throw TypeError("Illegal str: Missing offset or limit"); + if (j>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + var out = new Array(end - begin), + b; + while (begin < end) { + b = this.view[begin++]; + if (b < 0x10) + out.push("0", b.toString(16)); + else out.push(b.toString(16)); + } + return out.join(''); + }; + + /** + * Decodes a hex encoded string to a ByteBuffer. + * @param {string} str String to decode + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} ByteBuffer + * @expose + */ + ByteBuffer.fromHex = function(str, littleEndian, noAssert) { + if (!noAssert) { + if (typeof str !== 'string') + throw TypeError("Illegal str: Not a string"); + if (str.length % 2 !== 0) + throw TypeError("Illegal str: Length not a multiple of 2"); + } + var k = str.length, + bb = new ByteBuffer((k / 2) | 0, littleEndian), + b; + for (var i=0, j=0; i 255) + throw TypeError("Illegal str: Contains non-hex characters"); + bb.view[j++] = b; + } + bb.limit = j; + return bb; + }; + + // utfx-embeddable + + /** + * utfx-embeddable (c) 2014 Daniel Wirtz + * Released under the Apache License, Version 2.0 + * see: https://github.com/dcodeIO/utfx for details + */ + var utfx = function() { + "use strict"; + + /** + * utfx namespace. + * @inner + * @type {!Object.} + */ + var utfx = {}; + + /** + * Maximum valid code point. + * @type {number} + * @const + */ + utfx.MAX_CODEPOINT = 0x10FFFF; + + /** + * Encodes UTF8 code points to UTF8 bytes. + * @param {(!function():number|null) | number} src Code points source, either as a function returning the next code point + * respectively `null` if there are no more code points left or a single numeric code point. + * @param {!function(number)} dst Bytes destination as a function successively called with the next byte + */ + utfx.encodeUTF8 = function(src, dst) { + var cp = null; + if (typeof src === 'number') + cp = src, + src = function() { return null; }; + while (cp !== null || (cp = src()) !== null) { + if (cp < 0x80) + dst(cp&0x7F); + else if (cp < 0x800) + dst(((cp>>6)&0x1F)|0xC0), + dst((cp&0x3F)|0x80); + else if (cp < 0x10000) + dst(((cp>>12)&0x0F)|0xE0), + dst(((cp>>6)&0x3F)|0x80), + dst((cp&0x3F)|0x80); + else + dst(((cp>>18)&0x07)|0xF0), + dst(((cp>>12)&0x3F)|0x80), + dst(((cp>>6)&0x3F)|0x80), + dst((cp&0x3F)|0x80); + cp = null; + } + }; + + /** + * Decodes UTF8 bytes to UTF8 code points. + * @param {!function():number|null} src Bytes source as a function returning the next byte respectively `null` if there + * are no more bytes left. + * @param {!function(number)} dst Code points destination as a function successively called with each decoded code point. + * @throws {RangeError} If a starting byte is invalid in UTF8 + * @throws {Error} If the last sequence is truncated. Has an array property `bytes` holding the + * remaining bytes. + */ + utfx.decodeUTF8 = function(src, dst) { + var a, b, c, d, fail = function(b) { + b = b.slice(0, b.indexOf(null)); + var err = Error(b.toString()); + err.name = "TruncatedError"; + err['bytes'] = b; + throw err; + }; + while ((a = src()) !== null) { + if ((a&0x80) === 0) + dst(a); + else if ((a&0xE0) === 0xC0) + ((b = src()) === null) && fail([a, b]), + dst(((a&0x1F)<<6) | (b&0x3F)); + else if ((a&0xF0) === 0xE0) + ((b=src()) === null || (c=src()) === null) && fail([a, b, c]), + dst(((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F)); + else if ((a&0xF8) === 0xF0) + ((b=src()) === null || (c=src()) === null || (d=src()) === null) && fail([a, b, c ,d]), + dst(((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F)); + else throw RangeError("Illegal starting byte: "+a); + } + }; + + /** + * Converts UTF16 characters to UTF8 code points. + * @param {!function():number|null} src Characters source as a function returning the next char code respectively + * `null` if there are no more characters left. + * @param {!function(number)} dst Code points destination as a function successively called with each converted code + * point. + */ + utfx.UTF16toUTF8 = function(src, dst) { + var c1, c2 = null; + while (true) { + if ((c1 = c2 !== null ? c2 : src()) === null) + break; + if (c1 >= 0xD800 && c1 <= 0xDFFF) { + if ((c2 = src()) !== null) { + if (c2 >= 0xDC00 && c2 <= 0xDFFF) { + dst((c1-0xD800)*0x400+c2-0xDC00+0x10000); + c2 = null; continue; + } + } + } + dst(c1); + } + if (c2 !== null) dst(c2); + }; + + /** + * Converts UTF8 code points to UTF16 characters. + * @param {(!function():number|null) | number} src Code points source, either as a function returning the next code point + * respectively `null` if there are no more code points left or a single numeric code point. + * @param {!function(number)} dst Characters destination as a function successively called with each converted char code. + * @throws {RangeError} If a code point is out of range + */ + utfx.UTF8toUTF16 = function(src, dst) { + var cp = null; + if (typeof src === 'number') + cp = src, src = function() { return null; }; + while (cp !== null || (cp = src()) !== null) { + if (cp <= 0xFFFF) + dst(cp); + else + cp -= 0x10000, + dst((cp>>10)+0xD800), + dst((cp%0x400)+0xDC00); + cp = null; + } + }; + + /** + * Converts and encodes UTF16 characters to UTF8 bytes. + * @param {!function():number|null} src Characters source as a function returning the next char code respectively `null` + * if there are no more characters left. + * @param {!function(number)} dst Bytes destination as a function successively called with the next byte. + */ + utfx.encodeUTF16toUTF8 = function(src, dst) { + utfx.UTF16toUTF8(src, function(cp) { + utfx.encodeUTF8(cp, dst); + }); + }; + + /** + * Decodes and converts UTF8 bytes to UTF16 characters. + * @param {!function():number|null} src Bytes source as a function returning the next byte respectively `null` if there + * are no more bytes left. + * @param {!function(number)} dst Characters destination as a function successively called with each converted char code. + * @throws {RangeError} If a starting byte is invalid in UTF8 + * @throws {Error} If the last sequence is truncated. Has an array property `bytes` holding the remaining bytes. + */ + utfx.decodeUTF8toUTF16 = function(src, dst) { + utfx.decodeUTF8(src, function(cp) { + utfx.UTF8toUTF16(cp, dst); + }); + }; + + /** + * Calculates the byte length of an UTF8 code point. + * @param {number} cp UTF8 code point + * @returns {number} Byte length + */ + utfx.calculateCodePoint = function(cp) { + return (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4; + }; + + /** + * Calculates the number of UTF8 bytes required to store UTF8 code points. + * @param {(!function():number|null)} src Code points source as a function returning the next code point respectively + * `null` if there are no more code points left. + * @returns {number} The number of UTF8 bytes required + */ + utfx.calculateUTF8 = function(src) { + var cp, l=0; + while ((cp = src()) !== null) + l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4; + return l; + }; + + /** + * Calculates the number of UTF8 code points respectively UTF8 bytes required to store UTF16 char codes. + * @param {(!function():number|null)} src Characters source as a function returning the next char code respectively + * `null` if there are no more characters left. + * @returns {!Array.} The number of UTF8 code points at index 0 and the number of UTF8 bytes required at index 1. + */ + utfx.calculateUTF16asUTF8 = function(src) { + var n=0, l=0; + utfx.UTF16toUTF8(src, function(cp) { + ++n; l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4; + }); + return [n,l]; + }; + + return utfx; + }(); + + // encodings/utf8 + + /** + * Encodes this ByteBuffer's contents between {@link ByteBuffer#offset} and {@link ByteBuffer#limit} to an UTF8 encoded + * string. + * @returns {string} Hex encoded string + * @throws {RangeError} If `offset > limit` + * @expose + */ + ByteBufferPrototype.toUTF8 = function(begin, end) { + if (typeof begin === 'undefined') begin = this.offset; + if (typeof end === 'undefined') end = this.limit; + if (!this.noAssert) { + if (typeof begin !== 'number' || begin % 1 !== 0) + throw TypeError("Illegal begin: Not an integer"); + begin >>>= 0; + if (typeof end !== 'number' || end % 1 !== 0) + throw TypeError("Illegal end: Not an integer"); + end >>>= 0; + if (begin < 0 || begin > end || end > this.buffer.byteLength) + throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength); + } + var sd; try { + utfx.decodeUTF8toUTF16(function() { + return begin < end ? this.view[begin++] : null; + }.bind(this), sd = stringDestination()); + } catch (e) { + if (begin !== end) + throw RangeError("Illegal range: Truncated data, "+begin+" != "+end); + } + return sd(); + }; + + /** + * Decodes an UTF8 encoded string to a ByteBuffer. + * @param {string} str String to decode + * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to + * {@link ByteBuffer.DEFAULT_ENDIAN}. + * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to + * {@link ByteBuffer.DEFAULT_NOASSERT}. + * @returns {!ByteBuffer} ByteBuffer + * @expose + */ + ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) { + if (!noAssert) + if (typeof str !== 'string') + throw TypeError("Illegal str: Not a string"); + var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert), + i = 0; + utfx.encodeUTF16toUTF8(stringSource(str), function(b) { + bb.view[i++] = b; + }); + bb.limit = i; + return bb; + }; + + return ByteBuffer; +}); + +},{"long":23}],23:[function(require,module,exports){ +/* + 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 + */ +(function(global, factory) { + + /* AMD */ if (typeof define === 'function' && define["amd"]) + define([], factory); + /* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"]) + module["exports"] = factory(); + /* Global */ else + (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = factory(); + +})(this, function() { + "use strict"; + + /** + * 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. + * @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` for signed + * @constructor + */ + function Long(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; + } + + // 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. + // + // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* + // methods on which they depend. + + /** + * An indicator used to reliably determine if an object is a Long or not. + * @type {boolean} + * @const + * @expose + * @private + */ + Long.__isLong__; + + Object.defineProperty(Long.prototype, "__isLong__", { + value: true, + enumerable: false, + configurable: false + }); + + /** + * Tests if the specified object is a Long. + * @param {*} obj Object + * @returns {boolean} + * @expose + */ + Long.isLong = function isLong(obj) { + return (obj && obj["__isLong__"]) === true; + }; + + /** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ + var INT_CACHE = {}; + + /** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ + 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` for signed + * @returns {!Long} The corresponding Long value + * @expose + */ + Long.fromInt = function fromInt(value, unsigned) { + var obj, cachedObj, cache; + if (!unsigned) { + value = value | 0; + if (cache = (-128 <= value && value < 128)) { + cachedObj = INT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = new Long(value, value < 0 ? -1 : 0, false); + if (cache) + INT_CACHE[value] = obj; + return obj; + } else { + value = value >>> 0; + if (cache = (0 <= value && value < 256)) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); + if (cache) + 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` for signed + * @returns {!Long} The corresponding Long value + * @expose + */ + Long.fromNumber = function fromNumber(value, unsigned) { + unsigned = !!unsigned; + if (isNaN(value) || !isFinite(value)) + return Long.ZERO; + if (!unsigned && value <= -TWO_PWR_63_DBL) + return Long.MIN_VALUE; + if (!unsigned && value + 1 >= TWO_PWR_63_DBL) + return Long.MAX_VALUE; + if (unsigned && value >= TWO_PWR_64_DBL) + return Long.MAX_UNSIGNED_VALUE; + if (value < 0) + return Long.fromNumber(-value, unsigned).neg(); + return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); + }; + + /** + * Returns a Long representing the 64 bit 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` for signed + * @returns {!Long} The corresponding Long value + * @expose + */ + Long.fromBits = function fromBits(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); + }; + + /** + * Returns a Long representation of the given string, written using the specified radix. + * @param {string} str The textual representation of the Long + * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed + * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 + * @returns {!Long} The corresponding Long value + * @expose + */ + Long.fromString = function fromString(str, unsigned, radix) { + if (str.length === 0) + throw 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 Error('radix out of range: ' + radix); + + var p; + if ((p = str.indexOf('-')) > 0) + throw Error('number format error: interior "-" character: ' + str); + else if (p === 0) + return Long.fromString(str.substring(1), unsigned, radix).neg(); + + // 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.mul(power).add(Long.fromNumber(value)); + } else { + result = result.mul(radixToPower); + result = result.add(Long.fromNumber(value)); + } + } + result.unsigned = unsigned; + return result; + }; + + /** + * Converts the specified value to a Long. + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @returns {!Long} + * @expose + */ + Long.fromValue = function fromValue(val) { + if (val /* is compatible */ instanceof Long) + return val; + if (typeof val === 'number') + return Long.fromNumber(val); + if (typeof val === 'string') + return Long.fromString(val); + // Throws for non-objects, converts non-instanceof Long: + return new Long(val.low, val.high, val.unsigned); + }; + + // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be + // no runtime penalty for these. + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_16_DBL = 1 << 16; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_24_DBL = 1 << 24; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + + /** + * @type {number} + * @const + * @inner + */ + var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + + /** + * @type {!Long} + * @const + * @inner + */ + var TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL); + + /** + * Signed zero. + * @type {!Long} + * @expose + */ + Long.ZERO = Long.fromInt(0); + + /** + * Unsigned zero. + * @type {!Long} + * @expose + */ + Long.UZERO = Long.fromInt(0, true); + + /** + * Signed one. + * @type {!Long} + * @expose + */ + Long.ONE = Long.fromInt(1); + + /** + * Unsigned one. + * @type {!Long} + * @expose + */ + Long.UONE = Long.fromInt(1, true); + + /** + * Signed negative one. + * @type {!Long} + * @expose + */ + Long.NEG_ONE = Long.fromInt(-1); + + /** + * Maximum signed value. + * @type {!Long} + * @expose + */ + Long.MAX_VALUE = new Long(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); + + /** + * Maximum unsigned value. + * @type {!Long} + * @expose + */ + Long.MAX_UNSIGNED_VALUE = new Long(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); + + /** + * Minimum signed value. + * @type {!Long} + * @expose + */ + Long.MIN_VALUE = new Long(0, 0x80000000|0, false); + + /** + * @alias Long.prototype + * @inner + */ + var LongPrototype = Long.prototype; + + /** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @returns {number} + * @expose + */ + LongPrototype.toInt = function toInt() { + return this.unsigned ? this.low >>> 0 : this.low; + }; + + /** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @returns {number} + * @expose + */ + LongPrototype.toNumber = function toNumber() { + if (this.unsigned) { + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + } + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); + }; + + /** + * Converts the Long to a string written in the specified radix. + * @param {number=} radix Radix (2-36), defaults to 10 + * @returns {string} + * @override + * @throws {RangeError} If `radix` is out of range + * @expose + */ + LongPrototype.toString = function toString(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix out of range: ' + radix); + if (this.isZero()) + return '0'; + var rem; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.eq(Long.MIN_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.mul(radixLong).sub(this); + return div.toString(radix) + rem.toInt().toString(radix); + } else + return '-' + this.neg().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), this.unsigned); + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower), + intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, + digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) + return digits + result; + else { + while (digits.length < 6) + digits = '0' + digits; + result = '' + digits + result; + } + } + }; + + /** + * Gets the high 32 bits as a signed integer. + * @returns {number} Signed high bits + * @expose + */ + LongPrototype.getHighBits = function getHighBits() { + return this.high; + }; + + /** + * Gets the high 32 bits as an unsigned integer. + * @returns {number} Unsigned high bits + * @expose + */ + LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { + return this.high >>> 0; + }; + + /** + * Gets the low 32 bits as a signed integer. + * @returns {number} Signed low bits + * @expose + */ + LongPrototype.getLowBits = function getLowBits() { + return this.low; + }; + + /** + * Gets the low 32 bits as an unsigned integer. + * @returns {number} Unsigned low bits + * @expose + */ + LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { + return this.low >>> 0; + }; + + /** + * Gets the number of bits needed to represent the absolute value of this Long. + * @returns {number} + * @expose + */ + LongPrototype.getNumBitsAbs = function getNumBitsAbs() { + if (this.isNegative()) // Unsigned Longs are never negative + return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); + 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; + }; + + /** + * Tests if this Long's value equals zero. + * @returns {boolean} + * @expose + */ + LongPrototype.isZero = function isZero() { + return this.high === 0 && this.low === 0; + }; + + /** + * Tests if this Long's value is negative. + * @returns {boolean} + * @expose + */ + LongPrototype.isNegative = function isNegative() { + return !this.unsigned && this.high < 0; + }; + + /** + * Tests if this Long's value is positive. + * @returns {boolean} + * @expose + */ + LongPrototype.isPositive = function isPositive() { + return this.unsigned || this.high >= 0; + }; + + /** + * Tests if this Long's value is odd. + * @returns {boolean} + * @expose + */ + LongPrototype.isOdd = function isOdd() { + return (this.low & 1) === 1; + }; + + /** + * Tests if this Long's value is even. + * @returns {boolean} + * @expose + */ + LongPrototype.isEven = function isEven() { + return (this.low & 1) === 0; + }; + + /** + * Tests if this Long's value equals the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.equals = function equals(other) { + if (!Long.isLong(other)) + other = Long.fromValue(other); + if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) + return false; + return this.high === other.high && this.low === other.low; + }; + + /** + * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.eq = LongPrototype.equals; + + /** + * Tests if this Long's value differs from the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.notEquals = function notEquals(other) { + return !this.eq(/* validates */ other); + }; + + /** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.neq = LongPrototype.notEquals; + + /** + * Tests if this Long's value is less than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.lessThan = function lessThan(other) { + return this.compare(/* validates */ other) < 0; + }; + + /** + * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.lt = LongPrototype.lessThan; + + /** + * Tests if this Long's value is less than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { + return this.compare(/* validates */ other) <= 0; + }; + + /** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.lte = LongPrototype.lessThanOrEqual; + + /** + * Tests if this Long's value is greater than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.greaterThan = function greaterThan(other) { + return this.compare(/* validates */ other) > 0; + }; + + /** + * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.gt = LongPrototype.greaterThan; + + /** + * Tests if this Long's value is greater than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { + return this.compare(/* validates */ other) >= 0; + }; + + /** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @expose + */ + LongPrototype.gte = LongPrototype.greaterThanOrEqual; + + /** + * Compares this Long's value with the specified's. + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + * @expose + */ + LongPrototype.compare = function compare(other) { + if (!Long.isLong(other)) + other = Long.fromValue(other); + if (this.eq(other)) + return 0; + var thisNeg = this.isNegative(), + otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) + return -1; + if (!thisNeg && otherNeg) + return 1; + // At this point the sign bits are the same + if (!this.unsigned) + return this.sub(other).isNegative() ? -1 : 1; + // 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; + }; + + /** + * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. + * @function + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + * @expose + */ + LongPrototype.comp = LongPrototype.compare; + + /** + * Negates this Long's value. + * @returns {!Long} Negated Long + * @expose + */ + LongPrototype.negate = function negate() { + if (!this.unsigned && this.eq(Long.MIN_VALUE)) + return Long.MIN_VALUE; + return this.not().add(Long.ONE); + }; + + /** + * Negates this Long's value. This is an alias of {@link Long#negate}. + * @function + * @returns {!Long} Negated Long + * @expose + */ + LongPrototype.neg = LongPrototype.negate; + + /** + * Returns the sum of this and the specified Long. + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + * @expose + */ + LongPrototype.add = function add(addend) { + if (!Long.isLong(addend)) + addend = Long.fromValue(addend); + + // 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 = addend.high >>> 16; + var b32 = addend.high & 0xFFFF; + var b16 = addend.low >>> 16; + var b00 = addend.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 new Long((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns the difference of this and the specified Long. + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + * @expose + */ + LongPrototype.subtract = function subtract(subtrahend) { + if (!Long.isLong(subtrahend)) + subtrahend = Long.fromValue(subtrahend); + return this.add(subtrahend.neg()); + }; + + /** + * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. + * @function + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + * @expose + */ + LongPrototype.sub = LongPrototype.subtract; + + /** + * Returns the product of this and the specified Long. + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + * @expose + */ + LongPrototype.multiply = function multiply(multiplier) { + if (this.isZero()) + return Long.ZERO; + if (!Long.isLong(multiplier)) + multiplier = Long.fromValue(multiplier); + if (multiplier.isZero()) + return Long.ZERO; + if (this.eq(Long.MIN_VALUE)) + return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO; + if (multiplier.eq(Long.MIN_VALUE)) + return this.isOdd() ? Long.MIN_VALUE : Long.ZERO; + + if (this.isNegative()) { + if (multiplier.isNegative()) + return this.neg().mul(multiplier.neg()); + else + return this.neg().mul(multiplier).neg(); + } else if (multiplier.isNegative()) + return this.mul(multiplier.neg()).neg(); + + // If both longs are small, use float multiplication + if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) + return Long.fromNumber(this.toNumber() * multiplier.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 = multiplier.high >>> 16; + var b32 = multiplier.high & 0xFFFF; + var b16 = multiplier.low >>> 16; + var b00 = multiplier.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 new Long((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); + }; + + /** + * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. + * @function + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + * @expose + */ + LongPrototype.mul = LongPrototype.multiply; + + /** + * Returns this Long divided by the specified. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + * @expose + */ + LongPrototype.divide = function divide(divisor) { + if (!Long.isLong(divisor)) + divisor = Long.fromValue(divisor); + if (divisor.isZero()) + throw Error('division by zero'); + if (this.isZero()) + return this.unsigned ? Long.UZERO : Long.ZERO; + var approx, rem, res; + if (this.eq(Long.MIN_VALUE)) { + if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE)) + return Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + else if (divisor.eq(Long.MIN_VALUE)) + return Long.ONE; + else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shr(1); + approx = halfThis.div(divisor).shl(1); + if (approx.eq(Long.ZERO)) { + return divisor.isNegative() ? Long.ONE : Long.NEG_ONE; + } else { + rem = this.sub(divisor.mul(approx)); + res = approx.add(rem.div(divisor)); + return res; + } + } + } else if (divisor.eq(Long.MIN_VALUE)) + return this.unsigned ? Long.UZERO : Long.ZERO; + if (this.isNegative()) { + if (divisor.isNegative()) + return this.neg().div(divisor.neg()); + return this.neg().div(divisor).neg(); + } else if (divisor.isNegative()) + return this.div(divisor.neg()).neg(); + + // 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. + res = Long.ZERO; + rem = this; + while (rem.gte(divisor)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / divisor.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), + 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. + approxRes = Long.fromNumber(approx), + approxRem = approxRes.mul(divisor); + while (approxRem.isNegative() || approxRem.gt(rem)) { + approx -= delta; + approxRes = Long.fromNumber(approx, this.unsigned); + approxRem = approxRes.mul(divisor); + } + + // 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.sub(approxRem); + } + return res; + }; + + /** + * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + * @expose + */ + LongPrototype.div = LongPrototype.divide; + + /** + * Returns this Long modulo the specified. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + * @expose + */ + LongPrototype.modulo = function modulo(divisor) { + if (!Long.isLong(divisor)) + divisor = Long.fromValue(divisor); + return this.sub(this.div(divisor).mul(divisor)); + }; + + /** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + * @expose + */ + LongPrototype.mod = LongPrototype.modulo; + + /** + * Returns the bitwise NOT of this Long. + * @returns {!Long} + * @expose + */ + LongPrototype.not = function not() { + return new Long(~this.low, ~this.high, this.unsigned); + }; + + /** + * Returns the bitwise AND of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @expose + */ + LongPrototype.and = function and(other) { + if (!Long.isLong(other)) + other = Long.fromValue(other); + return new Long(this.low & other.low, this.high & other.high, this.unsigned); + }; + + /** + * Returns the bitwise OR of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @expose + */ + LongPrototype.or = function or(other) { + if (!Long.isLong(other)) + other = Long.fromValue(other); + return new Long(this.low | other.low, this.high | other.high, this.unsigned); + }; + + /** + * Returns the bitwise XOR of this Long and the given one. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @expose + */ + LongPrototype.xor = function xor(other) { + if (!Long.isLong(other)) + other = Long.fromValue(other); + return new Long(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|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shiftLeft = function shiftLeft(numBits) { + if (Long.isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return new Long(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); + else + return new Long(0, this.low << (numBits - 32), this.unsigned); + }; + + /** + * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shl = LongPrototype.shiftLeft; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shiftRight = function shiftRight(numBits) { + if (Long.isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return new Long((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); + else + return new Long(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); + }; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shr = LongPrototype.shiftRight; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { + if (Long.isLong(numBits)) + numBits = numBits.toInt(); + numBits &= 63; + if (numBits === 0) + return this; + else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return new Long((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits === 32) + return new Long(high, 0, this.unsigned); + else + return new Long(high >>> (numBits - 32), 0, this.unsigned); + } + }; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @expose + */ + LongPrototype.shru = LongPrototype.shiftRightUnsigned; + + /** + * Converts this Long to signed. + * @returns {!Long} Signed long + * @expose + */ + LongPrototype.toSigned = function toSigned() { + if (!this.unsigned) + return this; + return new Long(this.low, this.high, false); + }; + + /** + * Converts this Long to unsigned. + * @returns {!Long} Unsigned long + * @expose + */ + LongPrototype.toUnsigned = function toUnsigned() { + if (this.unsigned) + return this; + return new Long(this.low, this.high, true); + }; + + return Long; +}); + +},{}]},{},[18])(18) +}); \ No newline at end of file diff --git a/dist/machinetalk-protobuf.min.js b/dist/machinetalk-protobuf.min.js new file mode 100644 index 000000000..5538e7500 --- /dev/null +++ b/dist/machinetalk-protobuf.min.js @@ -0,0 +1,61 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.machinetalk || (g.machinetalk = {})).protobuf = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o1)for(var r=1;r]/g,RULE:/^(?:required|optional|repeated|map)$/,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]*$/,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|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0[xX][0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,BOOL:/^(?:true|false)$/i,ID:/^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,STRING_DQ:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,STRING_SQ:/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g},i.DotProto=function(e,t){function i(e,i){var r=-1,n=1;if("-"==e.charAt(0)&&(n=-1,e=e.substring(1)),t.NUMBER_DEC.test(e))r=parseInt(e);else if(t.NUMBER_HEX.test(e))r=parseInt(e.substring(2),16);else{if(!t.NUMBER_OCT.test(e))throw Error("illegal id value: "+(0>n?"-":"")+e);r=parseInt(e.substring(1),8)}if(r=n*r|0,!i&&0>r)throw Error("illegal id value: "+(0>n?"-":"")+e);return r}function r(e){var i=1;if("-"==e.charAt(0)&&(i=-1,e=e.substring(1)),t.NUMBER_DEC.test(e))return i*parseInt(e,10);if(t.NUMBER_HEX.test(e))return i*parseInt(e.substring(2),16);if(t.NUMBER_OCT.test(e))return i*parseInt(e.substring(1),8);if("inf"===e)return i*(1/0);if("nan"===e)return NaN;if(t.NUMBER_FLT.test(e))return i*parseFloat(e);throw Error("illegal number value: "+(0>i?"-":"")+e)}function n(e,t,i){"undefined"==typeof e[t]?e[t]=i:(Array.isArray(e[t])||(e[t]=[e[t]]),e[t].push(i))}var s={},o=function(e){this.source=e+"",this.index=0,this.line=1,this.stack=[],this._stringOpen=null},a=o.prototype;a._readString=function(){var e='"'===this._stringOpen?t.STRING_DQ:t.STRING_SQ;e.lastIndex=this.index-1;var i=e.exec(this.source);if(!i)throw Error("unterminated string");return this.index=e.lastIndex,this.stack.push(this._stringOpen),this._stringOpen=null,i[1]},a.next=function(){if(this.stack.length>0)return this.stack.shift();if(this.index>=this.source.length)return null;if(null!==this._stringOpen)return this._readString();var e,i,r;do{for(e=!1;t.WHITESPACE.test(r=this.source.charAt(this.index));)if("\n"===r&&++this.line,++this.index===this.source.length)return null;if("/"===this.source.charAt(this.index))if(++this.index,"/"===this.source.charAt(this.index)){for(;"\n"!==this.source.charAt(++this.index);)if(this.index==this.source.length)return null;++this.index,++this.line,e=!0}else{if("*"!==(r=this.source.charAt(this.index)))return"/";do{if("\n"===r&&++this.line,++this.index===this.source.length)return null;i=r,r=this.source.charAt(this.index)}while("*"!==i||"/"!==r);++this.index,e=!0}}while(e);if(this.index===this.source.length)return null;var n=this.index;t.DELIM.lastIndex=0;var s=t.DELIM.test(this.source.charAt(n++));if(!s)for(;n"),s=this.tn.next(),!t.NAME.test(s))throw Error("illegal message field name: "+s);o.name=s,this.tn.skip("="),o.id=i(this.tn.next()),s=this.tn.peek(),"["===s&&this._parseFieldOptions(o),this.tn.skip(";")}else if(n="undefined"!=typeof n?n:this.tn.next(),"group"===n){var a=this._parseMessage(e,o);if(!/^[A-Z]/.test(a.name))throw Error("illegal group name: "+a.name);o.type=a.name,o.name=a.name.toLowerCase(),this.tn.omit(";")}else{if(!t.TYPE.test(n)&&!t.TYPEREF.test(n))throw Error("illegal message field type: "+n);if(o.type=n,s=this.tn.next(),!t.NAME.test(s))throw Error("illegal message field name: "+s);o.name=s,this.tn.skip("="),o.id=i(this.tn.next()),s=this.tn.peek(),"["===s&&this._parseFieldOptions(o),this.tn.skip(";")}return e.fields.push(o),o},u._parseMessageOneOf=function(e){var i=this.tn.next();if(!t.NAME.test(i))throw Error("illegal oneof name: "+i);var r,n=i,s=[];for(this.tn.skip("{");"}"!==(i=this.tn.next());)r=this._parseMessageField(e,"optional",i),r.oneof=n,s.push(r.id);this.tn.omit(";"),e.oneofs[n]=s},u._parseFieldOptions=function(e){this.tn.skip("[");for(var t,i=!0;"]"!==(t=this.tn.peek());)i||this.tn.skip(","),this._parseOption(e,!0),i=!1;this.tn.next()},u._parseEnum=function(e){var r={name:"",values:[],options:{}},n=this.tn.next();if(!t.NAME.test(n))throw Error("illegal name: "+n);for(r.name=n,this.tn.skip("{");"}"!==(n=this.tn.next());)if("option"===n)this._parseOption(r);else{if(!t.NAME.test(n))throw Error("illegal name: "+n);this.tn.skip("=");var s={name:n,id:i(this.tn.next(),!0)};n=this.tn.peek(),"["===n&&this._parseFieldOptions({options:{}}),this.tn.skip(";"),r.values.push(s)}this.tn.omit(";"),e.enums.push(r)},u._parseExtensions=function(t){var i=this.tn.next(),n=[];"min"===i?n.push(e.ID_MIN):"max"===i?n.push(e.ID_MAX):n.push(r(i)),this.tn.skip("to"),i=this.tn.next(),"min"===i?n.push(e.ID_MIN):"max"===i?n.push(e.ID_MAX):n.push(r(i)),this.tn.skip(";"),t.extensions=n},u._parseExtend=function(e){var i=this.tn.next();if(!t.TYPEREF.test(i))throw Error("illegal extend reference: "+i);var r={ref:i,fields:[]};for(this.tn.skip("{");"}"!==(i=this.tn.next());)if(t.RULE.test(i))this._parseMessageField(r,i);else{if(!t.TYPEREF.test(i))throw Error("illegal extend token: "+i);if(!this.proto3)throw Error("illegal field rule: "+i);this._parseMessageField(r,"optional",i)}return this.tn.omit(";"),e.messages.push(r),r},u.toString=function(){return"Parser at line "+this.tn.line},s.Parser=l,s}(i,i.Lang),i.Reflect=function(t){function i(i){if("string"==typeof i&&(i=t.TYPES[i]),"undefined"==typeof i.defaultValue)throw Error("default value for type "+i.name+" is not supported");return i==t.TYPES.bytes?new e(0):i.defaultValue}function r(e,i){if(e&&"number"==typeof e.low&&"number"==typeof e.high&&"boolean"==typeof e.unsigned&&e.low===e.low&&e.high===e.high)return new t.Long(e.low,e.high,"undefined"==typeof i?e.unsigned:i);if("string"==typeof e)return t.Long.fromString(e,i||!1,10);if("number"==typeof e)return t.Long.fromNumber(e,i||!1);throw Error("not convertible to Long")}function n(e,i){var r=i.readVarint32(),s=7&r,o=r>>>3;switch(s){case t.WIRE_TYPES.VARINT:do r=i.readUint8();while(128===(128&r));break;case t.WIRE_TYPES.BITS64:i.offset+=8;break;case t.WIRE_TYPES.LDELIM:r=i.readVarint32(),i.offset+=r;break;case t.WIRE_TYPES.STARTGROUP:n(o,i);break;case t.WIRE_TYPES.ENDGROUP:if(o===e)return!1;throw Error("Illegal GROUPEND after unknown group: "+o+" ("+e+" expected)");case t.WIRE_TYPES.BITS32:i.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+e+": "+s)}return!0}var s={},o=function(e,t,i){this.builder=e,this.parent=t,this.name=i,this.className},a=o.prototype;a.fqn=function(){for(var e=this.name,t=this;;){if(t=t.parent,null==t)break;e=t.name+"."+e}return e},a.toString=function(e){return(e?this.className+" ":"")+this.fqn()},a.build=function(){throw Error(this.toString(!0)+" cannot be built directly")},s.T=o;var l=function(e,t,i,r,n){o.call(this,e,t,i),this.className="Namespace",this.children=[],this.options=r||{},this.syntax=n||"proto2"},u=l.prototype=Object.create(o.prototype);u.getChildren=function(e){if(e=e||null,null==e)return this.children.slice();for(var t=[],i=0,r=this.children.length;r>i;++i)this.children[i]instanceof e&&t.push(this.children[i]);return t},u.addChild=function(e){var t;if(t=this.getChild(e.name))if(t instanceof p.Field&&t.name!==t.originalName&&null===this.getChild(t.originalName))t.name=t.originalName;else{if(!(e instanceof p.Field&&e.name!==e.originalName&&null===this.getChild(e.originalName)))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+e.name);e.name=e.originalName}this.children.push(e)},u.getChild=function(e){for(var t="number"==typeof e?"id":"name",i=0,r=this.children.length;r>i;++i)if(this.children[i][t]===e)return this.children[i];return null},u.resolve=function(e,t){var i="string"==typeof e?e.split("."):e,r=this,n=0;if(""===i[n]){for(;null!==r.parent;)r=r.parent;n++}var o;do{do{if(!(r instanceof s.Namespace)){r=null;break}if(o=r.getChild(i[n]),!o||!(o instanceof s.T)||t&&!(o instanceof s.Namespace)){r=null;break}r=o,n++}while(nr;++r)e=i[r],e instanceof l&&(t[e.name]=e.build());return Object.defineProperty&&Object.defineProperty(t,"$options",{value:this.buildOpt()}),t},u.buildOpt=function(){for(var e={},t=Object.keys(this.options),i=0,r=t.length;r>i;++i){var n=t[i],s=this.options[t[i]];e[n]=s}return e},u.getOption=function(e){return"undefined"==typeof e?this.options:"undefined"!=typeof this.options[e]?this.options[e]:null},s.Namespace=l;var f=function(e,i,r,n){if(this.type=e,this.resolvedType=i,this.isMapKey=r,this.syntax=n,r&&t.MAP_KEY_TYPES.indexOf(e)<0)throw Error("Invalid map key type: "+e.name)},h=f.prototype;f.defaultFieldValue=i,h.verifyValue=function(i){var n=function(e,t){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+e+" ("+t+")")}.bind(this);switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:return("number"!=typeof i||i===i&&i%1!==0)&&n(typeof i,"not an integer"),i>4294967295?0|i:i;case t.TYPES.uint32:case t.TYPES.fixed32:return("number"!=typeof i||i===i&&i%1!==0)&&n(typeof i,"not an integer"),0>i?i>>>0:i;case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:if(t.Long)try{return r(i,!1)}catch(s){n(typeof i,s.message)}else n(typeof i,"requires Long.js");case t.TYPES.uint64:case t.TYPES.fixed64:if(t.Long)try{return r(i,!0)}catch(s){n(typeof i,s.message)}else n(typeof i,"requires Long.js");case t.TYPES.bool:return"boolean"!=typeof i&&n(typeof i,"not a boolean"),i;case t.TYPES["float"]:case t.TYPES["double"]:return"number"!=typeof i&&n(typeof i,"not a number"),i;case t.TYPES.string:return"string"==typeof i||i&&i instanceof String||n(typeof i,"not a string"),""+i;case t.TYPES.bytes:return e.isByteBuffer(i)?i:e.wrap(i,"base64");case t.TYPES["enum"]:var o=this.resolvedType.getChildren(t.Reflect.Enum.Value);for(l=0;l4294967295||0>i)&&n(typeof i,"not in range for uint32"),i;n(i,"not a valid enum value");case t.TYPES.group:case t.TYPES.message:if(i&&"object"==typeof i||n(typeof i,"object expected"),i instanceof this.resolvedType.clazz)return i;if(i instanceof t.Builder.Message){var a={};for(var l in i)i.hasOwnProperty(l)&&(a[l]=i[l]);i=a}return new this.resolvedType.clazz(i)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+i+" (undefined type "+this.type+")")},h.calculateLength=function(i,r){if(null===r)return 0;var n;switch(this.type){case t.TYPES.int32:return 0>r?e.calculateVarint64(r):e.calculateVarint32(r);case t.TYPES.uint32:return e.calculateVarint32(r);case t.TYPES.sint32:return e.calculateVarint32(e.zigZagEncode32(r));case t.TYPES.fixed32:case t.TYPES.sfixed32:case t.TYPES["float"]:return 4;case t.TYPES.int64:case t.TYPES.uint64:return e.calculateVarint64(r);case t.TYPES.sint64:return e.calculateVarint64(e.zigZagEncode64(r));case t.TYPES.fixed64:case t.TYPES.sfixed64:return 8;case t.TYPES.bool:return 1;case t.TYPES["enum"]:return e.calculateVarint32(r);case t.TYPES["double"]:return 8;case t.TYPES.string:return n=e.calculateUTF8Bytes(r),e.calculateVarint32(n)+n;case t.TYPES.bytes:if(r.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+r.remaining()+" bytes remaining");return e.calculateVarint32(r.remaining())+r.remaining();case t.TYPES.message:return n=this.resolvedType.calculate(r),e.calculateVarint32(n)+n;case t.TYPES.group:return n=this.resolvedType.calculate(r),n+e.calculateVarint32(i<<3|t.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+r+" (unknown type)")},h.encodeValue=function(i,r,n){if(null===r)return n;switch(this.type){case t.TYPES.int32:0>r?n.writeVarint64(r):n.writeVarint32(r);break;case t.TYPES.uint32:n.writeVarint32(r);break;case t.TYPES.sint32:n.writeVarint32ZigZag(r);break;case t.TYPES.fixed32:n.writeUint32(r);break;case t.TYPES.sfixed32:n.writeInt32(r);break;case t.TYPES.int64:case t.TYPES.uint64:n.writeVarint64(r);break;case t.TYPES.sint64:n.writeVarint64ZigZag(r);break;case t.TYPES.fixed64:n.writeUint64(r);break;case t.TYPES.sfixed64:n.writeInt64(r);break;case t.TYPES.bool:"string"==typeof r?n.writeVarint32("false"===r.toLowerCase()?0:!!r):n.writeVarint32(r?1:0);break;case t.TYPES["enum"]:n.writeVarint32(r);break;case t.TYPES["float"]:n.writeFloat32(r);break;case t.TYPES["double"]:n.writeFloat64(r);break;case t.TYPES.string:n.writeVString(r);break;case t.TYPES.bytes:if(r.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+r.remaining()+" bytes remaining");var s=r.offset;n.writeVarint32(r.remaining()),n.append(r),r.offset=s;break;case t.TYPES.message:var o=(new e).LE();this.resolvedType.encode(r,o),n.writeVarint32(o.offset),n.append(o.flip());break;case t.TYPES.group:this.resolvedType.encode(r,n),n.writeVarint32(i<<3|t.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+r+" (unknown type)")}return n},h.decode=function(e,i,r){if(i!=this.type.wireType)throw Error("Unexpected wire type for element");var n,s;switch(this.type){case t.TYPES.int32:return 0|e.readVarint32();case t.TYPES.uint32:return e.readVarint32()>>>0;case t.TYPES.sint32:return 0|e.readVarint32ZigZag();case t.TYPES.fixed32:return e.readUint32()>>>0;case t.TYPES.sfixed32:return 0|e.readInt32();case t.TYPES.int64:return e.readVarint64();case t.TYPES.uint64:return e.readVarint64().toUnsigned();case t.TYPES.sint64:return e.readVarint64ZigZag();case t.TYPES.fixed64:return e.readUint64();case t.TYPES.sfixed64:return e.readInt64();case t.TYPES.bool:return!!e.readVarint32();case t.TYPES["enum"]:return e.readVarint32();case t.TYPES["float"]:return e.readFloat();case t.TYPES["double"]:return e.readDouble();case t.TYPES.string:return e.readVString();case t.TYPES.bytes:if(s=e.readVarint32(),e.remaining()l;++l)this[s[l].name]=null;for(l=0,u=n.length;u>l;++l){var f=n[l];this[f.name]=f.repeated?[]:f.map?new t.Map(f):null,!f.required&&"proto3"!==i.syntax||null===f.defaultValue||(this[f.name]=f.defaultValue)}if(arguments.length>0){var h;if(1!==arguments.length||null===r||"object"!=typeof r||!("function"!=typeof r.encode||r instanceof o)||Array.isArray(r)||r instanceof t.Map||e.isByteBuffer(r)||r instanceof ArrayBuffer||t.Long&&r instanceof t.Long)for(l=0,u=arguments.length;u>l;++l)"undefined"!=typeof(h=arguments[l])&&this.$set(n[l].name,h);else this.$set(r)}},a=o.prototype=Object.create(t.Builder.Message.prototype);a.add=function(e,r,n){var s=i._fieldsByName[e];if(!n){if(!s)throw Error(this+"#"+e+" is undefined");if(!(s instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+s.toString(!0));if(!s.repeated)throw Error(this+"#"+e+" is not a repeated field");r=s.verifyValue(r,!0)}return null===this[e]&&(this[e]=[]),this[e].push(r),this},a.$add=a.add,a.set=function(e,r,n){if(e&&"object"==typeof e){n=r;for(var s in e)e.hasOwnProperty(s)&&"undefined"!=typeof(r=e[s])&&this.$set(s,r,n);return this}var o=i._fieldsByName[e];if(n)this[e]=r;else{if(!o)throw Error(this+"#"+e+" is not a field: undefined");if(!(o instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+o.toString(!0));this[o.name]=r=o.verifyValue(r)}if(o&&o.oneof){var a=this[o.oneof.name];null!==r?(null!==a&&a!==o.name&&(this[a]=null),this[o.oneof.name]=o.name):a===e&&(this[o.oneof.name]=null)}return this},a.$set=a.set,a.get=function(e,r){if(r)return this[e];var n=i._fieldsByName[e];if(!(n&&n instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: undefined");if(!(n instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+n.toString(!0));return this[n.name]},a.$get=a.get;for(var l=0;ls;s++)if(n=this.children[s],n instanceof m||n instanceof p||n instanceof P){if(r.hasOwnProperty(n.name))throw Error("Illegal reflect child of "+this.toString(!0)+": "+n.toString(!0)+" cannot override static property '"+n.name+"'");r[n.name]=n.build()}else if(n instanceof p.Field)n.build(),this._fields.push(n),this._fieldsById[n.id]=n,this._fieldsByName[n.name]=n;else if(!(n instanceof p.OneOf||n instanceof S))throw Error("Illegal reflect child of "+this.toString(!0)+": "+this.children[s].toString(!0));return this.clazz=r},c.encode=function(e,t,i){for(var r,n,s=null,o=0,a=this._fields.length;a>o;++o)r=this._fields[o],n=e[r.name],r.required&&null===n?null===s&&(s=r):r.encode(i?n:r.verifyValue(n),t,e);if(null!==s){var l=Error("Missing at least one required field for "+this.toString(!0)+": "+s);throw l.encoded=t,l}return t},c.calculate=function(e){for(var t,i,r=0,n=0,s=this._fields.length;s>n;++n){if(t=this._fields[n],i=e[t.name],t.required&&null===i)throw Error("Missing at least one required field for "+this.toString(!0)+": "+t);r+=t.calculate(i,e)}return r},c.decode=function(e,i,r){i="number"==typeof i?i:-1;for(var s,o,a,l,u=e.offset,f=new this.clazz;e.offset0;){if(s=e.readVarint32(),o=7&s,a=s>>>3,o===t.WIRE_TYPES.ENDGROUP){if(a!==r)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+a+" ("+(r?r+" expected":"not a group")+")");break}if(l=this._fieldsById[a]){if(l.repeated&&!l.options.packed)f[l.name].push(l.decode(o,e));else if(l.map){var h=l.decode(o,e);f[l.name].set(h[0],h[1])}else if(f[l.name]=l.decode(o,e), +l.oneof){var p=f[l.oneof.name];null!==p&&p!==l.name&&(f[p]=null),f[l.oneof.name]=l.name}}else switch(o){case t.WIRE_TYPES.VARINT:e.readVarint32();break;case t.WIRE_TYPES.BITS32:e.offset+=4;break;case t.WIRE_TYPES.BITS64:e.offset+=8;break;case t.WIRE_TYPES.LDELIM:var c=e.readVarint32();e.offset+=c;break;case t.WIRE_TYPES.STARTGROUP:for(;n(a,e););break;default:throw Error("Illegal wire type for unknown field "+a+" in "+this.toString(!0)+"#decode: "+o)}}for(var d=0,E=this._fields.length;E>d;++d)if(l=this._fields[d],null===f[l.name])if("proto3"===this.syntax)f[l.name]=l.defaultValue;else{if(l.required){var y=Error("Missing at least one required field for "+this.toString(!0)+": "+l.name);throw y.decoded=f,y}t.populateDefaults&&null!==l.defaultValue&&(f[l.name]=l.defaultValue)}return f},s.Message=p;var d=function(e,i,r,n,s,a,l,u,f,h){o.call(this,e,i,a),this.className="Message.Field",this.required="required"===r,this.repeated="repeated"===r,this.map="map"===r,this.keyType=n||null,this.type=s,this.resolvedType=null,this.id=l,this.options=u||{},this.defaultValue=null,this.oneof=f||null,this.syntax=h||"proto2",this.originalName=this.name,this.element=null,this.keyElement=null,!this.builder.options.convertFieldsToCamelCase||this instanceof p.ExtensionField||(this.name=t.Util.toCamelCase(this.name))},E=d.prototype=Object.create(o.prototype);E.build=function(){this.element=new f(this.type,this.resolvedType,!1,this.syntax),this.map&&(this.keyElement=new f(this.keyType,void 0,!0,this.syntax)),"proto3"!==this.syntax||this.repeated||this.map?"undefined"!=typeof this.options["default"]&&(this.defaultValue=this.verifyValue(this.options["default"])):this.defaultValue=f.defaultFieldValue(this.type)},E.verifyValue=function(e,i){i=i||!1;var r=function(e,t){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+e+" ("+t+")")}.bind(this);if(null===e)return this.required&&r(typeof e,"required"),"proto3"===this.syntax&&this.type!==t.TYPES.message&&r(typeof e,"proto3 field without field presence cannot be null"),null;var n;if(this.repeated&&!i){Array.isArray(e)||(e=[e]);var s=[];for(n=0;n0;case t.TYPES.bytes:return e.remaining()>0;case t.TYPES["enum"]:return 0!==e;case t.TYPES.message:return null!==e;default:return!0}},E.encode=function(i,r,n){if(null===this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===i||this.repeated&&0==i.length)return r;try{if(this.repeated){var s;if(this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0){r.writeVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),r.ensureCapacity(r.offset+=1);var o=r.offset;for(s=0;s1){var u=r.slice(o,r.offset);o+=l-1,r.offset=o,r.append(u)}r.writeVarint32(a,o-l)}else for(s=0;s=0){for(n+=e.calculateVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),o=0,s=0;s=0&&!r){s=i.readVarint32(),s=i.offset+s;for(var a=[];i.offset0;){var h=u.readVarint32();e=7&h;var p=h>>>3;if(1===p)l=this.keyElement.decode(u,e,p);else{if(2!==p)throw Error("Unexpected tag in map field key/value submessage");n=this.element.decode(u,e,p)}}return[l,n]}return this.element.decode(i,e,this.id)},s.Message.Field=d;var y=function(e,t,i,r,n,s,o){d.call(this,e,t,i,null,r,n,s,o),this.extension};y.prototype=Object.create(d.prototype),s.Message.ExtensionField=y;var g=function(e,t,i){o.call(this,e,t,i),this.fields=[]};s.Message.OneOf=g;var m=function(e,t,i,r,n){l.call(this,e,t,i,r,n),this.className="Enum",this.object=null};m.getName=function(e,t){for(var i,r=Object.keys(e),n=0;nn;++n)i[r[n].name]=r[n].id;return Object.defineProperty&&Object.defineProperty(i,"$options",{value:this.buildOpt(),enumerable:!1}),this.object=i},s.Enum=m;var T=function(e,t,i,r){o.call(this,e,t,i),this.className="Enum.Value",this.id=r};T.prototype=Object.create(o.prototype),s.Enum.Value=T;var S=function(e,t,i,r){o.call(this,e,t,i),this.field=r};S.prototype=Object.create(o.prototype),s.Extension=S;var P=function(e,t,i,r){l.call(this,e,t,i,r),this.className="Service",this.clazz=null},w=P.prototype=Object.create(l.prototype);w.build=function(i){return this.clazz&&!i?this.clazz:this.clazz=function(t,i){for(var r=function(e){t.Builder.Service.call(this),this.rpcImpl=e||function(e,t,i){setTimeout(i.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}},n=r.prototype=Object.create(t.Builder.Service.prototype),s=i.getChildren(t.Reflect.Service.RPCMethod),o=0;o0;){if(t=r.pop(),!Array.isArray(t))throw Error("not a valid namespace: "+JSON.stringify(t));for(;t.length>0;){var s=t.shift();if(n.isMessage(s)){var o=new i.Message(this,this.ptr,s.name,s.options,s.isGroup,s.syntax),a={};s.oneofs&&Object.keys(s.oneofs).forEach(function(e){o.addChild(a[e]=new i.Message.OneOf(this,o,e))},this),s.fields&&s.fields.forEach(function(e){if(null!==o.getChild(0|e.id))throw Error("duplicate or invalid field id in "+o.name+": "+e.id);if(e.options&&"object"!=typeof e.options)throw Error("illegal field options in "+o.name+"#"+e.name);var t=null;if("string"==typeof e.oneof&&!(t=a[e.oneof]))throw Error("illegal oneof in "+o.name+"#"+e.name+": "+e.oneof);e=new i.Message.Field(this,o,e.rule,e.keytype,e.type,e.name,e.id,e.options,t,s.syntax),t&&t.fields.push(e),o.addChild(e)},this);var l=[];if(s.enums&&s.enums.forEach(function(e){l.push(e)}),s.messages&&s.messages.forEach(function(e){l.push(e)}),s.services&&s.services.forEach(function(e){l.push(e)}),s.extensions&&(o.extensions=s.extensions,o.extensions[0]e.ID_MAX&&(o.extensions[1]=e.ID_MAX)),this.ptr.addChild(o),l.length>0){r.push(t),t=l,l=null,this.ptr=o,o=null;continue}l=null}else if(n.isEnum(s))o=new i.Enum(this,this.ptr,s.name,s.options,s.syntax),s.values.forEach(function(e){o.addChild(new i.Enum.Value(this,o,e.name,e.id))},this),this.ptr.addChild(o);else if(n.isService(s))o=new i.Service(this,this.ptr,s.name,s.options),Object.keys(s.rpc).forEach(function(e){var t=s.rpc[e];o.addChild(new i.Service.RPCMethod(this,o,e,t.request,t.response,!!t.request_stream,!!t.response_stream,t.options))},this),this.ptr.addChild(o);else{if(!n.isExtend(s))throw Error("not a valid definition: "+JSON.stringify(s));if(o=this.ptr.resolve(s.ref,!0))s.fields.forEach(function(t){if(null!==o.getChild(0|t.id))throw Error("duplicate extended field id in "+o.name+": "+t.id);if(t.ido.extensions[1])throw Error("illegal extended field id in "+o.name+": "+t.id+" ("+o.extensions.join(" to ")+" expected)");var r=t.name;this.options.convertFieldsToCamelCase&&(r=e.Util.toCamelCase(r));var n=new i.Message.ExtensionField(this,o,t.rule,t.type,this.ptr.fqn()+"."+r,t.id,t.options),s=new i.Extension(this,this.ptr,t.name,n);n.extension=s,this.ptr.addChild(s),o.addChild(n)},this);else if(!/\.?google\.protobuf\./.test(s.ref))throw Error("extended message "+s.ref+" is not defined")}s=null,o=null}t=null,this.ptr=this.ptr.parent}return this.resolved=!1,this.result=null,this},s["import"]=function(t,i){var n="/";if("string"==typeof i){if(e.Util.IS_NODE&&(i=require("path").resolve(i)),this.files[i]===!0)return this.reset();this.files[i]=!0}else if("object"==typeof i){var s=i.root;e.Util.IS_NODE&&(s=require("path").resolve(s)),(s.indexOf("\\")>=0||i.file.indexOf("\\")>=0)&&(n="\\");var o=s+n+i.file;if(this.files[o]===!0)return this.reset();this.files[o]=!0}if(t.imports&&t.imports.length>0){var a,l=!1;"object"==typeof i?(this.importRoot=i.root,l=!0,a=this.importRoot,i=i.file,(a.indexOf("\\")>=0||i.indexOf("\\")>=0)&&(n="\\")):"string"==typeof i?this.importRoot?a=this.importRoot:i.indexOf("/")>=0?(a=i.replace(/\/[^\/]*$/,""),""===a&&(a="/")):i.indexOf("\\")>=0?(a=i.replace(/\\[^\\]*$/,""),n="\\"):a=".":a=null;for(var u=0;u1024&&(t.push(h.apply(String,e)),e.length=0),void Array.prototype.push.apply(e,arguments))}}function i(e,t,r,i,n){var f,o,s=8*n-i-1,h=(1<>1,l=-7,u=r?n-1:0,g=r?-1:1,y=e[t+u];for(u+=g,f=y&(1<<-l)-1,y>>=-l,l+=s;l>0;f=256*f+e[t+u],u+=g,l-=8);for(o=f&(1<<-l)-1,f>>=-l,l+=i;l>0;o=256*o+e[t+u],u+=g,l-=8);if(0===f)f=1-a;else{if(f===h)return o?NaN:(y?-1:1)*(1/0);o+=Math.pow(2,i),f-=a}return(y?-1:1)*o*Math.pow(2,f-i)}function n(e,t,r,i,n,f){var o,s,h,a=8*f-n-1,l=(1<>1,g=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,y=i?0:f-1,b=i?1:-1,w=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),t+=o+u>=1?g/h:g*Math.pow(2,1-u),t*h>=2&&(o++,h/=2),o+u>=l?(s=0,o=l):o+u>=1?(s=(t*h-1)*Math.pow(2,n),o+=u):(s=t*Math.pow(2,u-1)*Math.pow(2,n),o=0));n>=8;e[r+y]=255&s,y+=b,s/=256,n-=8);for(o=o<0;e[r+y]=255&o,y+=b,o/=256,a-=8);e[r+y-b]|=128*w}var f=function(e,t,r){if("undefined"==typeof e&&(e=f.DEFAULT_CAPACITY),"undefined"==typeof t&&(t=f.DEFAULT_ENDIAN),"undefined"==typeof r&&(r=f.DEFAULT_NOASSERT),!r){if(e=0|e,0>e)throw RangeError("Illegal capacity");t=!!t,r=!!r}this.buffer=0===e?s:new ArrayBuffer(e),this.view=0===e?null:new Uint8Array(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian="undefined"!=typeof t?!!t:!1,this.noAssert=!!r};f.VERSION="5.0.0",f.LITTLE_ENDIAN=!0,f.BIG_ENDIAN=!1,f.DEFAULT_CAPACITY=16,f.DEFAULT_ENDIAN=f.BIG_ENDIAN,f.DEFAULT_NOASSERT=!1,f.Long=e||null;var o=f.prototype;o.__isByteBuffer__,Object.defineProperty(o,"__isByteBuffer__",{value:!0,enumerable:!1,configurable:!1});var s=new ArrayBuffer(0),h=String.fromCharCode;f.accessor=function(){return Uint8Array},f.allocate=function(e,t,r){return new f(e,t,r)},f.concat=function(e,t,r,i){("boolean"==typeof t||"string"!=typeof t)&&(i=r,r=t,t=void 0);for(var n,o=0,s=0,h=e.length;h>s;++s)f.isByteBuffer(e[s])||(e[s]=f.wrap(e[s],t)),n=e[s].limit-e[s].offset,n>0&&(o+=n);if(0===o)return new f(0,r,i);var a,l=new f(o,r,i);for(s=0;h>s;)a=e[s++],n=a.limit-a.offset,0>=n||(l.view.set(a.view.subarray(a.offset,a.limit),l.offset),l.offset+=n);return l.limit=l.offset,l.offset=0,l},f.isByteBuffer=function(e){return(e&&e.__isByteBuffer__)===!0},f.type=function(){return ArrayBuffer},f.wrap=function(e,t,r,i){if("string"!=typeof t&&(i=r,r=t,t=void 0),"string"==typeof e)switch("undefined"==typeof t&&(t="utf8"),t){case"base64":return f.fromBase64(e,r);case"hex":return f.fromHex(e,r);case"binary":return f.fromBinary(e,r);case"utf8":return f.fromUTF8(e,r);case"debug":return f.fromDebug(e,r);default:throw Error("Unsupported encoding: "+t)}if(null===e||"object"!=typeof e)throw TypeError("Illegal buffer");var n;if(f.isByteBuffer(e))return n=o.clone.call(e),n.markedOffset=-1,n;if(e instanceof Uint8Array)n=new f(0,r,i),e.length>0&&(n.buffer=e.buffer,n.offset=e.byteOffset,n.limit=e.byteOffset+e.byteLength,n.view=new Uint8Array(e.buffer));else if(e instanceof ArrayBuffer)n=new f(0,r,i),e.byteLength>0&&(n.buffer=e,n.offset=0,n.limit=e.byteLength,n.view=e.byteLength>0?new Uint8Array(e):null);else{if("[object Array]"!==Object.prototype.toString.call(e))throw TypeError("Illegal buffer");n=new f(e.length,r,i),n.limit=e.length;for(var s=0;s>>=0,0>t||t+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+"+e+") <= "+this.buffer.byteLength)}var i=this.slice(t,t+e);return r&&(this.offset+=e),i},o.writeBytes=o.append,o.writeInt8=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=1,this.view[t]=e,r&&(this.offset+=1),this},o.writeByte=o.writeInt8,o.readInt8=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=this.view[e];return 128===(128&r)&&(r=-(255-r+1)),t&&(this.offset+=1),r},o.readByte=o.readInt8,o.writeUint8=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=1,this.view[t]=e,r&&(this.offset+=1),this},o.writeUInt8=o.writeUint8,o.readUint8=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=this.view[e];return t&&(this.offset+=1),r},o.readUInt8=o.readUint8,o.writeInt16=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),r&&(this.offset+=2),this},o.writeShort=o.writeInt16,o.readInt16=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e],r|=this.view[e+1]<<8):(r=this.view[e]<<8,r|=this.view[e+1]),32768===(32768&r)&&(r=-(65535-r+1)),t&&(this.offset+=2),r},o.readShort=o.readInt16,o.writeUint16=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),r&&(this.offset+=2),this},o.writeUInt16=o.writeUint16,o.readUint16=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e],r|=this.view[e+1]<<8):(r=this.view[e]<<8,r|=this.view[e+1]),t&&(this.offset+=2),r},o.readUInt16=o.readUint16,o.writeInt32=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),r&&(this.offset+=4),this},o.writeInt=o.writeInt32,o.readInt32=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e+2]<<16,r|=this.view[e+1]<<8,r|=this.view[e],r+=this.view[e+3]<<24>>>0):(r=this.view[e+1]<<16,r|=this.view[e+2]<<8,r|=this.view[e+3],r+=this.view[e]<<24>>>0),r|=0,t&&(this.offset+=4),r},o.readInt=o.readInt32,o.writeUint32=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),r&&(this.offset+=4),this},o.writeUInt32=o.writeUint32,o.readUint32=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e+2]<<16,r|=this.view[e+1]<<8,r|=this.view[e],r+=this.view[e+3]<<24>>>0):(r=this.view[e+1]<<16,r|=this.view[e+2]<<8,r|=this.view[e+3],r+=this.view[e]<<24>>>0),t&&(this.offset+=4),r},o.readUInt32=o.readUint32,e&&(o.writeInt64=function(t,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),r+=8;var n=this.buffer.byteLength;r>n&&this.resize((n*=2)>r?n:r),r-=8;var f=t.low,o=t.high;return this.littleEndian?(this.view[r+3]=f>>>24&255,this.view[r+2]=f>>>16&255,this.view[r+1]=f>>>8&255,this.view[r]=255&f,r+=4,this.view[r+3]=o>>>24&255,this.view[r+2]=o>>>16&255,this.view[r+1]=o>>>8&255,this.view[r]=255&o):(this.view[r]=o>>>24&255,this.view[r+1]=o>>>16&255,this.view[r+2]=o>>>8&255,this.view[r+3]=255&o,r+=4,this.view[r]=f>>>24&255,this.view[r+1]=f>>>16&255,this.view[r+2]=f>>>8&255,this.view[r+3]=255&f),i&&(this.offset+=8),this},o.writeLong=o.writeInt64,o.readInt64=function(t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var i=0,n=0;this.littleEndian?(i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0,t+=4,n=this.view[t+2]<<16,n|=this.view[t+1]<<8,n|=this.view[t],n+=this.view[t+3]<<24>>>0):(n=this.view[t+1]<<16,n|=this.view[t+2]<<8,n|=this.view[t+3],n+=this.view[t]<<24>>>0,t+=4,i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0);var f=new e(i,n,!1);return r&&(this.offset+=8),f},o.readLong=o.readInt64,o.writeUint64=function(t,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),r+=8;var n=this.buffer.byteLength;r>n&&this.resize((n*=2)>r?n:r),r-=8;var f=t.low,o=t.high;return this.littleEndian?(this.view[r+3]=f>>>24&255,this.view[r+2]=f>>>16&255,this.view[r+1]=f>>>8&255,this.view[r]=255&f,r+=4,this.view[r+3]=o>>>24&255,this.view[r+2]=o>>>16&255,this.view[r+1]=o>>>8&255,this.view[r]=255&o):(this.view[r]=o>>>24&255,this.view[r+1]=o>>>16&255,this.view[r+2]=o>>>8&255,this.view[r+3]=255&o,r+=4,this.view[r]=f>>>24&255,this.view[r+1]=f>>>16&255,this.view[r+2]=f>>>8&255,this.view[r+3]=255&f),i&&(this.offset+=8),this},o.writeUInt64=o.writeUint64,o.readUint64=function(t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var i=0,n=0;this.littleEndian?(i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0,t+=4,n=this.view[t+2]<<16,n|=this.view[t+1]<<8,n|=this.view[t],n+=this.view[t+3]<<24>>>0):(n=this.view[t+1]<<16,n|=this.view[t+2]<<8,n|=this.view[t+3],n+=this.view[t]<<24>>>0,t+=4,i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0);var f=new e(i,n,!0);return r&&(this.offset+=8),f},o.readUInt64=o.readUint64),o.writeFloat32=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=4,n(this.view,e,t,this.littleEndian,23,4),r&&(this.offset+=4),this},o.writeFloat=o.writeFloat32,o.readFloat32=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=i(this.view,e,this.littleEndian,23,4);return t&&(this.offset+=4),r},o.readFloat=o.readFloat32,o.writeFloat64=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=8;var i=this.buffer.byteLength;return t>i&&this.resize((i*=2)>t?i:t),t-=8,n(this.view,e,t,this.littleEndian,52,8),r&&(this.offset+=8),this},o.writeDouble=o.writeFloat64,o.readFloat64=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+8) <= "+this.buffer.byteLength)}var r=i(this.view,e,this.littleEndian,52,8);return t&&(this.offset+=8),r},o.readDouble=o.readFloat64,f.MAX_VARINT32_BYTES=5,f.calculateVarint32=function(e){return e>>>=0,128>e?1:16384>e?2:1<<21>e?3:1<<28>e?4:5},f.zigZagEncode32=function(e){return((e|=0)<<1^e>>31)>>>0},f.zigZagDecode32=function(e){return e>>>1^-(1&e)|0},o.writeVarint32=function(e,t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var i,n=f.calculateVarint32(e);t+=n;var o=this.buffer.byteLength;for(t>o&&this.resize((o*=2)>t?o:t),t-=n,e>>>=0;e>=128;)i=127&e|128,this.view[t++]=i,e>>>=7;return this.view[t++]=e,r?(this.offset=t,this):n},o.writeVarint32ZigZag=function(e,t){return this.writeVarint32(f.zigZagEncode32(e),t)},o.readVarint32=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r,i=0,n=0;do{if(!this.noAssert&&e>this.limit){var f=Error("Truncated");throw f.truncated=!0,f}r=this.view[e++],5>i&&(n|=(127&r)<<7*i),++i}while(0!==(128&r));return n|=0,t?(this.offset=e,n):{value:n,length:i}},o.readVarint32ZigZag=function(e){var t=this.readVarint32(e);return"object"==typeof t?t.value=f.zigZagDecode32(t.value):t=f.zigZagDecode32(t),t},e&&(f.MAX_VARINT64_BYTES=10,f.calculateVarint64=function(t){"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t));var r=t.toInt()>>>0,i=t.shiftRightUnsigned(28).toInt()>>>0,n=t.shiftRightUnsigned(56).toInt()>>>0;return 0==n?0==i?16384>r?128>r?1:2:1<<21>r?3:4:16384>i?128>i?5:6:1<<21>i?7:8:128>n?9:10},f.zigZagEncode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):t.unsigned!==!1&&(t=t.toSigned()),t.shiftLeft(1).xor(t.shiftRight(63)).toUnsigned()},f.zigZagDecode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):t.unsigned!==!1&&(t=t.toSigned()),t.shiftRightUnsigned(1).xor(t.and(e.ONE).toSigned().negate()).toSigned()},o.writeVarint64=function(t,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):t.unsigned!==!1&&(t=t.toSigned());var n=f.calculateVarint64(t),o=t.toInt()>>>0,s=t.shiftRightUnsigned(28).toInt()>>>0,h=t.shiftRightUnsigned(56).toInt()>>>0;r+=n;var a=this.buffer.byteLength;switch(r>a&&this.resize((a*=2)>r?a:r),r-=n,n){case 10:this.view[r+9]=h>>>7&1;case 9:this.view[r+8]=9!==n?128|h:127&h;case 8:this.view[r+7]=8!==n?s>>>21|128:s>>>21&127;case 7:this.view[r+6]=7!==n?s>>>14|128:s>>>14&127;case 6:this.view[r+5]=6!==n?s>>>7|128:s>>>7&127;case 5:this.view[r+4]=5!==n?128|s:127&s;case 4:this.view[r+3]=4!==n?o>>>21|128:o>>>21&127;case 3:this.view[r+2]=3!==n?o>>>14|128:o>>>14&127;case 2:this.view[r+1]=2!==n?o>>>7|128:o>>>7&127;case 1:this.view[r]=1!==n?128|o:127&o}return i?(this.offset+=n,this):n},o.writeVarint64ZigZag=function(e,t){return this.writeVarint64(f.zigZagEncode64(e),t)},o.readVarint64=function(t){var r="undefined"==typeof t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+1) <= "+this.buffer.byteLength)}var i=t,n=0,f=0,o=0,s=0;if(s=this.view[t++],n=127&s,128&s&&(s=this.view[t++],n|=(127&s)<<7,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],n|=(127&s)<<14,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],n|=(127&s)<<21,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],f=127&s,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],f|=(127&s)<<7,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],f|=(127&s)<<14,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],f|=(127&s)<<21,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],o=127&s,(128&s||this.noAssert&&"undefined"==typeof s)&&(s=this.view[t++],o|=(127&s)<<7,128&s||this.noAssert&&"undefined"==typeof s))))))))))throw Error("Buffer overrun");var h=e.fromBits(n|f<<28,f>>>4|o<<24,!1);return r?(this.offset=t,h):{value:h,length:t-i}},o.readVarint64ZigZag=function(t){var r=this.readVarint64(t);return r&&r.value instanceof e?r.value=f.zigZagDecode64(r.value):r=f.zigZagDecode64(r),r}),o.writeCString=function(e,r){var i="undefined"==typeof r;i&&(r=this.offset);var n,f=e.length;if(!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");for(n=0;f>n;++n)if(0===e.charCodeAt(n))throw RangeError("Illegal str: Contains NULL-characters");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}f=l.calculateUTF16asUTF8(t(e))[1],r+=f+1;var o=this.buffer.byteLength;return r>o&&this.resize((o*=2)>r?o:r),r-=f+1,l.encodeUTF16toUTF8(t(e),function(e){this.view[r++]=e}.bind(this)),this.view[r++]=0,i?(this.offset=r,this):f},o.readCString=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var i,n=e,f=-1;return l.decodeUTF8toUTF16(function(){if(0===f)return null;if(e>=this.limit)throw RangeError("Illegal range: Truncated data, "+e+" < "+this.limit);return f=this.view[e++],0===f?null:f}.bind(this),i=r(),!0),t?(this.offset=e,i()):{string:i(),length:e-n}},o.writeIString=function(e,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var n,f=r;n=l.calculateUTF16asUTF8(t(e),this.noAssert)[1],r+=4+n;var o=this.buffer.byteLength;if(r>o&&this.resize((o*=2)>r?o:r),r-=4+n,this.littleEndian?(this.view[r+3]=n>>>24&255,this.view[r+2]=n>>>16&255,this.view[r+1]=n>>>8&255,this.view[r]=255&n):(this.view[r]=n>>>24&255,this.view[r+1]=n>>>16&255,this.view[r+2]=n>>>8&255,this.view[r+3]=255&n),r+=4,l.encodeUTF16toUTF8(t(e),function(e){this.view[r++]=e}.bind(this)),r!==f+4+n)throw RangeError("Illegal range: Truncated data, "+r+" == "+(r+4+n));return i?(this.offset=r,this):r-f},o.readIString=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=e,i=this.readUint32(e),n=this.readUTF8String(i,f.METRICS_BYTES,e+=4);return e+=n.length,t?(this.offset=e,n.string):{string:n.string,length:e-r}},f.METRICS_CHARS="c",f.METRICS_BYTES="b",o.writeUTF8String=function(e,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var n,f=r;n=l.calculateUTF16asUTF8(t(e))[1],r+=n;var o=this.buffer.byteLength;return r>o&&this.resize((o*=2)>r?o:r),r-=n,l.encodeUTF16toUTF8(t(e),function(e){this.view[r++]=e}.bind(this)),i?(this.offset=r,this):r-f},o.writeString=o.writeUTF8String,f.calculateUTF8Chars=function(e){return l.calculateUTF16asUTF8(t(e))[0]},f.calculateUTF8Bytes=function(e){return l.calculateUTF16asUTF8(t(e))[1]},f.calculateString=f.calculateUTF8Bytes,o.readUTF8String=function(e,t,i){"number"==typeof t&&(i=t,t=void 0);var n="undefined"==typeof i;if(n&&(i=this.offset),"undefined"==typeof t&&(t=f.METRICS_CHARS),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal length: "+e+" (not an integer)");if(e|=0,"number"!=typeof i||i%1!==0)throw TypeError("Illegal offset: "+i+" (not an integer)");if(i>>>=0,0>i||i+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+i+" (+0) <= "+this.buffer.byteLength)}var o,s=0,h=i;if(t===f.METRICS_CHARS){if(o=r(),l.decodeUTF8(function(){return e>s&&i>>=0,0>i||i+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+i+" (+"+e+") <= "+this.buffer.byteLength)}var a=i+e;if(l.decodeUTF8toUTF16(function(){return a>i?this.view[i++]:null}.bind(this),o=r(),this.noAssert),i!==a)throw RangeError("Illegal range: Truncated data, "+i+" == "+a);return n?(this.offset=i,o()):{string:o(),length:i-h}}throw TypeError("Unsupported metrics: "+t)},o.readString=o.readUTF8String,o.writeVString=function(e,r){var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var n,o,s=r;n=l.calculateUTF16asUTF8(t(e),this.noAssert)[1],o=f.calculateVarint32(n),r+=o+n;var h=this.buffer.byteLength;if(r>h&&this.resize((h*=2)>r?h:r),r-=o+n,r+=this.writeVarint32(n,r),l.encodeUTF16toUTF8(t(e),function(e){this.view[r++]=e}.bind(this)),r!==s+n+o)throw RangeError("Illegal range: Truncated data, "+r+" == "+(r+n+o));return i?(this.offset=r,this):r-s},o.readVString=function(e){var t="undefined"==typeof e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=e,i=this.readVarint32(e),n=this.readUTF8String(i.value,f.METRICS_BYTES,e+=i.length);return e+=n.length,t?(this.offset=e,n.string):{string:n.string,length:e-r}},o.append=function(e,t,r){("number"==typeof t||"string"!=typeof t)&&(r=t,t=void 0);var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}e instanceof f||(e=f.wrap(e,t));var n=e.limit-e.offset;if(0>=n)return this;r+=n;var o=this.buffer.byteLength;return r>o&&this.resize((o*=2)>r?o:r),r-=n,this.view.set(e.view.subarray(e.offset,e.limit),r),e.offset+=n,i&&(this.offset+=n),this},o.appendTo=function(e,t){return e.append(this,t),this},o.assert=function(e){return this.noAssert=!e,this},o.capacity=function(){return this.buffer.byteLength},o.clear=function(){return this.offset=0,this.limit=this.buffer.byteLength,this.markedOffset=-1,this},o.clone=function(e){var t=new f(0,this.littleEndian,this.noAssert);return e?(t.buffer=new ArrayBuffer(this.buffer.byteLength),t.view=new Uint8Array(t.buffer)):(t.buffer=this.buffer,t.view=this.view),t.offset=this.offset,t.markedOffset=this.markedOffset,t.limit=this.limit,t},o.compact=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(0===e&&t===this.buffer.byteLength)return this;var r=t-e;if(0===r)return this.buffer=s,this.view=null,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=0,this;var i=new ArrayBuffer(r),n=new Uint8Array(i);return n.set(this.view.subarray(e,t)),this.buffer=i,this.view=n,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=r,this},o.copy=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(e===t)return new f(0,this.littleEndian,this.noAssert);var r=t-e,i=new f(r,this.littleEndian,this.noAssert);return i.offset=0,i.limit=r,i.markedOffset>=0&&(i.markedOffset-=e),this.copyTo(i,0,e,t),i},o.copyTo=function(e,t,r,i){var n,o;if(!this.noAssert&&!f.isByteBuffer(e))throw TypeError("Illegal target: Not a ByteBuffer");if(t=(o="undefined"==typeof t)?e.offset:0|t,r=(n="undefined"==typeof r)?this.offset:0|r,i="undefined"==typeof i?this.limit:0|i,0>t||t>e.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+t+" <= "+e.buffer.byteLength);if(0>r||i>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+r+" <= "+this.buffer.byteLength);var s=i-r;return 0===s?e:(e.ensureCapacity(t+s),e.view.set(this.view.subarray(r,i),t),n&&(this.offset+=s),o&&(e.offset+=s),this)},o.ensureCapacity=function(e){var t=this.buffer.byteLength;return e>t?this.resize((t*=2)>e?t:e):this},o.fill=function(e,t,r){var i="undefined"==typeof t;if(i&&(t=this.offset),"string"==typeof e&&e.length>0&&(e=e.charCodeAt(0)),"undefined"==typeof t&&(t=this.offset),"undefined"==typeof r&&(r=this.limit),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal begin: Not an integer");if(t>>>=0,"number"!=typeof r||r%1!==0)throw TypeError("Illegal end: Not an integer");if(r>>>=0,0>t||t>r||r>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+r+" <= "+this.buffer.byteLength)}if(t>=r)return this;for(;r>t;)this.view[t++]=e;return i&&(this.offset=t),this},o.flip=function(){return this.limit=this.offset,this.offset=0,this},o.mark=function(e){if(e="undefined"==typeof e?this.offset:e,!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+0) <= "+this.buffer.byteLength)}return this.markedOffset=e,this},o.order=function(e){if(!this.noAssert&&"boolean"!=typeof e)throw TypeError("Illegal littleEndian: Not a boolean");return this.littleEndian=!!e,this},o.LE=function(e){ +return this.littleEndian="undefined"!=typeof e?!!e:!0,this},o.BE=function(e){return this.littleEndian="undefined"!=typeof e?!e:!1,this},o.prepend=function(e,t,r){("number"==typeof t||"string"!=typeof t)&&(r=t,t=void 0);var i="undefined"==typeof r;if(i&&(r=this.offset),!this.noAssert){if("number"!=typeof r||r%1!==0)throw TypeError("Illegal offset: "+r+" (not an integer)");if(r>>>=0,0>r||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}e instanceof f||(e=f.wrap(e,t));var n=e.limit-e.offset;if(0>=n)return this;var o=n-r;if(o>0){var s=new ArrayBuffer(this.buffer.byteLength+o),h=new Uint8Array(s);h.set(this.view.subarray(r,this.buffer.byteLength),n),this.buffer=s,this.view=h,this.offset+=o,this.markedOffset>=0&&(this.markedOffset+=o),this.limit+=o,r+=o}else{new Uint8Array(this.buffer)}return this.view.set(e.view.subarray(e.offset,e.limit),r-n),e.offset=e.limit,i&&(this.offset-=n),this},o.prependTo=function(e,t){return e.prepend(this,t),this},o.printDebug=function(e){"function"!=typeof e&&(e=console.log.bind(console)),e(this.toString()+"\n-------------------------------------------------------------------\n"+this.toDebug(!0))},o.remaining=function(){return this.limit-this.offset},o.reset=function(){return this.markedOffset>=0?(this.offset=this.markedOffset,this.markedOffset=-1):this.offset=0,this},o.resize=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal capacity: "+e+" (not an integer)");if(e|=0,0>e)throw RangeError("Illegal capacity: 0 <= "+e)}if(this.buffer.byteLength>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}return e===t?this:(Array.prototype.reverse.call(this.view.subarray(e,t)),this)},o.skip=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal length: "+e+" (not an integer)");e|=0}var t=this.offset+e;if(!this.noAssert&&(0>t||t>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+e+" <= "+this.buffer.byteLength);return this.offset=t,this},o.slice=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var r=this.clone();return r.offset=e,r.limit=t,r},o.toBuffer=function(e){var t=this.offset,r=this.limit;if(!this.noAssert){if("number"!=typeof t||t%1!==0)throw TypeError("Illegal offset: Not an integer");if(t>>>=0,"number"!=typeof r||r%1!==0)throw TypeError("Illegal limit: Not an integer");if(r>>>=0,0>t||t>r||r>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+r+" <= "+this.buffer.byteLength)}if(!e&&0===t&&r===this.buffer.byteLength)return this.buffer;if(t===r)return s;var i=new ArrayBuffer(r-t);return new Uint8Array(i).set(new Uint8Array(this.buffer).subarray(t,r),0),i},o.toArrayBuffer=o.toBuffer,o.toString=function(e,t,r){if("undefined"==typeof e)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";switch("number"==typeof e&&(e="utf8",t=e,r=t),e){case"utf8":return this.toUTF8(t,r);case"base64":return this.toBase64(t,r);case"hex":return this.toHex(t,r);case"binary":return this.toBinary(t,r);case"debug":return this.toDebug();case"columns":return this.toColumns();default:throw Error("Unsupported encoding: "+e)}};var a=function(){for(var e={},t=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],r=[],i=0,n=t.length;n>i;++i)r[t[i]]=i;return e.encode=function(e,r){for(var i,n;null!==(i=e());)r(t[i>>2&63]),n=(3&i)<<4,null!==(i=e())?(n|=i>>4&15,r(t[63&(n|i>>4&15)]),n=(15&i)<<2,null!==(i=e())?(r(t[63&(n|i>>6&3)]),r(t[63&i])):(r(t[63&n]),r(61))):(r(t[63&n]),r(61),r(61))},e.decode=function(e,t){function i(e){throw Error("Illegal character code: "+e)}for(var n,f,o;null!==(n=e());)if(f=r[n],"undefined"==typeof f&&i(n),null!==(n=e())&&(o=r[n],"undefined"==typeof o&&i(n),t(f<<2>>>0|(48&o)>>4),null!==(n=e()))){if(f=r[n],"undefined"==typeof f){if(61===n)break;i(n)}if(t((15&o)<<4>>>0|(60&f)>>2),null!==(n=e())){if(o=r[n],"undefined"==typeof o){if(61===n)break;i(n)}t((3&f)<<6>>>0|o)}}},e.test=function(e){return/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(e)},e}();o.toBase64=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),e=0|e,t=0|t,0>e||t>this.capacity||e>t)throw RangeError("begin, end");var i;return a.encode(function(){return t>e?this.view[e++]:null}.bind(this),i=r()),i()},f.fromBase64=function(e,r){if("string"!=typeof e)throw TypeError("str");var i=new f(e.length/4*3,r),n=0;return a.decode(t(e),function(e){i.view[n++]=e}),i.limit=n,i},f.btoa=function(e){return f.fromBinary(e).toBase64()},f.atob=function(e){return f.fromBase64(e).toBinary()},o.toBinary=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),e|=0,t|=0,0>e||t>this.capacity()||e>t)throw RangeError("begin, end");if(e===t)return"";for(var r=[],i=[];t>e;)r.push(this.view[e++]),r.length>=1024&&(i.push(String.fromCharCode.apply(String,r)),r=[]);return i.join("")+String.fromCharCode.apply(String,r)},f.fromBinary=function(e,t){if("string"!=typeof e)throw TypeError("str");for(var r,i=0,n=e.length,o=new f(n,t);n>i;){if(r=e.charCodeAt(i),r>255)throw RangeError("illegal char code: "+r);o.view[i++]=r}return o.limit=n,o},o.toDebug=function(e){for(var t,r=-1,i=this.buffer.byteLength,n="",f="",o="";i>r;){if(-1!==r&&(t=this.view[r],n+=16>t?"0"+t.toString(16).toUpperCase():t.toString(16).toUpperCase(),e&&(f+=t>32&&127>t?String.fromCharCode(t):".")),++r,e&&r>0&&r%16===0&&r!==i){for(;n.length<51;)n+=" ";o+=n+f+"\n",n=f=""}n+=r===this.offset&&r===this.limit?r===this.markedOffset?"!":"|":r===this.offset?r===this.markedOffset?"[":"<":r===this.limit?r===this.markedOffset?"]":">":r===this.markedOffset?"'":e||0!==r&&r!==i?" ":""}if(e&&" "!==n){for(;n.length<51;)n+=" ";o+=n+f+"\n"}return e?o:n},f.fromDebug=function(e,t,r){for(var i,n,o=e.length,s=new f((o+1)/3|0,t,r),h=0,a=0,l=!1,u=!1,g=!1,y=!1,b=!1;o>h;){switch(i=e.charAt(h++)){case"!":if(!r){if(u||g||y){b=!0;break}u=g=y=!0}s.offset=s.markedOffset=s.limit=a,l=!1;break;case"|":if(!r){if(u||y){b=!0;break}u=y=!0}s.offset=s.limit=a,l=!1;break;case"[":if(!r){if(u||g){b=!0;break}u=g=!0}s.offset=s.markedOffset=a,l=!1;break;case"<":if(!r){if(u){b=!0;break}u=!0}s.offset=a,l=!1;break;case"]":if(!r){if(y||g){b=!0;break}y=g=!0}s.limit=s.markedOffset=a,l=!1;break;case">":if(!r){if(y){b=!0;break}y=!0}s.limit=a,l=!1;break;case"'":if(!r){if(g){b=!0;break}g=!0}s.markedOffset=a,l=!1;break;case" ":l=!1;break;default:if(!r&&l){b=!0;break}if(n=parseInt(i+e.charAt(h++),16),!r&&(isNaN(n)||0>n||n>255))throw TypeError("Illegal str: Not a debug encoded string");s.view[a++]=n,l=!0}if(b)throw TypeError("Illegal str: Invalid symbol at "+h)}if(!r){if(!u||!y)throw TypeError("Illegal str: Missing offset or limit");if(a>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}for(var r,i=new Array(t-e);t>e;)r=this.view[e++],16>r?i.push("0",r.toString(16)):i.push(r.toString(16));return i.join("")},f.fromHex=function(e,t,r){if(!r){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if(e.length%2!==0)throw TypeError("Illegal str: Length not a multiple of 2")}for(var i,n=e.length,o=new f(n/2|0,t),s=0,h=0;n>s;s+=2){if(i=parseInt(e.substring(s,s+2),16),!r&&(!isFinite(i)||0>i||i>255))throw TypeError("Illegal str: Contains non-hex characters");o.view[h++]=i}return o.limit=h,o};var l=function(){var e={};return e.MAX_CODEPOINT=1114111,e.encodeUTF8=function(e,t){var r=null;for("number"==typeof e&&(r=e,e=function(){return null});null!==r||null!==(r=e());)128>r?t(127&r):2048>r?(t(r>>6&31|192),t(63&r|128)):65536>r?(t(r>>12&15|224),t(r>>6&63|128),t(63&r|128)):(t(r>>18&7|240),t(r>>12&63|128),t(r>>6&63|128),t(63&r|128)),r=null},e.decodeUTF8=function(e,t){for(var r,i,n,f,o=function(e){e=e.slice(0,e.indexOf(null));var t=Error(e.toString());throw t.name="TruncatedError",t.bytes=e,t};null!==(r=e());)if(0===(128&r))t(r);else if(192===(224&r))null===(i=e())&&o([r,i]),t((31&r)<<6|63&i);else if(224===(240&r))(null===(i=e())||null===(n=e()))&&o([r,i,n]),t((15&r)<<12|(63&i)<<6|63&n);else{if(240!==(248&r))throw RangeError("Illegal starting byte: "+r);(null===(i=e())||null===(n=e())||null===(f=e()))&&o([r,i,n,f]),t((7&r)<<18|(63&i)<<12|(63&n)<<6|63&f)}},e.UTF16toUTF8=function(e,t){for(var r,i=null;;){if(null===(r=null!==i?i:e()))break;r>=55296&&57343>=r&&null!==(i=e())&&i>=56320&&57343>=i?(t(1024*(r-55296)+i-56320+65536),i=null):t(r)}null!==i&&t(i)},e.UTF8toUTF16=function(e,t){var r=null;for("number"==typeof e&&(r=e,e=function(){return null});null!==r||null!==(r=e());)65535>=r?t(r):(r-=65536,t((r>>10)+55296),t(r%1024+56320)),r=null},e.encodeUTF16toUTF8=function(t,r){e.UTF16toUTF8(t,function(t){e.encodeUTF8(t,r)})},e.decodeUTF8toUTF16=function(t,r){e.decodeUTF8(t,function(t){e.UTF8toUTF16(t,r)})},e.calculateCodePoint=function(e){return 128>e?1:2048>e?2:65536>e?3:4},e.calculateUTF8=function(e){for(var t,r=0;null!==(t=e());)r+=128>t?1:2048>t?2:65536>t?3:4;return r},e.calculateUTF16asUTF8=function(t){var r=0,i=0;return e.UTF16toUTF8(t,function(e){++r,i+=128>e?1:2048>e?2:65536>e?3:4}),[r,i]},e}();return o.toUTF8=function(e,t){if("undefined"==typeof e&&(e=this.offset),"undefined"==typeof t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!==0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!==0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var i;try{l.decodeUTF8toUTF16(function(){return t>e?this.view[e++]:null}.bind(this),i=r())}catch(n){if(e!==t)throw RangeError("Illegal range: Truncated data, "+e+" != "+t)}return i()},f.fromUTF8=function(e,r,i){if(!i&&"string"!=typeof e)throw TypeError("Illegal str: Not a string");var n=new f(l.calculateUTF16asUTF8(t(e),!0)[1],r,i),o=0;return l.encodeUTF16toUTF8(t(e),function(e){n.view[o++]=e}),n.limit=o,n},f}); +},{"long":23}],23:[function(require,module,exports){ +!function(i,t){"function"==typeof define&&define.amd?define([],t):"function"==typeof require&&"object"==typeof module&&module&&module.exports?module.exports=t():(i.dcodeIO=i.dcodeIO||{}).Long=t()}(this,function(){"use strict";function i(i,t,n){this.low=0|i,this.high=0|t,this.unsigned=!!n}i.__isLong__,Object.defineProperty(i.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),i.isLong=function(i){return(i&&i.__isLong__)===!0};var t={},n={};i.fromInt=function(e,r){var s,h,o;return r?(e>>>=0,(o=e>=0&&256>e)&&(h=n[e])?h:(s=new i(e,0>(0|e)?-1:0,!0),o&&(n[e]=s),s)):(e=0|e,(o=e>=-128&&128>e)&&(h=t[e])?h:(s=new i(e,0>e?-1:0,!1),o&&(t[e]=s),s))},i.fromNumber=function(t,n){return n=!!n,isNaN(t)||!isFinite(t)?i.ZERO:!n&&-o>=t?i.MIN_VALUE:!n&&t+1>=o?i.MAX_VALUE:n&&t>=h?i.MAX_UNSIGNED_VALUE:0>t?i.fromNumber(-t,n).neg():new i(t%s|0,t/s|0,n)},i.fromBits=function(t,n,e){return new i(t,n,e)},i.fromString=function(t,n,e){if(0===t.length)throw Error("number format error: empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return i.ZERO;if("number"==typeof n&&(e=n,n=!1),e=e||10,2>e||e>36)throw Error("radix out of range: "+e);var r;if((r=t.indexOf("-"))>0)throw Error('number format error: interior "-" character: '+t);if(0===r)return i.fromString(t.substring(1),n,e).neg();for(var s=i.fromNumber(Math.pow(e,8)),h=i.ZERO,o=0;ou){var f=i.fromNumber(Math.pow(e,u));h=h.mul(f).add(i.fromNumber(g))}else h=h.mul(s),h=h.add(i.fromNumber(g))}return h.unsigned=n,h},i.fromValue=function(t){return t instanceof i?t:"number"==typeof t?i.fromNumber(t):"string"==typeof t?i.fromString(t):new i(t.low,t.high,t.unsigned)};var e=65536,r=1<<24,s=e*e,h=s*s,o=h/2,u=i.fromInt(r);i.ZERO=i.fromInt(0),i.UZERO=i.fromInt(0,!0),i.ONE=i.fromInt(1),i.UONE=i.fromInt(1,!0),i.NEG_ONE=i.fromInt(-1),i.MAX_VALUE=new i(-1,2147483647,!1),i.MAX_UNSIGNED_VALUE=new i(-1,-1,!0),i.MIN_VALUE=new i(0,-2147483648,!1);var g=i.prototype;return g.toInt=function(){return this.unsigned?this.low>>>0:this.low},g.toNumber=function(){return this.unsigned?(this.high>>>0)*s+(this.low>>>0):this.high*s+(this.low>>>0)},g.toString=function(t){if(t=t||10,2>t||t>36)throw RangeError("radix out of range: "+t);if(this.isZero())return"0";var n;if(this.isNegative()){if(this.eq(i.MIN_VALUE)){var e=i.fromNumber(t),r=this.div(e);return n=r.mul(e).sub(this),r.toString(t)+n.toInt().toString(t)}return"-"+this.neg().toString(t)}var s=i.fromNumber(Math.pow(t,6),this.unsigned);n=this;for(var h="";;){var o=n.div(s),u=n.sub(o.mul(s)).toInt()>>>0,g=u.toString(t);if(n=o,n.isZero())return g+h;for(;g.length<6;)g="0"+g;h=""+g+h}},g.getHighBits=function(){return this.high},g.getHighBitsUnsigned=function(){return this.high>>>0},g.getLowBits=function(){return this.low},g.getLowBitsUnsigned=function(){return this.low>>>0},g.getNumBitsAbs=function(){if(this.isNegative())return this.eq(i.MIN_VALUE)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,n=31;n>0&&0==(t&1<=0},g.isOdd=function(){return 1===(1&this.low)},g.isEven=function(){return 0===(1&this.low)},g.equals=function(t){return i.isLong(t)||(t=i.fromValue(t)),this.unsigned!==t.unsigned&&this.high>>>31===1&&t.high>>>31===1?!1:this.high===t.high&&this.low===t.low},g.eq=g.equals,g.notEquals=function(i){return!this.eq(i)},g.neq=g.notEquals,g.lessThan=function(i){return this.compare(i)<0},g.lt=g.lessThan,g.lessThanOrEqual=function(i){return this.compare(i)<=0},g.lte=g.lessThanOrEqual,g.greaterThan=function(i){return this.compare(i)>0},g.gt=g.greaterThan,g.greaterThanOrEqual=function(i){return this.compare(i)>=0},g.gte=g.greaterThanOrEqual,g.compare=function(t){if(i.isLong(t)||(t=i.fromValue(t)),this.eq(t))return 0;var n=this.isNegative(),e=t.isNegative();return n&&!e?-1:!n&&e?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},g.comp=g.compare,g.negate=function(){return!this.unsigned&&this.eq(i.MIN_VALUE)?i.MIN_VALUE:this.not().add(i.ONE)},g.neg=g.negate,g.add=function(t){i.isLong(t)||(t=i.fromValue(t));var n=this.high>>>16,e=65535&this.high,r=this.low>>>16,s=65535&this.low,h=t.high>>>16,o=65535&t.high,u=t.low>>>16,g=65535&t.low,f=0,a=0,l=0,m=0;return m+=s+g,l+=m>>>16,m&=65535,l+=r+u,a+=l>>>16,l&=65535,a+=e+o,f+=a>>>16,a&=65535,f+=n+h,f&=65535,new i(l<<16|m,f<<16|a,this.unsigned)},g.subtract=function(t){return i.isLong(t)||(t=i.fromValue(t)),this.add(t.neg())},g.sub=g.subtract,g.multiply=function(t){if(this.isZero())return i.ZERO;if(i.isLong(t)||(t=i.fromValue(t)),t.isZero())return i.ZERO;if(this.eq(i.MIN_VALUE))return t.isOdd()?i.MIN_VALUE:i.ZERO;if(t.eq(i.MIN_VALUE))return this.isOdd()?i.MIN_VALUE:i.ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(u)&&t.lt(u))return i.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);var n=this.high>>>16,e=65535&this.high,r=this.low>>>16,s=65535&this.low,h=t.high>>>16,o=65535&t.high,g=t.low>>>16,f=65535&t.low,a=0,l=0,m=0,d=0;return d+=s*f,m+=d>>>16,d&=65535,m+=r*f,l+=m>>>16,m&=65535,m+=s*g,l+=m>>>16,m&=65535,l+=e*f,a+=l>>>16,l&=65535,l+=r*g,a+=l>>>16,l&=65535,l+=s*o,a+=l>>>16,l&=65535,a+=n*f+e*g+r*o+s*h,a&=65535,new i(m<<16|d,a<<16|l,this.unsigned)},g.mul=g.multiply,g.divide=function(t){if(i.isLong(t)||(t=i.fromValue(t)),t.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?i.UZERO:i.ZERO;var n,e,r;if(this.eq(i.MIN_VALUE)){if(t.eq(i.ONE)||t.eq(i.NEG_ONE))return i.MIN_VALUE;if(t.eq(i.MIN_VALUE))return i.ONE;var s=this.shr(1);return n=s.div(t).shl(1),n.eq(i.ZERO)?t.isNegative()?i.ONE:i.NEG_ONE:(e=this.sub(t.mul(n)),r=n.add(e.div(t)))}if(t.eq(i.MIN_VALUE))return this.unsigned?i.UZERO:i.ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();for(r=i.ZERO,e=this;e.gte(t);){n=Math.max(1,Math.floor(e.toNumber()/t.toNumber()));for(var h=Math.ceil(Math.log(n)/Math.LN2),o=48>=h?1:Math.pow(2,h-48),u=i.fromNumber(n),g=u.mul(t);g.isNegative()||g.gt(e);)n-=o,u=i.fromNumber(n,this.unsigned),g=u.mul(t);u.isZero()&&(u=i.ONE),r=r.add(u),e=e.sub(g)}return r},g.div=g.divide,g.modulo=function(t){return i.isLong(t)||(t=i.fromValue(t)),this.sub(this.div(t).mul(t))},g.mod=g.modulo,g.not=function(){return new i(~this.low,~this.high,this.unsigned)},g.and=function(t){return i.isLong(t)||(t=i.fromValue(t)),new i(this.low&t.low,this.high&t.high,this.unsigned)},g.or=function(t){return i.isLong(t)||(t=i.fromValue(t)),new i(this.low|t.low,this.high|t.high,this.unsigned)},g.xor=function(t){return i.isLong(t)||(t=i.fromValue(t)),new i(this.low^t.low,this.high^t.high,this.unsigned)},g.shiftLeft=function(t){return i.isLong(t)&&(t=t.toInt()),0===(t&=63)?this:32>t?new i(this.low<>>32-t,this.unsigned):new i(0,this.low<t?new i(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):new i(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},g.shr=g.shiftRight,g.shiftRightUnsigned=function(t){if(i.isLong(t)&&(t=t.toInt()),t&=63,0===t)return this;var n=this.high;if(32>t){var e=this.low;return new i(e>>>t|n<<32-t,n>>>t,this.unsigned)}return 32===t?new i(n,0,this.unsigned):new i(n>>>t-32,0,this.unsigned)},g.shru=g.shiftRightUnsigned,g.toSigned=function(){return this.unsigned?new i(this.low,this.high,!1):this},g.toUnsigned=function(){return this.unsigned?this:new i(this.low,this.high,!0)},i}); +},{}]},{},[18])(18) +}); + + +//# sourceMappingURL=machinetalk-protobuf.min.map.json \ No newline at end of file diff --git a/dist/machinetalk-protobuf.min.js.gz b/dist/machinetalk-protobuf.min.js.gz new file mode 100644 index 0000000000000000000000000000000000000000..3dfc9ad337d4e346c64e866af62a76c870747263 GIT binary patch literal 70104 zcmdQ~!;&xzj2zpxZQHiz8{4*R+qP}nwr$(qe{cH=dr4PyE`3QV-BrPlf`9-IO#KH0 zY-3<#ZeeTUY+!9gYwu|1Y-i|VN@rtXOK0f>aIB-{w8fF?yQg=sDjcVCBO8%Vp)t|f zY985|AyFJ!d~K{miAK8s*G0NmC4Cq@_U8kL&C zM}4~0O%r=3pZoN6bQ3pL-OWFli#PS+>g4OYOL^xzbGkJ<$A46z+ObaCl(#=!t8V<} zkwD8uKKF8tE#&6s{g_D0zJaLKI9iB0k!nBVc`w_kna#7-7sv0%*;5yh*H>~?6y|0f zap%!M(Kn^VpS^bU7z#i2NTC4IK@zhS&cCvGe_sg9)GBv@7`Yh>E>zTHsXk@lL_L zn~PR<5RuvkdZCLaF>+8SEa=j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\r\n\r\n Licensed under the Apache License, Version 2.0 (the \"License\");\r\n you may not use this file except in compliance with the License.\r\n You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License.\r\n */\r\n\r\n/**\r\n * @license protobuf.js (c) 2013 Daniel Wirtz \r\n * Released under the Apache License, Version 2.0\r\n * see: https://github.com/dcodeIO/protobuf.js for details\r\n */\r\n(function(global, factory) {\r\n\r\n /* AMD */ if (typeof define === 'function' && define[\"amd\"])\r\n define([\"bytebuffer\"], factory);\r\n /* CommonJS */ else if (typeof require === \"function\" && typeof module === \"object\" && module && module[\"exports\"])\r\n module[\"exports\"] = factory(require(\"bytebuffer\"), true);\r\n /* Global */ else\r\n (global[\"dcodeIO\"] = global[\"dcodeIO\"] || {})[\"ProtoBuf\"] = factory(global[\"dcodeIO\"][\"ByteBuffer\"]);\r\n\r\n})(this, function(ByteBuffer, isCommonJS) {\r\n \"use strict\";\r\n\r\n /**\r\n * The ProtoBuf namespace.\r\n * @exports ProtoBuf\r\n * @namespace\r\n * @expose\r\n */\r\n var ProtoBuf = {};\r\n\r\n /**\r\n * @type {!function(new: ByteBuffer, ...[*])}\r\n * @expose\r\n */\r\n ProtoBuf.ByteBuffer = ByteBuffer;\r\n\r\n /**\r\n * @type {?function(new: Long, ...[*])}\r\n * @expose\r\n */\r\n ProtoBuf.Long = ByteBuffer.Long || null;\r\n\r\n /**\r\n * ProtoBuf.js version.\r\n * @type {string}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.VERSION = \"5.0.0\";\r\n\r\n /**\r\n * Wire types.\r\n * @type {Object.}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES = {};\r\n\r\n /**\r\n * Varint wire type.\r\n * @type {number}\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.VARINT = 0;\r\n\r\n /**\r\n * Fixed 64 bits wire type.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.BITS64 = 1;\r\n\r\n /**\r\n * Length delimited wire type.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.LDELIM = 2;\r\n\r\n /**\r\n * Start group wire type.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.STARTGROUP = 3;\r\n\r\n /**\r\n * End group wire type.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.ENDGROUP = 4;\r\n\r\n /**\r\n * Fixed 32 bits wire type.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.WIRE_TYPES.BITS32 = 5;\r\n\r\n /**\r\n * Packable wire types.\r\n * @type {!Array.}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.PACKABLE_WIRE_TYPES = [\r\n ProtoBuf.WIRE_TYPES.VARINT,\r\n ProtoBuf.WIRE_TYPES.BITS64,\r\n ProtoBuf.WIRE_TYPES.BITS32\r\n ];\r\n\r\n /**\r\n * Types.\r\n * @dict\r\n * @type {!Object.}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.TYPES = {\r\n // According to the protobuf spec.\r\n \"int32\": {\r\n name: \"int32\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: 0\r\n },\r\n \"uint32\": {\r\n name: \"uint32\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: 0\r\n },\r\n \"sint32\": {\r\n name: \"sint32\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: 0\r\n },\r\n \"int64\": {\r\n name: \"int64\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r\n },\r\n \"uint64\": {\r\n name: \"uint64\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined\r\n },\r\n \"sint64\": {\r\n name: \"sint64\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r\n },\r\n \"bool\": {\r\n name: \"bool\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: false\r\n },\r\n \"double\": {\r\n name: \"double\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS64,\r\n defaultValue: 0\r\n },\r\n \"string\": {\r\n name: \"string\",\r\n wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r\n defaultValue: \"\"\r\n },\r\n \"bytes\": {\r\n name: \"bytes\",\r\n wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r\n defaultValue: null // overridden in the code, must be a unique instance\r\n },\r\n \"fixed32\": {\r\n name: \"fixed32\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS32,\r\n defaultValue: 0\r\n },\r\n \"sfixed32\": {\r\n name: \"sfixed32\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS32,\r\n defaultValue: 0\r\n },\r\n \"fixed64\": {\r\n name: \"fixed64\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS64,\r\n defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined\r\n },\r\n \"sfixed64\": {\r\n name: \"sfixed64\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS64,\r\n defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r\n },\r\n \"float\": {\r\n name: \"float\",\r\n wireType: ProtoBuf.WIRE_TYPES.BITS32,\r\n defaultValue: 0\r\n },\r\n \"enum\": {\r\n name: \"enum\",\r\n wireType: ProtoBuf.WIRE_TYPES.VARINT,\r\n defaultValue: 0\r\n },\r\n \"message\": {\r\n name: \"message\",\r\n wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r\n defaultValue: null\r\n },\r\n \"group\": {\r\n name: \"group\",\r\n wireType: ProtoBuf.WIRE_TYPES.STARTGROUP,\r\n defaultValue: null\r\n }\r\n };\r\n\r\n /**\r\n * Valid map key types.\r\n * @type {!Array.>}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.MAP_KEY_TYPES = [\r\n ProtoBuf.TYPES[\"int32\"],\r\n ProtoBuf.TYPES[\"sint32\"],\r\n ProtoBuf.TYPES[\"sfixed32\"],\r\n ProtoBuf.TYPES[\"uint32\"],\r\n ProtoBuf.TYPES[\"fixed32\"],\r\n ProtoBuf.TYPES[\"int64\"],\r\n ProtoBuf.TYPES[\"sint64\"],\r\n ProtoBuf.TYPES[\"sfixed64\"],\r\n ProtoBuf.TYPES[\"uint64\"],\r\n ProtoBuf.TYPES[\"fixed64\"],\r\n ProtoBuf.TYPES[\"bool\"],\r\n ProtoBuf.TYPES[\"string\"],\r\n ProtoBuf.TYPES[\"bytes\"]\r\n ];\r\n\r\n /**\r\n * Minimum field id.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.ID_MIN = 1;\r\n\r\n /**\r\n * Maximum field id.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ProtoBuf.ID_MAX = 0x1FFFFFFF;\r\n\r\n /**\r\n * If set to `true`, field names will be converted from underscore notation to camel case. Defaults to `false`.\r\n * Must be set prior to parsing.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n ProtoBuf.convertFieldsToCamelCase = false;\r\n\r\n /**\r\n * By default, messages are populated with (setX, set_x) accessors for each field. This can be disabled by\r\n * setting this to `false` prior to building messages.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n ProtoBuf.populateAccessors = true;\r\n\r\n /**\r\n * By default, messages are populated with default values if a field is not present on the wire. To disable\r\n * this behavior, set this setting to `false`.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n ProtoBuf.populateDefaults = true;\r\n\r\n /**\n * @alias ProtoBuf.Util\n * @expose\n */\n ProtoBuf.Util = (function() {\n \"use strict\";\n\n /**\n * ProtoBuf utilities.\n * @exports ProtoBuf.Util\n * @namespace\n */\n var Util = {};\n\n /**\n * Flag if running in node or not.\n * @type {boolean}\n * @const\n * @expose\n */\n Util.IS_NODE = !!(\n typeof process === 'object' && process+'' === '[object process]' && !process['browser']\n );\n\n /**\n * Constructs a XMLHttpRequest object.\n * @return {XMLHttpRequest}\n * @throws {Error} If XMLHttpRequest is not supported\n * @expose\n */\n Util.XHR = function() {\n // No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html\n var XMLHttpFactories = [\n function () {return new XMLHttpRequest()},\n function () {return new ActiveXObject(\"Msxml2.XMLHTTP\")},\n function () {return new ActiveXObject(\"Msxml3.XMLHTTP\")},\n function () {return new ActiveXObject(\"Microsoft.XMLHTTP\")}\n ];\n /** @type {?XMLHttpRequest} */\n var xhr = null;\n for (var i=0;i}\r\n * @expose\r\n */\r\n ProtoBuf.Lang = {\r\n\r\n // Characters always ending a statement\r\n DELIM: /[\\s\\{\\}=;:\\[\\],'\"\\(\\)<>]/g,\r\n\r\n // Field rules\r\n RULE: /^(?:required|optional|repeated|map)$/,\r\n\r\n // Field types\r\n TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,\r\n\r\n // Names\r\n NAME: /^[a-zA-Z_][a-zA-Z_0-9]*$/,\r\n\r\n // Type definitions\r\n TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/,\r\n\r\n // Type references\r\n TYPEREF: /^(?:\\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,\r\n\r\n // Fully qualified type references\r\n FQTYPEREF: /^(?:\\.[a-zA-Z][a-zA-Z_0-9]*)+$/,\r\n\r\n // All numbers\r\n NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,\r\n\r\n // Decimal numbers\r\n NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/,\r\n\r\n // Hexadecimal numbers\r\n NUMBER_HEX: /^0[xX][0-9a-fA-F]+$/,\r\n\r\n // Octal numbers\r\n NUMBER_OCT: /^0[0-7]+$/,\r\n\r\n // Floating point numbers\r\n NUMBER_FLT: /^([0-9]*(\\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,\r\n\r\n // Booleans\r\n BOOL: /^(?:true|false)$/i,\r\n\r\n // Id numbers\r\n ID: /^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,\r\n\r\n // Negative id numbers (enum values)\r\n NEGID: /^\\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,\r\n\r\n // Whitespaces\r\n WHITESPACE: /\\s/,\r\n\r\n // All strings\r\n STRING: /(?:\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\")|(?:'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)')/g,\r\n\r\n // Double quoted strings\r\n STRING_DQ: /(?:\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\")/g,\r\n\r\n // Single quoted strings\r\n STRING_SQ: /(?:'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)')/g\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.DotProto\r\n * @expose\r\n */\r\n ProtoBuf.DotProto = (function(ProtoBuf, Lang) {\r\n \"use strict\";\r\n\r\n /**\r\n * Utilities to parse .proto files.\r\n * @exports ProtoBuf.DotProto\r\n * @namespace\r\n */\r\n var DotProto = {};\r\n\r\n /**\r\n * Constructs a new Tokenizer.\r\n * @exports ProtoBuf.DotProto.Tokenizer\r\n * @class prototype tokenizer\r\n * @param {string} proto Proto to tokenize\r\n * @constructor\r\n */\r\n var Tokenizer = function(proto) {\r\n\r\n /**\r\n * Source to parse.\r\n * @type {string}\r\n * @expose\r\n */\r\n this.source = proto+\"\";\r\n\r\n /**\r\n * Current index.\r\n * @type {number}\r\n * @expose\r\n */\r\n this.index = 0;\r\n\r\n /**\r\n * Current line.\r\n * @type {number}\r\n * @expose\r\n */\r\n this.line = 1;\r\n\r\n /**\r\n * Token stack.\r\n * @type {!Array.}\r\n * @expose\r\n */\r\n this.stack = [];\r\n\r\n /**\r\n * Opening character of the current string read, if any.\r\n * @type {?string}\r\n * @private\r\n */\r\n this._stringOpen = null;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.DotProto.Tokenizer.prototype\r\n * @inner\r\n */\r\n var TokenizerPrototype = Tokenizer.prototype;\r\n\r\n /**\r\n * Reads a string beginning at the current index.\r\n * @return {string}\r\n * @private\r\n */\r\n TokenizerPrototype._readString = function() {\r\n var re = this._stringOpen === '\"'\r\n ? Lang.STRING_DQ\r\n : Lang.STRING_SQ;\r\n re.lastIndex = this.index - 1; // Include the open quote\r\n var match = re.exec(this.source);\r\n if (!match)\r\n throw Error(\"unterminated string\");\r\n this.index = re.lastIndex;\r\n this.stack.push(this._stringOpen);\r\n this._stringOpen = null;\r\n return match[1];\r\n };\r\n\r\n /**\r\n * Gets the next token and advances by one.\r\n * @return {?string} Token or `null` on EOF\r\n * @expose\r\n */\r\n TokenizerPrototype.next = function() {\r\n if (this.stack.length > 0)\r\n return this.stack.shift();\r\n if (this.index >= this.source.length)\r\n return null;\r\n if (this._stringOpen !== null)\r\n return this._readString();\r\n\r\n var repeat,\r\n prev,\r\n next;\r\n do {\r\n repeat = false;\r\n\r\n // Strip white spaces\r\n while (Lang.WHITESPACE.test(next = this.source.charAt(this.index))) {\r\n if (next === '\\n')\r\n ++this.line;\r\n if (++this.index === this.source.length)\r\n return null;\r\n }\r\n\r\n // Strip comments\r\n if (this.source.charAt(this.index) === '/') {\r\n ++this.index;\r\n if (this.source.charAt(this.index) === '/') { // Line\r\n while (this.source.charAt(++this.index) !== '\\n')\r\n if (this.index == this.source.length)\r\n return null;\r\n ++this.index;\r\n ++this.line;\r\n repeat = true;\r\n } else if ((next = this.source.charAt(this.index)) === '*') { /* Block */\r\n do {\r\n if (next === '\\n')\r\n ++this.line;\r\n if (++this.index === this.source.length)\r\n return null;\r\n prev = next;\r\n next = this.source.charAt(this.index);\r\n } while (prev !== '*' || next !== '/');\r\n ++this.index;\r\n repeat = true;\r\n } else\r\n return '/';\r\n }\r\n } while (repeat);\r\n\r\n if (this.index === this.source.length)\r\n return null;\r\n\r\n // Read the next token\r\n var end = this.index;\r\n Lang.DELIM.lastIndex = 0;\r\n var delim = Lang.DELIM.test(this.source.charAt(end++));\r\n if (!delim)\r\n while(end < this.source.length && !Lang.DELIM.test(this.source.charAt(end)))\r\n ++end;\r\n var token = this.source.substring(this.index, this.index = end);\r\n if (token === '\"' || token === \"'\")\r\n this._stringOpen = token;\r\n return token;\r\n };\r\n\r\n /**\r\n * Peeks for the next token.\r\n * @return {?string} Token or `null` on EOF\r\n * @expose\r\n */\r\n TokenizerPrototype.peek = function() {\r\n if (this.stack.length === 0) {\r\n var token = this.next();\r\n if (token === null)\r\n return null;\r\n this.stack.push(token);\r\n }\r\n return this.stack[0];\r\n };\r\n\r\n /**\r\n * Skips a specific token and throws if it differs.\r\n * @param {string} expected Expected token\r\n * @throws {Error} If the actual token differs\r\n */\r\n TokenizerPrototype.skip = function(expected) {\r\n var actual = this.next();\r\n if (actual !== expected)\r\n throw Error(\"illegal '\"+actual+\"', '\"+expected+\"' expected\");\r\n };\r\n\r\n /**\r\n * Omits an optional token.\r\n * @param {string} expected Expected optional token\r\n * @returns {boolean} `true` if the token exists\r\n */\r\n TokenizerPrototype.omit = function(expected) {\r\n if (this.peek() === expected) {\r\n this.next();\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n /**\r\n * Returns a string representation of this object.\r\n * @return {string} String representation as of \"Tokenizer(index/length)\"\r\n * @expose\r\n */\r\n TokenizerPrototype.toString = function() {\r\n return \"Tokenizer (\"+this.index+\"/\"+this.source.length+\" at line \"+this.line+\")\";\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.DotProto.Tokenizer\r\n * @expose\r\n */\r\n DotProto.Tokenizer = Tokenizer;\r\n\r\n /**\r\n * Constructs a new Parser.\r\n * @exports ProtoBuf.DotProto.Parser\r\n * @class prototype parser\r\n * @param {string} source Source\r\n * @constructor\r\n */\r\n var Parser = function(source) {\r\n\r\n /**\r\n * Tokenizer.\r\n * @type {!ProtoBuf.DotProto.Tokenizer}\r\n * @expose\r\n */\r\n this.tn = new Tokenizer(source);\r\n\r\n /**\r\n * Whether parsing proto3 or not.\r\n * @type {boolean}\r\n */\r\n this.proto3 = false;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.DotProto.Parser.prototype\r\n * @inner\r\n */\r\n var ParserPrototype = Parser.prototype;\r\n\r\n /**\r\n * Parses the source.\r\n * @returns {!Object}\r\n * @throws {Error} If the source cannot be parsed\r\n * @expose\r\n */\r\n ParserPrototype.parse = function() {\r\n var topLevel = {\r\n \"name\": \"[ROOT]\", // temporary\r\n \"package\": null,\r\n \"messages\": [],\r\n \"enums\": [],\r\n \"imports\": [],\r\n \"options\": {},\r\n \"services\": []\r\n // \"syntax\": undefined\r\n };\r\n var token,\r\n head = true;\r\n try {\r\n while (token = this.tn.next()) {\r\n switch (token) {\r\n case 'package':\r\n if (!head || topLevel[\"package\"] !== null)\r\n throw Error(\"unexpected 'package'\");\r\n token = this.tn.next();\r\n if (!Lang.TYPEREF.test(token))\r\n throw Error(\"illegal package name: \" + token);\r\n this.tn.skip(\";\");\r\n topLevel[\"package\"] = token;\r\n break;\r\n case 'import':\r\n if (!head)\r\n throw Error(\"unexpected 'import'\");\r\n token = this.tn.peek();\r\n if (token === \"public\") // ignored\r\n this.tn.next();\r\n token = this._readString();\r\n this.tn.skip(\";\");\r\n topLevel[\"imports\"].push(token);\r\n break;\r\n case 'syntax':\r\n if (!head)\r\n throw Error(\"unexpected 'syntax'\");\r\n this.tn.skip(\"=\");\r\n if ((topLevel[\"syntax\"] = this._readString()) === \"proto3\")\r\n this.proto3 = true;\r\n this.tn.skip(\";\");\r\n break;\r\n case 'message':\r\n this._parseMessage(topLevel, null);\r\n head = false;\r\n break;\r\n case 'enum':\r\n this._parseEnum(topLevel);\r\n head = false;\r\n break;\r\n case 'option':\r\n this._parseOption(topLevel);\r\n break;\r\n case 'service':\r\n this._parseService(topLevel);\r\n break;\r\n case 'extend':\r\n this._parseExtend(topLevel);\r\n break;\r\n default:\r\n throw Error(\"unexpected '\" + token + \"'\");\r\n }\r\n }\r\n } catch (e) {\r\n e.message = \"Parse error at line \"+this.tn.line+\": \" + e.message;\r\n throw e;\r\n }\r\n delete topLevel[\"name\"];\r\n return topLevel;\r\n };\r\n\r\n /**\r\n * Parses the specified source.\r\n * @returns {!Object}\r\n * @throws {Error} If the source cannot be parsed\r\n * @expose\r\n */\r\n Parser.parse = function(source) {\r\n return new Parser(source).parse();\r\n };\r\n\r\n // ----- Conversion ------\r\n\r\n /**\r\n * Converts a numerical string to an id.\r\n * @param {string} value\r\n * @param {boolean=} mayBeNegative\r\n * @returns {number}\r\n * @inner\r\n */\r\n function mkId(value, mayBeNegative) {\r\n var id = -1,\r\n sign = 1;\r\n if (value.charAt(0) == '-') {\r\n sign = -1;\r\n value = value.substring(1);\r\n }\r\n if (Lang.NUMBER_DEC.test(value))\r\n id = parseInt(value);\r\n else if (Lang.NUMBER_HEX.test(value))\r\n id = parseInt(value.substring(2), 16);\r\n else if (Lang.NUMBER_OCT.test(value))\r\n id = parseInt(value.substring(1), 8);\r\n else\r\n throw Error(\"illegal id value: \" + (sign < 0 ? '-' : '') + value);\r\n id = (sign*id)|0; // Force to 32bit\r\n if (!mayBeNegative && id < 0)\r\n throw Error(\"illegal id value: \" + (sign < 0 ? '-' : '') + value);\r\n return id;\r\n }\r\n\r\n /**\r\n * Converts a numerical string to a number.\r\n * @param {string} val\r\n * @returns {number}\r\n * @inner\r\n */\r\n function mkNumber(val) {\r\n var sign = 1;\r\n if (val.charAt(0) == '-') {\r\n sign = -1;\r\n val = val.substring(1);\r\n }\r\n if (Lang.NUMBER_DEC.test(val))\r\n return sign * parseInt(val, 10);\r\n else if (Lang.NUMBER_HEX.test(val))\r\n return sign * parseInt(val.substring(2), 16);\r\n else if (Lang.NUMBER_OCT.test(val))\r\n return sign * parseInt(val.substring(1), 8);\r\n else if (val === 'inf')\r\n return sign * Infinity;\r\n else if (val === 'nan')\r\n return NaN;\r\n else if (Lang.NUMBER_FLT.test(val))\r\n return sign * parseFloat(val);\r\n throw Error(\"illegal number value: \" + (sign < 0 ? '-' : '') + val);\r\n }\r\n\r\n // ----- Reading ------\r\n\r\n /**\r\n * Reads a string.\r\n * @returns {string}\r\n * @private\r\n */\r\n ParserPrototype._readString = function() {\r\n var value = \"\",\r\n token,\r\n delim;\r\n do {\r\n delim = this.tn.next();\r\n if (delim !== \"'\" && delim !== '\"')\r\n throw Error(\"illegal string delimiter: \"+delim);\r\n value += this.tn.next();\r\n this.tn.skip(delim);\r\n token = this.tn.peek();\r\n } while (token === '\"' || token === '\"'); // multi line?\r\n return value;\r\n };\r\n\r\n /**\r\n * Reads a value.\r\n * @param {boolean=} mayBeTypeRef\r\n * @returns {number|boolean|string}\r\n * @private\r\n */\r\n ParserPrototype._readValue = function(mayBeTypeRef) {\r\n var token = this.tn.peek(),\r\n value;\r\n if (token === '\"' || token === \"'\")\r\n return this._readString();\r\n this.tn.next();\r\n if (Lang.NUMBER.test(token))\r\n return mkNumber(token);\r\n if (Lang.BOOL.test(token))\r\n return (token.toLowerCase() === 'true');\r\n if (mayBeTypeRef && Lang.TYPEREF.test(token))\r\n return token;\r\n throw Error(\"illegal value: \"+token);\r\n\r\n };\r\n\r\n // ----- Parsing constructs -----\r\n\r\n /**\r\n * Parses a namespace option.\r\n * @param {!Object} parent Parent definition\r\n * @param {boolean=} isList\r\n * @private\r\n */\r\n ParserPrototype._parseOption = function(parent, isList) {\r\n var token = this.tn.next(),\r\n custom = false;\r\n if (token === '(') {\r\n custom = true;\r\n token = this.tn.next();\r\n }\r\n if (!Lang.TYPEREF.test(token))\r\n // we can allow options of the form google.protobuf.* since they will just get ignored anyways\r\n // if (!/google\\.protobuf\\./.test(token)) // FIXME: Why should that not be a valid typeref?\r\n throw Error(\"illegal option name: \"+token);\r\n var name = token;\r\n if (custom) { // (my_method_option).foo, (my_method_option), some_method_option, (foo.my_option).bar\r\n this.tn.skip(')');\r\n name = '('+name+')';\r\n token = this.tn.peek();\r\n if (Lang.FQTYPEREF.test(token)) {\r\n name += token;\r\n this.tn.next();\r\n }\r\n }\r\n this.tn.skip('=');\r\n this._parseOptionValue(parent, name);\r\n if (!isList)\r\n this.tn.skip(\";\");\r\n };\r\n\r\n /**\r\n * Sets an option on the specified options object.\r\n * @param {!Object.} options\r\n * @param {string} name\r\n * @param {string|number|boolean} value\r\n * @inner\r\n */\r\n function setOption(options, name, value) {\r\n if (typeof options[name] === 'undefined')\r\n options[name] = value;\r\n else {\r\n if (!Array.isArray(options[name]))\r\n options[name] = [ options[name] ];\r\n options[name].push(value);\r\n }\r\n }\r\n\r\n /**\r\n * Parses an option value.\r\n * @param {!Object} parent\r\n * @param {string} name\r\n * @private\r\n */\r\n ParserPrototype._parseOptionValue = function(parent, name) {\r\n var token = this.tn.peek();\r\n if (token !== '{') { // Plain value\r\n setOption(parent[\"options\"], name, this._readValue(true));\r\n } else { // Aggregate options\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== '}') {\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal option name: \" + name + \".\" + token);\r\n if (this.tn.omit(\":\"))\r\n setOption(parent[\"options\"], name + \".\" + token, this._readValue(true));\r\n else\r\n this._parseOptionValue(parent, name + \".\" + token);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Parses a service definition.\r\n * @param {!Object} parent Parent definition\r\n * @private\r\n */\r\n ParserPrototype._parseService = function(parent) {\r\n var token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal service name at line \"+this.tn.line+\": \"+token);\r\n var name = token;\r\n var svc = {\r\n \"name\": name,\r\n \"rpc\": {},\r\n \"options\": {}\r\n };\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== '}') {\r\n if (token === \"option\")\r\n this._parseOption(svc);\r\n else if (token === 'rpc')\r\n this._parseServiceRPC(svc);\r\n else\r\n throw Error(\"illegal service token: \"+token);\r\n }\r\n this.tn.omit(\";\");\r\n parent[\"services\"].push(svc);\r\n };\r\n\r\n /**\r\n * Parses a RPC service definition of the form ['rpc', name, (request), 'returns', (response)].\r\n * @param {!Object} svc Service definition\r\n * @private\r\n */\r\n ParserPrototype._parseServiceRPC = function(svc) {\r\n var type = \"rpc\",\r\n token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal rpc service method name: \"+token);\r\n var name = token;\r\n var method = {\r\n \"request\": null,\r\n \"response\": null,\r\n \"request_stream\": false,\r\n \"response_stream\": false,\r\n \"options\": {}\r\n };\r\n this.tn.skip(\"(\");\r\n token = this.tn.next();\r\n if (token.toLowerCase() === \"stream\") {\r\n method[\"request_stream\"] = true;\r\n token = this.tn.next();\r\n }\r\n if (!Lang.TYPEREF.test(token))\r\n throw Error(\"illegal rpc service request type: \"+token);\r\n method[\"request\"] = token;\r\n this.tn.skip(\")\");\r\n token = this.tn.next();\r\n if (token.toLowerCase() !== \"returns\")\r\n throw Error(\"illegal rpc service request type delimiter: \"+token);\r\n this.tn.skip(\"(\");\r\n token = this.tn.next();\r\n if (token.toLowerCase() === \"stream\") {\r\n method[\"response_stream\"] = true;\r\n token = this.tn.next();\r\n }\r\n method[\"response\"] = token;\r\n this.tn.skip(\")\");\r\n token = this.tn.peek();\r\n if (token === '{') {\r\n this.tn.next();\r\n while ((token = this.tn.next()) !== '}') {\r\n if (token === 'option')\r\n this._parseOption(method);\r\n else\r\n throw Error(\"illegal rpc service token: \" + token);\r\n }\r\n this.tn.omit(\";\");\r\n } else\r\n this.tn.skip(\";\");\r\n if (typeof svc[type] === 'undefined')\r\n svc[type] = {};\r\n svc[type][name] = method;\r\n };\r\n\r\n /**\r\n * Parses a message definition.\r\n * @param {!Object} parent Parent definition\r\n * @param {!Object=} fld Field definition if this is a group\r\n * @returns {!Object}\r\n * @private\r\n */\r\n ParserPrototype._parseMessage = function(parent, fld) {\r\n var isGroup = !!fld,\r\n token = this.tn.next();\r\n var msg = {\r\n \"name\": \"\",\r\n \"fields\": [],\r\n \"enums\": [],\r\n \"messages\": [],\r\n \"options\": {},\r\n \"services\": [],\r\n \"oneofs\": {}\r\n // \"extensions\": undefined\r\n };\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal \"+(isGroup ? \"group\" : \"message\")+\" name: \"+token);\r\n msg[\"name\"] = token;\r\n if (isGroup) {\r\n this.tn.skip(\"=\");\r\n fld[\"id\"] = mkId(this.tn.next());\r\n msg[\"isGroup\"] = true;\r\n }\r\n token = this.tn.peek();\r\n if (token === '[' && fld)\r\n this._parseFieldOptions(fld);\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== '}') {\r\n if (Lang.RULE.test(token))\r\n this._parseMessageField(msg, token);\r\n else if (token === \"oneof\")\r\n this._parseMessageOneOf(msg);\r\n else if (token === \"enum\")\r\n this._parseEnum(msg);\r\n else if (token === \"message\")\r\n this._parseMessage(msg);\r\n else if (token === \"option\")\r\n this._parseOption(msg);\r\n else if (token === \"service\")\r\n this._parseService(msg);\r\n else if (token === \"extensions\")\r\n this._parseExtensions(msg);\r\n else if (token === \"extend\")\r\n this._parseExtend(msg);\r\n else if (token === \"reserved\")\r\n this._parseMessageReserved(msg);\r\n else if (Lang.TYPEREF.test(token)) {\r\n if (!this.proto3)\r\n throw Error(\"illegal field rule: \"+token);\r\n this._parseMessageField(msg, \"optional\", token);\r\n } else\r\n throw Error(\"illegal message token: \"+token);\r\n }\r\n this.tn.omit(\";\");\r\n parent[\"messages\"].push(msg);\r\n return msg;\r\n };\r\n\r\n /**\r\n * Parses a message's reserved ids / names statement.\r\n * @param {!Object} msg Message definition\r\n * @private\r\n */\r\n ParserPrototype._parseMessageReserved = function(msg) {\r\n // TODO: This currently just skips a reserved statement for compatibility.\r\n // Valid formats are\r\n // reserved 2, 15, 9 to 11;\r\n // for reserved ids or\r\n // reserved \"foo\", \"bar\";\r\n // for reserved names.\r\n while (this.tn.peek() !== ';')\r\n this.tn.next();\r\n this.tn.skip(\";\");\r\n };\r\n\r\n /**\r\n * Parses a message field.\r\n * @param {!Object} msg Message definition\r\n * @param {string} rule Field rule\r\n * @param {string=} type Field type if already known (never known for maps)\r\n * @returns {!Object} Field descriptor\r\n * @private\r\n */\r\n ParserPrototype._parseMessageField = function(msg, rule, type) {\r\n if (!Lang.RULE.test(rule))\r\n throw Error(\"illegal message field rule: \"+rule);\r\n var fld = {\r\n \"rule\": rule,\r\n \"type\": \"\",\r\n \"name\": \"\",\r\n \"options\": {},\r\n \"id\": 0\r\n };\r\n var token;\r\n if (rule === \"map\") {\r\n\r\n if (type)\r\n throw Error(\"illegal type: \" + type);\r\n this.tn.skip('<');\r\n token = this.tn.next();\r\n if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token))\r\n throw Error(\"illegal message field type: \" + token);\r\n fld[\"keytype\"] = token;\r\n this.tn.skip(',');\r\n token = this.tn.next();\r\n if (!Lang.TYPE.test(token) && !Lang.TYPEREF.test(token))\r\n throw Error(\"illegal message field: \" + token);\r\n fld[\"type\"] = token;\r\n this.tn.skip('>');\r\n token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal message field name: \" + token);\r\n fld[\"name\"] = token;\r\n this.tn.skip(\"=\");\r\n fld[\"id\"] = mkId(this.tn.next());\r\n token = this.tn.peek();\r\n if (token === '[')\r\n this._parseFieldOptions(fld);\r\n this.tn.skip(\";\");\r\n\r\n } else {\r\n\r\n type = typeof type !== 'undefined' ? type : this.tn.next();\r\n\r\n if (type === \"group\") {\r\n\r\n // \"A [legacy] group simply combines a nested message type and a field into a single declaration. In your\r\n // code, you can treat this message just as if it had a Result type field called result (the latter name is\r\n // converted to lower-case so that it does not conflict with the former).\"\r\n var grp = this._parseMessage(msg, fld);\r\n if (!/^[A-Z]/.test(grp[\"name\"]))\r\n throw Error('illegal group name: '+grp[\"name\"]);\r\n fld[\"type\"] = grp[\"name\"];\r\n fld[\"name\"] = grp[\"name\"].toLowerCase();\r\n this.tn.omit(\";\");\r\n\r\n } else {\r\n\r\n if (!Lang.TYPE.test(type) && !Lang.TYPEREF.test(type))\r\n throw Error(\"illegal message field type: \" + type);\r\n fld[\"type\"] = type;\r\n token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal message field name: \" + token);\r\n fld[\"name\"] = token;\r\n this.tn.skip(\"=\");\r\n fld[\"id\"] = mkId(this.tn.next());\r\n token = this.tn.peek();\r\n if (token === \"[\")\r\n this._parseFieldOptions(fld);\r\n this.tn.skip(\";\");\r\n\r\n }\r\n }\r\n msg[\"fields\"].push(fld);\r\n return fld;\r\n };\r\n\r\n /**\r\n * Parses a message oneof.\r\n * @param {!Object} msg Message definition\r\n * @private\r\n */\r\n ParserPrototype._parseMessageOneOf = function(msg) {\r\n var token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal oneof name: \"+token);\r\n var name = token,\r\n fld;\r\n var fields = [];\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== \"}\") {\r\n fld = this._parseMessageField(msg, \"optional\", token);\r\n fld[\"oneof\"] = name;\r\n fields.push(fld[\"id\"]);\r\n }\r\n this.tn.omit(\";\");\r\n msg[\"oneofs\"][name] = fields;\r\n };\r\n\r\n /**\r\n * Parses a set of field option definitions.\r\n * @param {!Object} fld Field definition\r\n * @private\r\n */\r\n ParserPrototype._parseFieldOptions = function(fld) {\r\n this.tn.skip(\"[\");\r\n var token,\r\n first = true;\r\n while ((token = this.tn.peek()) !== ']') {\r\n if (!first)\r\n this.tn.skip(\",\");\r\n this._parseOption(fld, true);\r\n first = false;\r\n }\r\n this.tn.next();\r\n };\r\n\r\n /**\r\n * Parses an enum.\r\n * @param {!Object} msg Message definition\r\n * @private\r\n */\r\n ParserPrototype._parseEnum = function(msg) {\r\n var enm = {\r\n \"name\": \"\",\r\n \"values\": [],\r\n \"options\": {}\r\n };\r\n var token = this.tn.next();\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal name: \"+token);\r\n enm[\"name\"] = token;\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== '}') {\r\n if (token === \"option\")\r\n this._parseOption(enm);\r\n else {\r\n if (!Lang.NAME.test(token))\r\n throw Error(\"illegal name: \"+token);\r\n this.tn.skip(\"=\");\r\n var val = {\r\n \"name\": token,\r\n \"id\": mkId(this.tn.next(), true)\r\n };\r\n token = this.tn.peek();\r\n if (token === \"[\")\r\n this._parseFieldOptions({ \"options\": {} });\r\n this.tn.skip(\";\");\r\n enm[\"values\"].push(val);\r\n }\r\n }\r\n this.tn.omit(\";\");\r\n msg[\"enums\"].push(enm);\r\n };\r\n\r\n /**\r\n * Parses an extensions statement.\r\n * @param {!Object} msg Message object\r\n * @private\r\n */\r\n ParserPrototype._parseExtensions = function(msg) {\r\n var token = this.tn.next(),\r\n range = [];\r\n if (token === \"min\")\r\n range.push(ProtoBuf.ID_MIN);\r\n else if (token === \"max\")\r\n range.push(ProtoBuf.ID_MAX);\r\n else\r\n range.push(mkNumber(token));\r\n this.tn.skip(\"to\");\r\n token = this.tn.next();\r\n if (token === \"min\")\r\n range.push(ProtoBuf.ID_MIN);\r\n else if (token === \"max\")\r\n range.push(ProtoBuf.ID_MAX);\r\n else\r\n range.push(mkNumber(token));\r\n this.tn.skip(\";\");\r\n msg[\"extensions\"] = range;\r\n };\r\n\r\n /**\r\n * Parses an extend block.\r\n * @param {!Object} parent Parent object\r\n * @private\r\n */\r\n ParserPrototype._parseExtend = function(parent) {\r\n var token = this.tn.next();\r\n if (!Lang.TYPEREF.test(token))\r\n throw Error(\"illegal extend reference: \"+token);\r\n var ext = {\r\n \"ref\": token,\r\n \"fields\": []\r\n };\r\n this.tn.skip(\"{\");\r\n while ((token = this.tn.next()) !== '}') {\r\n if (Lang.RULE.test(token))\r\n this._parseMessageField(ext, token);\r\n else if (Lang.TYPEREF.test(token)) {\r\n if (!this.proto3)\r\n throw Error(\"illegal field rule: \"+token);\r\n this._parseMessageField(ext, \"optional\", token);\r\n } else\r\n throw Error(\"illegal extend token: \"+token);\r\n }\r\n this.tn.omit(\";\");\r\n parent[\"messages\"].push(ext);\r\n return ext;\r\n };\r\n\r\n // ----- General -----\r\n\r\n /**\r\n * Returns a string representation of this parser.\r\n * @returns {string}\r\n */\r\n ParserPrototype.toString = function() {\r\n return \"Parser at line \"+this.tn.line;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.DotProto.Parser\r\n * @expose\r\n */\r\n DotProto.Parser = Parser;\r\n\r\n return DotProto;\r\n\r\n })(ProtoBuf, ProtoBuf.Lang);\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect\r\n * @expose\r\n */\r\n ProtoBuf.Reflect = (function(ProtoBuf) {\r\n \"use strict\";\r\n\r\n /**\r\n * Reflection types.\r\n * @exports ProtoBuf.Reflect\r\n * @namespace\r\n */\r\n var Reflect = {};\r\n\r\n /**\r\n * Constructs a Reflect base class.\r\n * @exports ProtoBuf.Reflect.T\r\n * @constructor\r\n * @abstract\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {?ProtoBuf.Reflect.T} parent Parent object\r\n * @param {string} name Object name\r\n */\r\n var T = function(builder, parent, name) {\r\n\r\n /**\r\n * Builder reference.\r\n * @type {!ProtoBuf.Builder}\r\n * @expose\r\n */\r\n this.builder = builder;\r\n\r\n /**\r\n * Parent object.\r\n * @type {?ProtoBuf.Reflect.T}\r\n * @expose\r\n */\r\n this.parent = parent;\r\n\r\n /**\r\n * Object name in namespace.\r\n * @type {string}\r\n * @expose\r\n */\r\n this.name = name;\r\n\r\n /**\r\n * Fully qualified class name\r\n * @type {string}\r\n * @expose\r\n */\r\n this.className;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.T.prototype\r\n * @inner\r\n */\r\n var TPrototype = T.prototype;\r\n\r\n /**\r\n * Returns the fully qualified name of this object.\r\n * @returns {string} Fully qualified name as of \".PATH.TO.THIS\"\r\n * @expose\r\n */\r\n TPrototype.fqn = function() {\r\n var name = this.name,\r\n ptr = this;\r\n do {\r\n ptr = ptr.parent;\r\n if (ptr == null)\r\n break;\r\n name = ptr.name+\".\"+name;\r\n } while (true);\r\n return name;\r\n };\r\n\r\n /**\r\n * Returns a string representation of this Reflect object (its fully qualified name).\r\n * @param {boolean=} includeClass Set to true to include the class name. Defaults to false.\r\n * @return String representation\r\n * @expose\r\n */\r\n TPrototype.toString = function(includeClass) {\r\n return (includeClass ? this.className + \" \" : \"\") + this.fqn();\r\n };\r\n\r\n /**\r\n * Builds this type.\r\n * @throws {Error} If this type cannot be built directly\r\n * @expose\r\n */\r\n TPrototype.build = function() {\r\n throw Error(this.toString(true)+\" cannot be built directly\");\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.T\r\n * @expose\r\n */\r\n Reflect.T = T;\r\n\r\n /**\r\n * Constructs a new Namespace.\r\n * @exports ProtoBuf.Reflect.Namespace\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {?ProtoBuf.Reflect.Namespace} parent Namespace parent\r\n * @param {string} name Namespace name\r\n * @param {Object.=} options Namespace options\r\n * @param {string?} syntax The syntax level of this definition (e.g., proto3)\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.T\r\n */\r\n var Namespace = function(builder, parent, name, options, syntax) {\r\n T.call(this, builder, parent, name);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Namespace\";\r\n\r\n /**\r\n * Children inside the namespace.\r\n * @type {!Array.}\r\n */\r\n this.children = [];\r\n\r\n /**\r\n * Options.\r\n * @type {!Object.}\r\n */\r\n this.options = options || {};\r\n\r\n /**\r\n * Syntax level (e.g., proto2 or proto3).\r\n * @type {!string}\r\n */\r\n this.syntax = syntax || \"proto2\";\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Namespace.prototype\r\n * @inner\r\n */\r\n var NamespacePrototype = Namespace.prototype = Object.create(T.prototype);\r\n\r\n /**\r\n * Returns an array of the namespace's children.\r\n * @param {ProtoBuf.Reflect.T=} type Filter type (returns instances of this type only). Defaults to null (all children).\r\n * @return {Array.}\r\n * @expose\r\n */\r\n NamespacePrototype.getChildren = function(type) {\r\n type = type || null;\r\n if (type == null)\r\n return this.children.slice();\r\n var children = [];\r\n for (var i=0, k=this.children.length; i} qn Qualified name to resolve\r\n * @param {boolean=} excludeNonNamespace Excludes non-namespace types, defaults to `false`\r\n * @return {?ProtoBuf.Reflect.Namespace} The resolved type or null if not found\r\n * @expose\r\n */\r\n NamespacePrototype.resolve = function(qn, excludeNonNamespace) {\r\n var part = typeof qn === 'string' ? qn.split(\".\") : qn,\r\n ptr = this,\r\n i = 0;\r\n if (part[i] === \"\") { // Fully qualified name, e.g. \".My.Message'\r\n while (ptr.parent !== null)\r\n ptr = ptr.parent;\r\n i++;\r\n }\r\n var child;\r\n do {\r\n do {\r\n if (!(ptr instanceof Reflect.Namespace)) {\r\n ptr = null;\r\n break;\r\n }\r\n child = ptr.getChild(part[i]);\r\n if (!child || !(child instanceof Reflect.T) || (excludeNonNamespace && !(child instanceof Reflect.Namespace))) {\r\n ptr = null;\r\n break;\r\n }\r\n ptr = child; i++;\r\n } while (i < part.length);\r\n if (ptr != null)\r\n break; // Found\r\n // Else search the parent\r\n if (this.parent !== null)\r\n return this.parent.resolve(qn, excludeNonNamespace);\r\n } while (ptr != null);\r\n return ptr;\r\n };\r\n\r\n /**\r\n * Determines the shortest qualified name of the specified type, if any, relative to this namespace.\r\n * @param {!ProtoBuf.Reflect.T} t Reflection type\r\n * @returns {string} The shortest qualified name or, if there is none, the fqn\r\n * @expose\r\n */\r\n NamespacePrototype.qn = function(t) {\r\n var part = [], ptr = t;\r\n do {\r\n part.unshift(ptr.name);\r\n ptr = ptr.parent;\r\n } while (ptr !== null);\r\n for (var len=1; len <= part.length; len++) {\r\n var qn = part.slice(part.length-len);\r\n if (t === this.resolve(qn, t instanceof Reflect.Namespace))\r\n return qn.join(\".\");\r\n }\r\n return t.fqn();\r\n };\r\n\r\n /**\r\n * Builds the namespace and returns the runtime counterpart.\r\n * @return {Object.} Runtime namespace\r\n * @expose\r\n */\r\n NamespacePrototype.build = function() {\r\n /** @dict */\r\n var ns = {};\r\n var children = this.children;\r\n for (var i=0, k=children.length, child; i}\r\n */\r\n NamespacePrototype.buildOpt = function() {\r\n var opt = {},\r\n keys = Object.keys(this.options);\r\n for (var i=0, k=keys.length; i}null} Option value or NULL if there is no such option\r\n */\r\n NamespacePrototype.getOption = function(name) {\r\n if (typeof name === 'undefined')\r\n return this.options;\r\n return typeof this.options[name] !== 'undefined' ? this.options[name] : null;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Namespace\r\n * @expose\r\n */\r\n Reflect.Namespace = Namespace;\r\n\r\n /**\r\n * Constructs a new Element implementation that checks and converts values for a\r\n * particular field type, as appropriate.\r\n *\r\n * An Element represents a single value: either the value of a singular field,\r\n * or a value contained in one entry of a repeated field or map field. This\r\n * class does not implement these higher-level concepts; it only encapsulates\r\n * the low-level typechecking and conversion.\r\n *\r\n * @exports ProtoBuf.Reflect.Element\r\n * @param {{name: string, wireType: number}} type Resolved data type\r\n * @param {ProtoBuf.Reflect.T|null} resolvedType Resolved type, if relevant\r\n * (e.g. submessage field).\r\n * @param {boolean} isMapKey Is this element a Map key? The value will be\r\n * converted to string form if so.\r\n * @param {string} syntax Syntax level of defining message type, e.g.,\r\n * proto2 or proto3.\r\n * @constructor\r\n */\r\n var Element = function(type, resolvedType, isMapKey, syntax) {\r\n\r\n /**\r\n * Element type, as a string (e.g., int32).\r\n * @type {{name: string, wireType: number}}\r\n */\r\n this.type = type;\r\n\r\n /**\r\n * Element type reference to submessage or enum definition, if needed.\r\n * @type {ProtoBuf.Reflect.T|null}\r\n */\r\n this.resolvedType = resolvedType;\r\n\r\n /**\r\n * Element is a map key.\r\n * @type {boolean}\r\n */\r\n this.isMapKey = isMapKey;\r\n\r\n /**\r\n * Syntax level of defining message type, e.g., proto2 or proto3.\r\n * @type {string}\r\n */\r\n this.syntax = syntax;\r\n\r\n if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)\r\n throw Error(\"Invalid map key type: \" + type.name);\r\n };\r\n\r\n var ElementPrototype = Element.prototype;\r\n\r\n /**\r\n * Obtains a (new) default value for the specified type.\r\n * @param type {string|{name: string, wireType: number}} Field type\r\n * @returns {*} Default value\r\n * @inner\r\n */\r\n function mkDefault(type) {\r\n if (typeof type === 'string')\r\n type = ProtoBuf.TYPES[type];\r\n if (typeof type.defaultValue === 'undefined')\r\n throw Error(\"default value for type \"+type.name+\" is not supported\");\r\n if (type == ProtoBuf.TYPES[\"bytes\"])\r\n return new ByteBuffer(0);\r\n return type.defaultValue;\r\n }\r\n\r\n /**\r\n * Returns the default value for this field in proto3.\r\n * @function\r\n * @param type {string|{name: string, wireType: number}} the field type\r\n * @returns {*} Default value\r\n */\r\n Element.defaultFieldValue = mkDefault;\r\n\r\n /**\r\n * Makes a Long from a value.\r\n * @param {{low: number, high: number, unsigned: boolean}|string|number} value Value\r\n * @param {boolean=} unsigned Whether unsigned or not, defaults to reuse it from Long-like objects or to signed for\r\n * strings and numbers\r\n * @returns {!Long}\r\n * @throws {Error} If the value cannot be converted to a Long\r\n * @inner\r\n */\r\n function mkLong(value, unsigned) {\r\n if (value && typeof value.low === 'number' && typeof value.high === 'number' && typeof value.unsigned === 'boolean'\r\n && value.low === value.low && value.high === value.high)\r\n return new ProtoBuf.Long(value.low, value.high, typeof unsigned === 'undefined' ? value.unsigned : unsigned);\r\n if (typeof value === 'string')\r\n return ProtoBuf.Long.fromString(value, unsigned || false, 10);\r\n if (typeof value === 'number')\r\n return ProtoBuf.Long.fromNumber(value, unsigned || false);\r\n throw Error(\"not convertible to Long\");\r\n }\r\n\r\n /**\r\n * Checks if the given value can be set for an element of this type (singular\r\n * field or one element of a repeated field or map).\r\n * @param {*} value Value to check\r\n * @return {*} Verified, maybe adjusted, value\r\n * @throws {Error} If the value cannot be verified for this element slot\r\n * @expose\r\n */\r\n ElementPrototype.verifyValue = function(value) {\r\n var fail = function(val, msg) {\r\n throw Error(\"Illegal value for \"+this.toString(true)+\" of type \"+this.type.name+\": \"+val+\" (\"+msg+\")\");\r\n }.bind(this);\r\n switch (this.type) {\r\n // Signed 32bit\r\n case ProtoBuf.TYPES[\"int32\"]:\r\n case ProtoBuf.TYPES[\"sint32\"]:\r\n case ProtoBuf.TYPES[\"sfixed32\"]:\r\n // Account for !NaN: value === value\r\n if (typeof value !== 'number' || (value === value && value % 1 !== 0))\r\n fail(typeof value, \"not an integer\");\r\n return value > 4294967295 ? value | 0 : value;\r\n\r\n // Unsigned 32bit\r\n case ProtoBuf.TYPES[\"uint32\"]:\r\n case ProtoBuf.TYPES[\"fixed32\"]:\r\n if (typeof value !== 'number' || (value === value && value % 1 !== 0))\r\n fail(typeof value, \"not an integer\");\r\n return value < 0 ? value >>> 0 : value;\r\n\r\n // Signed 64bit\r\n case ProtoBuf.TYPES[\"int64\"]:\r\n case ProtoBuf.TYPES[\"sint64\"]:\r\n case ProtoBuf.TYPES[\"sfixed64\"]: {\r\n if (ProtoBuf.Long)\r\n try {\r\n return mkLong(value, false);\r\n } catch (e) {\r\n fail(typeof value, e.message);\r\n }\r\n else\r\n fail(typeof value, \"requires Long.js\");\r\n }\r\n\r\n // Unsigned 64bit\r\n case ProtoBuf.TYPES[\"uint64\"]:\r\n case ProtoBuf.TYPES[\"fixed64\"]: {\r\n if (ProtoBuf.Long)\r\n try {\r\n return mkLong(value, true);\r\n } catch (e) {\r\n fail(typeof value, e.message);\r\n }\r\n else\r\n fail(typeof value, \"requires Long.js\");\r\n }\r\n\r\n // Bool\r\n case ProtoBuf.TYPES[\"bool\"]:\r\n if (typeof value !== 'boolean')\r\n fail(typeof value, \"not a boolean\");\r\n return value;\r\n\r\n // Float\r\n case ProtoBuf.TYPES[\"float\"]:\r\n case ProtoBuf.TYPES[\"double\"]:\r\n if (typeof value !== 'number')\r\n fail(typeof value, \"not a number\");\r\n return value;\r\n\r\n // Length-delimited string\r\n case ProtoBuf.TYPES[\"string\"]:\r\n if (typeof value !== 'string' && !(value && value instanceof String))\r\n fail(typeof value, \"not a string\");\r\n return \"\"+value; // Convert String object to string\r\n\r\n // Length-delimited bytes\r\n case ProtoBuf.TYPES[\"bytes\"]:\r\n if (ByteBuffer.isByteBuffer(value))\r\n return value;\r\n return ByteBuffer.wrap(value, \"base64\");\r\n\r\n // Constant enum value\r\n case ProtoBuf.TYPES[\"enum\"]: {\r\n var values = this.resolvedType.getChildren(ProtoBuf.Reflect.Enum.Value);\r\n for (i=0; i 4294967295 || value < 0)\r\n fail(typeof value, \"not in range for uint32\")\r\n return value;\r\n } else {\r\n // proto2 requires enum values to be valid.\r\n fail(value, \"not a valid enum value\");\r\n }\r\n }\r\n // Embedded message\r\n case ProtoBuf.TYPES[\"group\"]:\r\n case ProtoBuf.TYPES[\"message\"]: {\r\n if (!value || typeof value !== 'object')\r\n fail(typeof value, \"object expected\");\r\n if (value instanceof this.resolvedType.clazz)\r\n return value;\r\n if (value instanceof ProtoBuf.Builder.Message) {\r\n // Mismatched type: Convert to object (see: https://github.com/dcodeIO/ProtoBuf.js/issues/180)\r\n var obj = {};\r\n for (var i in value)\r\n if (value.hasOwnProperty(i))\r\n obj[i] = value[i];\r\n value = obj;\r\n }\r\n // Else let's try to construct one from a key-value object\r\n return new (this.resolvedType.clazz)(value); // May throw for a hundred of reasons\r\n }\r\n }\r\n\r\n // We should never end here\r\n throw Error(\"[INTERNAL] Illegal value for \"+this.toString(true)+\": \"+value+\" (undefined type \"+this.type+\")\");\r\n };\r\n\r\n /**\r\n * Calculates the byte length of an element on the wire.\r\n * @param {number} id Field number\r\n * @param {*} value Field value\r\n * @returns {number} Byte length\r\n * @throws {Error} If the value cannot be calculated\r\n * @expose\r\n */\r\n ElementPrototype.calculateLength = function(id, value) {\r\n if (value === null) return 0; // Nothing to encode\r\n // Tag has already been written\r\n var n;\r\n switch (this.type) {\r\n case ProtoBuf.TYPES[\"int32\"]:\r\n return value < 0 ? ByteBuffer.calculateVarint64(value) : ByteBuffer.calculateVarint32(value);\r\n case ProtoBuf.TYPES[\"uint32\"]:\r\n return ByteBuffer.calculateVarint32(value);\r\n case ProtoBuf.TYPES[\"sint32\"]:\r\n return ByteBuffer.calculateVarint32(ByteBuffer.zigZagEncode32(value));\r\n case ProtoBuf.TYPES[\"fixed32\"]:\r\n case ProtoBuf.TYPES[\"sfixed32\"]:\r\n case ProtoBuf.TYPES[\"float\"]:\r\n return 4;\r\n case ProtoBuf.TYPES[\"int64\"]:\r\n case ProtoBuf.TYPES[\"uint64\"]:\r\n return ByteBuffer.calculateVarint64(value);\r\n case ProtoBuf.TYPES[\"sint64\"]:\r\n return ByteBuffer.calculateVarint64(ByteBuffer.zigZagEncode64(value));\r\n case ProtoBuf.TYPES[\"fixed64\"]:\r\n case ProtoBuf.TYPES[\"sfixed64\"]:\r\n return 8;\r\n case ProtoBuf.TYPES[\"bool\"]:\r\n return 1;\r\n case ProtoBuf.TYPES[\"enum\"]:\r\n return ByteBuffer.calculateVarint32(value);\r\n case ProtoBuf.TYPES[\"double\"]:\r\n return 8;\r\n case ProtoBuf.TYPES[\"string\"]:\r\n n = ByteBuffer.calculateUTF8Bytes(value);\r\n return ByteBuffer.calculateVarint32(n) + n;\r\n case ProtoBuf.TYPES[\"bytes\"]:\r\n if (value.remaining() < 0)\r\n throw Error(\"Illegal value for \"+this.toString(true)+\": \"+value.remaining()+\" bytes remaining\");\r\n return ByteBuffer.calculateVarint32(value.remaining()) + value.remaining();\r\n case ProtoBuf.TYPES[\"message\"]:\r\n n = this.resolvedType.calculate(value);\r\n return ByteBuffer.calculateVarint32(n) + n;\r\n case ProtoBuf.TYPES[\"group\"]:\r\n n = this.resolvedType.calculate(value);\r\n return n + ByteBuffer.calculateVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);\r\n }\r\n // We should never end here\r\n throw Error(\"[INTERNAL] Illegal value to encode in \"+this.toString(true)+\": \"+value+\" (unknown type)\");\r\n };\r\n\r\n /**\r\n * Encodes a value to the specified buffer. Does not encode the key.\r\n * @param {number} id Field number\r\n * @param {*} value Field value\r\n * @param {ByteBuffer} buffer ByteBuffer to encode to\r\n * @return {ByteBuffer} The ByteBuffer for chaining\r\n * @throws {Error} If the value cannot be encoded\r\n * @expose\r\n */\r\n ElementPrototype.encodeValue = function(id, value, buffer) {\r\n if (value === null) return buffer; // Nothing to encode\r\n // Tag has already been written\r\n\r\n switch (this.type) {\r\n // 32bit signed varint\r\n case ProtoBuf.TYPES[\"int32\"]:\r\n // \"If you use int32 or int64 as the type for a negative number, the resulting varint is always ten bytes\r\n // long – it is, effectively, treated like a very large unsigned integer.\" (see #122)\r\n if (value < 0)\r\n buffer.writeVarint64(value);\r\n else\r\n buffer.writeVarint32(value);\r\n break;\r\n\r\n // 32bit unsigned varint\r\n case ProtoBuf.TYPES[\"uint32\"]:\r\n buffer.writeVarint32(value);\r\n break;\r\n\r\n // 32bit varint zig-zag\r\n case ProtoBuf.TYPES[\"sint32\"]:\r\n buffer.writeVarint32ZigZag(value);\r\n break;\r\n\r\n // Fixed unsigned 32bit\r\n case ProtoBuf.TYPES[\"fixed32\"]:\r\n buffer.writeUint32(value);\r\n break;\r\n\r\n // Fixed signed 32bit\r\n case ProtoBuf.TYPES[\"sfixed32\"]:\r\n buffer.writeInt32(value);\r\n break;\r\n\r\n // 64bit varint as-is\r\n case ProtoBuf.TYPES[\"int64\"]:\r\n case ProtoBuf.TYPES[\"uint64\"]:\r\n buffer.writeVarint64(value); // throws\r\n break;\r\n\r\n // 64bit varint zig-zag\r\n case ProtoBuf.TYPES[\"sint64\"]:\r\n buffer.writeVarint64ZigZag(value); // throws\r\n break;\r\n\r\n // Fixed unsigned 64bit\r\n case ProtoBuf.TYPES[\"fixed64\"]:\r\n buffer.writeUint64(value); // throws\r\n break;\r\n\r\n // Fixed signed 64bit\r\n case ProtoBuf.TYPES[\"sfixed64\"]:\r\n buffer.writeInt64(value); // throws\r\n break;\r\n\r\n // Bool\r\n case ProtoBuf.TYPES[\"bool\"]:\r\n if (typeof value === 'string')\r\n buffer.writeVarint32(value.toLowerCase() === 'false' ? 0 : !!value);\r\n else\r\n buffer.writeVarint32(value ? 1 : 0);\r\n break;\r\n\r\n // Constant enum value\r\n case ProtoBuf.TYPES[\"enum\"]:\r\n buffer.writeVarint32(value);\r\n break;\r\n\r\n // 32bit float\r\n case ProtoBuf.TYPES[\"float\"]:\r\n buffer.writeFloat32(value);\r\n break;\r\n\r\n // 64bit float\r\n case ProtoBuf.TYPES[\"double\"]:\r\n buffer.writeFloat64(value);\r\n break;\r\n\r\n // Length-delimited string\r\n case ProtoBuf.TYPES[\"string\"]:\r\n buffer.writeVString(value);\r\n break;\r\n\r\n // Length-delimited bytes\r\n case ProtoBuf.TYPES[\"bytes\"]:\r\n if (value.remaining() < 0)\r\n throw Error(\"Illegal value for \"+this.toString(true)+\": \"+value.remaining()+\" bytes remaining\");\r\n var prevOffset = value.offset;\r\n buffer.writeVarint32(value.remaining());\r\n buffer.append(value);\r\n value.offset = prevOffset;\r\n break;\r\n\r\n // Embedded message\r\n case ProtoBuf.TYPES[\"message\"]:\r\n var bb = new ByteBuffer().LE();\r\n this.resolvedType.encode(value, bb);\r\n buffer.writeVarint32(bb.offset);\r\n buffer.append(bb.flip());\r\n break;\r\n\r\n // Legacy group\r\n case ProtoBuf.TYPES[\"group\"]:\r\n this.resolvedType.encode(value, buffer);\r\n buffer.writeVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);\r\n break;\r\n\r\n default:\r\n // We should never end here\r\n throw Error(\"[INTERNAL] Illegal value to encode in \"+this.toString(true)+\": \"+value+\" (unknown type)\");\r\n }\r\n return buffer;\r\n };\r\n\r\n /**\r\n * Decode one element value from the specified buffer.\r\n * @param {ByteBuffer} buffer ByteBuffer to decode from\r\n * @param {number} wireType The field wire type\r\n * @param {number} id The field number\r\n * @return {*} Decoded value\r\n * @throws {Error} If the field cannot be decoded\r\n * @expose\r\n */\r\n ElementPrototype.decode = function(buffer, wireType, id) {\r\n if (wireType != this.type.wireType)\r\n throw Error(\"Unexpected wire type for element\");\r\n\r\n var value, nBytes;\r\n switch (this.type) {\r\n // 32bit signed varint\r\n case ProtoBuf.TYPES[\"int32\"]:\r\n return buffer.readVarint32() | 0;\r\n\r\n // 32bit unsigned varint\r\n case ProtoBuf.TYPES[\"uint32\"]:\r\n return buffer.readVarint32() >>> 0;\r\n\r\n // 32bit signed varint zig-zag\r\n case ProtoBuf.TYPES[\"sint32\"]:\r\n return buffer.readVarint32ZigZag() | 0;\r\n\r\n // Fixed 32bit unsigned\r\n case ProtoBuf.TYPES[\"fixed32\"]:\r\n return buffer.readUint32() >>> 0;\r\n\r\n case ProtoBuf.TYPES[\"sfixed32\"]:\r\n return buffer.readInt32() | 0;\r\n\r\n // 64bit signed varint\r\n case ProtoBuf.TYPES[\"int64\"]:\r\n return buffer.readVarint64();\r\n\r\n // 64bit unsigned varint\r\n case ProtoBuf.TYPES[\"uint64\"]:\r\n return buffer.readVarint64().toUnsigned();\r\n\r\n // 64bit signed varint zig-zag\r\n case ProtoBuf.TYPES[\"sint64\"]:\r\n return buffer.readVarint64ZigZag();\r\n\r\n // Fixed 64bit unsigned\r\n case ProtoBuf.TYPES[\"fixed64\"]:\r\n return buffer.readUint64();\r\n\r\n // Fixed 64bit signed\r\n case ProtoBuf.TYPES[\"sfixed64\"]:\r\n return buffer.readInt64();\r\n\r\n // Bool varint\r\n case ProtoBuf.TYPES[\"bool\"]:\r\n return !!buffer.readVarint32();\r\n\r\n // Constant enum value (varint)\r\n case ProtoBuf.TYPES[\"enum\"]:\r\n // The following Builder.Message#set will already throw\r\n return buffer.readVarint32();\r\n\r\n // 32bit float\r\n case ProtoBuf.TYPES[\"float\"]:\r\n return buffer.readFloat();\r\n\r\n // 64bit float\r\n case ProtoBuf.TYPES[\"double\"]:\r\n return buffer.readDouble();\r\n\r\n // Length-delimited string\r\n case ProtoBuf.TYPES[\"string\"]:\r\n return buffer.readVString();\r\n\r\n // Length-delimited bytes\r\n case ProtoBuf.TYPES[\"bytes\"]: {\r\n nBytes = buffer.readVarint32();\r\n if (buffer.remaining() < nBytes)\r\n throw Error(\"Illegal number of bytes for \"+this.toString(true)+\": \"+nBytes+\" required but got only \"+buffer.remaining());\r\n value = buffer.clone(); // Offset already set\r\n value.limit = value.offset+nBytes;\r\n buffer.offset += nBytes;\r\n return value;\r\n }\r\n\r\n // Length-delimited embedded message\r\n case ProtoBuf.TYPES[\"message\"]: {\r\n nBytes = buffer.readVarint32();\r\n return this.resolvedType.decode(buffer, nBytes);\r\n }\r\n\r\n // Legacy group\r\n case ProtoBuf.TYPES[\"group\"]:\r\n return this.resolvedType.decode(buffer, -1, id);\r\n }\r\n\r\n // We should never end here\r\n throw Error(\"[INTERNAL] Illegal decode type\");\r\n };\r\n\r\n /**\r\n * Converts a value from a string to the canonical element type.\r\n *\r\n * Legal only when isMapKey is true.\r\n *\r\n * @param {string} str The string value\r\n * @returns {*} The value\r\n */\r\n ElementPrototype.valueFromString = function(str) {\r\n if (!this.isMapKey) {\r\n throw Error(\"valueFromString() called on non-map-key element\");\r\n }\r\n\r\n switch (this.type) {\r\n case ProtoBuf.TYPES[\"int32\"]:\r\n case ProtoBuf.TYPES[\"sint32\"]:\r\n case ProtoBuf.TYPES[\"sfixed32\"]:\r\n case ProtoBuf.TYPES[\"uint32\"]:\r\n case ProtoBuf.TYPES[\"fixed32\"]:\r\n return this.verifyValue(parseInt(str));\r\n\r\n case ProtoBuf.TYPES[\"int64\"]:\r\n case ProtoBuf.TYPES[\"sint64\"]:\r\n case ProtoBuf.TYPES[\"sfixed64\"]:\r\n case ProtoBuf.TYPES[\"uint64\"]:\r\n case ProtoBuf.TYPES[\"fixed64\"]:\r\n // Long-based fields support conversions from string already.\r\n return this.verifyValue(str);\r\n\r\n case ProtoBuf.TYPES[\"bool\"]:\r\n return str === \"true\";\r\n\r\n case ProtoBuf.TYPES[\"string\"]:\r\n return this.verifyValue(str);\r\n\r\n case ProtoBuf.TYPES[\"bytes\"]:\r\n return ByteBuffer.fromBinary(str);\r\n }\r\n };\r\n\r\n /**\r\n * Converts a value from the canonical element type to a string.\r\n *\r\n * It should be the case that `valueFromString(valueToString(val))` returns\r\n * a value equivalent to `verifyValue(val)` for every legal value of `val`\r\n * according to this element type.\r\n *\r\n * This may be used when the element must be stored or used as a string,\r\n * e.g., as a map key on an Object.\r\n *\r\n * Legal only when isMapKey is true.\r\n *\r\n * @param {*} val The value\r\n * @returns {string} The string form of the value.\r\n */\r\n ElementPrototype.valueToString = function(value) {\r\n if (!this.isMapKey) {\r\n throw Error(\"valueToString() called on non-map-key element\");\r\n }\r\n\r\n if (this.type === ProtoBuf.TYPES[\"bytes\"]) {\r\n return value.toString(\"binary\");\r\n } else {\r\n return value.toString();\r\n }\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Element\r\n * @expose\r\n */\r\n Reflect.Element = Element;\r\n\r\n /**\r\n * Constructs a new Message.\r\n * @exports ProtoBuf.Reflect.Message\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.Namespace} parent Parent message or namespace\r\n * @param {string} name Message name\r\n * @param {Object.=} options Message options\r\n * @param {boolean=} isGroup `true` if this is a legacy group\r\n * @param {string?} syntax The syntax level of this definition (e.g., proto3)\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.Namespace\r\n */\r\n var Message = function(builder, parent, name, options, isGroup, syntax) {\r\n Namespace.call(this, builder, parent, name, options, syntax);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Message\";\r\n\r\n /**\r\n * Extensions range.\r\n * @type {!Array.}\r\n * @expose\r\n */\r\n this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX];\r\n\r\n /**\r\n * Runtime message class.\r\n * @type {?function(new:ProtoBuf.Builder.Message)}\r\n * @expose\r\n */\r\n this.clazz = null;\r\n\r\n /**\r\n * Whether this is a legacy group or not.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.isGroup = !!isGroup;\r\n\r\n // The following cached collections are used to efficiently iterate over or look up fields when decoding.\r\n\r\n /**\r\n * Cached fields.\r\n * @type {?Array.}\r\n * @private\r\n */\r\n this._fields = null;\r\n\r\n /**\r\n * Cached fields by id.\r\n * @type {?Object.}\r\n * @private\r\n */\r\n this._fieldsById = null;\r\n\r\n /**\r\n * Cached fields by name.\r\n * @type {?Object.}\r\n * @private\r\n */\r\n this._fieldsByName = null;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Message.prototype\r\n * @inner\r\n */\r\n var MessagePrototype = Message.prototype = Object.create(Namespace.prototype);\r\n\r\n /**\r\n * Builds the message and returns the runtime counterpart, which is a fully functional class.\r\n * @see ProtoBuf.Builder.Message\r\n * @param {boolean=} rebuild Whether to rebuild or not, defaults to false\r\n * @return {ProtoBuf.Reflect.Message} Message class\r\n * @throws {Error} If the message cannot be built\r\n * @expose\r\n */\r\n MessagePrototype.build = function(rebuild) {\r\n if (this.clazz && !rebuild)\r\n return this.clazz;\r\n\r\n // Create the runtime Message class in its own scope\r\n var clazz = (function(ProtoBuf, T) {\r\n\r\n var fields = T.getChildren(ProtoBuf.Reflect.Message.Field),\r\n oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf);\r\n\r\n /**\r\n * Constructs a new runtime Message.\r\n * @name ProtoBuf.Builder.Message\r\n * @class Barebone of all runtime messages.\r\n * @param {!Object.|string} values Preset values\r\n * @param {...string} var_args\r\n * @constructor\r\n * @throws {Error} If the message cannot be created\r\n */\r\n var Message = function(values, var_args) {\r\n ProtoBuf.Builder.Message.call(this);\r\n\r\n // Create virtual oneof properties\r\n for (var i=0, k=oneofs.length; i 0) {\r\n var value;\r\n // Set field values from a values object\r\n if (arguments.length === 1 && values !== null && typeof values === 'object' &&\r\n /* not _another_ Message */ (typeof values.encode !== 'function' || values instanceof Message) &&\r\n /* not a repeated field */ !Array.isArray(values) &&\r\n /* not a Map */ !(values instanceof ProtoBuf.Map) &&\r\n /* not a ByteBuffer */ !ByteBuffer.isByteBuffer(values) &&\r\n /* not an ArrayBuffer */ !(values instanceof ArrayBuffer) &&\r\n /* not a Long */ !(ProtoBuf.Long && values instanceof ProtoBuf.Long)) {\r\n this.$set(values);\r\n } else // Set field values from arguments, in declaration order\r\n for (i=0, k=arguments.length; i} keyOrObj String key or plain object holding multiple values\r\n * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted\r\n * @param {boolean=} noAssert Whether to not assert for an actual field / proper value type, defaults to `false`\r\n * @returns {!ProtoBuf.Builder.Message} this\r\n * @throws {Error} If the value cannot be set\r\n * @expose\r\n */\r\n MessagePrototype.set = function(keyOrObj, value, noAssert) {\r\n if (keyOrObj && typeof keyOrObj === 'object') {\r\n noAssert = value;\r\n for (var ikey in keyOrObj)\r\n if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined')\r\n this.$set(ikey, value, noAssert);\r\n return this;\r\n }\r\n var field = T._fieldsByName[keyOrObj];\r\n if (!noAssert) {\r\n if (!field)\r\n throw Error(this+\"#\"+keyOrObj+\" is not a field: undefined\");\r\n if (!(field instanceof ProtoBuf.Reflect.Message.Field))\r\n throw Error(this+\"#\"+keyOrObj+\" is not a field: \"+field.toString(true));\r\n this[field.name] = (value = field.verifyValue(value)); // May throw\r\n } else\r\n this[keyOrObj] = value;\r\n if (field && field.oneof) { // Field is part of an OneOf (not a virtual OneOf field)\r\n var currentField = this[field.oneof.name]; // Virtual field references currently set field\r\n if (value !== null) {\r\n if (currentField !== null && currentField !== field.name)\r\n this[currentField] = null; // Clear currently set field\r\n this[field.oneof.name] = field.name; // Point virtual field at this field\r\n } else if (/* value === null && */currentField === keyOrObj)\r\n this[field.oneof.name] = null; // Clear virtual field (current field explicitly cleared)\r\n }\r\n return this;\r\n };\r\n\r\n /**\r\n * Sets a field's value. This is an alias for [@link ProtoBuf.Builder.Message#set}.\r\n * @name ProtoBuf.Builder.Message#$set\r\n * @function\r\n * @param {string|!Object.} keyOrObj String key or plain object holding multiple values\r\n * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted\r\n * @param {boolean=} noAssert Whether to not assert the value, defaults to `false`\r\n * @throws {Error} If the value cannot be set\r\n * @expose\r\n */\r\n MessagePrototype.$set = MessagePrototype.set;\r\n\r\n /**\r\n * Gets a field's value.\r\n * @name ProtoBuf.Builder.Message#get\r\n * @function\r\n * @param {string} key Key\r\n * @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false`\r\n * @return {*} Value\r\n * @throws {Error} If there is no such field\r\n * @expose\r\n */\r\n MessagePrototype.get = function(key, noAssert) {\r\n if (noAssert)\r\n return this[key];\r\n var field = T._fieldsByName[key];\r\n if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field))\r\n throw Error(this+\"#\"+key+\" is not a field: undefined\");\r\n if (!(field instanceof ProtoBuf.Reflect.Message.Field))\r\n throw Error(this+\"#\"+key+\" is not a field: \"+field.toString(true));\r\n return this[field.name];\r\n };\r\n\r\n /**\r\n * Gets a field's value. This is an alias for {@link ProtoBuf.Builder.Message#$get}.\r\n * @name ProtoBuf.Builder.Message#$get\r\n * @function\r\n * @param {string} key Key\r\n * @return {*} Value\r\n * @throws {Error} If there is no such field\r\n * @expose\r\n */\r\n MessagePrototype.$get = MessagePrototype.get;\r\n\r\n // Getters and setters\r\n\r\n for (var i=0; i} data Data payload\r\n * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.\r\n * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`\r\n * @return {!ByteBuffer} Encoded message as a ByteBuffer\r\n * @expose\r\n */\r\n Message.encode = function(data, buffer, noVerify) {\r\n return new Message(data).encode(buffer, noVerify);\r\n };\r\n\r\n /**\r\n * Calculates the byte length of the message.\r\n * @name ProtoBuf.Builder.Message#calculate\r\n * @function\r\n * @returns {number} Byte length\r\n * @throws {Error} If the message cannot be calculated or if required fields are missing.\r\n * @expose\r\n */\r\n MessagePrototype.calculate = function() {\r\n return T.calculate(this);\r\n };\r\n\r\n /**\r\n * Encodes the varint32 length-delimited message.\r\n * @name ProtoBuf.Builder.Message#encodeDelimited\r\n * @function\r\n * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.\r\n * @return {!ByteBuffer} Encoded message as a ByteBuffer\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded ByteBuffer in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.encodeDelimited = function(buffer) {\r\n var isNew = false;\r\n if (!buffer)\r\n buffer = new ByteBuffer(),\r\n isNew = true;\r\n var enc = new ByteBuffer().LE();\r\n T.encode(this, enc).flip();\r\n buffer.writeVarint32(enc.remaining());\r\n buffer.append(enc);\r\n return isNew ? buffer.flip() : buffer;\r\n };\r\n\r\n /**\r\n * Directly encodes the message to an ArrayBuffer.\r\n * @name ProtoBuf.Builder.Message#encodeAB\r\n * @function\r\n * @return {ArrayBuffer} Encoded message as ArrayBuffer\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded ArrayBuffer in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.encodeAB = function() {\r\n try {\r\n return this.encode().toArrayBuffer();\r\n } catch (e) {\r\n if (e[\"encoded\"]) e[\"encoded\"] = e[\"encoded\"].toArrayBuffer();\r\n throw(e);\r\n }\r\n };\r\n\r\n /**\r\n * Returns the message as an ArrayBuffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeAB}.\r\n * @name ProtoBuf.Builder.Message#toArrayBuffer\r\n * @function\r\n * @return {ArrayBuffer} Encoded message as ArrayBuffer\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded ArrayBuffer in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB;\r\n\r\n /**\r\n * Directly encodes the message to a node Buffer.\r\n * @name ProtoBuf.Builder.Message#encodeNB\r\n * @function\r\n * @return {!Buffer}\r\n * @throws {Error} If the message cannot be encoded, not running under node.js or if required fields are\r\n * missing. The later still returns the encoded node Buffer in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.encodeNB = function() {\r\n try {\r\n return this.encode().toBuffer();\r\n } catch (e) {\r\n if (e[\"encoded\"]) e[\"encoded\"] = e[\"encoded\"].toBuffer();\r\n throw(e);\r\n }\r\n };\r\n\r\n /**\r\n * Returns the message as a node Buffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeNB}.\r\n * @name ProtoBuf.Builder.Message#toBuffer\r\n * @function\r\n * @return {!Buffer}\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded node Buffer in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.toBuffer = MessagePrototype.encodeNB;\r\n\r\n /**\r\n * Directly encodes the message to a base64 encoded string.\r\n * @name ProtoBuf.Builder.Message#encode64\r\n * @function\r\n * @return {string} Base64 encoded string\r\n * @throws {Error} If the underlying buffer cannot be encoded or if required fields are missing. The later\r\n * still returns the encoded base64 string in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.encode64 = function() {\r\n try {\r\n return this.encode().toBase64();\r\n } catch (e) {\r\n if (e[\"encoded\"]) e[\"encoded\"] = e[\"encoded\"].toBase64();\r\n throw(e);\r\n }\r\n };\r\n\r\n /**\r\n * Returns the message as a base64 encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encode64}.\r\n * @name ProtoBuf.Builder.Message#toBase64\r\n * @function\r\n * @return {string} Base64 encoded string\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded base64 string in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.toBase64 = MessagePrototype.encode64;\r\n\r\n /**\r\n * Directly encodes the message to a hex encoded string.\r\n * @name ProtoBuf.Builder.Message#encodeHex\r\n * @function\r\n * @return {string} Hex encoded string\r\n * @throws {Error} If the underlying buffer cannot be encoded or if required fields are missing. The later\r\n * still returns the encoded hex string in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.encodeHex = function() {\r\n try {\r\n return this.encode().toHex();\r\n } catch (e) {\r\n if (e[\"encoded\"]) e[\"encoded\"] = e[\"encoded\"].toHex();\r\n throw(e);\r\n }\r\n };\r\n\r\n /**\r\n * Returns the message as a hex encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encodeHex}.\r\n * @name ProtoBuf.Builder.Message#toHex\r\n * @function\r\n * @return {string} Hex encoded string\r\n * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r\n * returns the encoded hex string in the `encoded` property on the error.\r\n * @expose\r\n */\r\n MessagePrototype.toHex = MessagePrototype.encodeHex;\r\n\r\n /**\r\n * Clones a message object or field value to a raw object.\r\n * @param {*} obj Object to clone\r\n * @param {boolean} binaryAsBase64 Whether to include binary data as base64 strings or as a buffer otherwise\r\n * @param {boolean} longsAsStrings Whether to encode longs as strings\r\n * @param {!ProtoBuf.Reflect.T=} resolvedType The resolved field type if a field\r\n * @returns {*} Cloned object\r\n * @inner\r\n */\r\n function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {\r\n if (obj === null || typeof obj !== 'object') {\r\n // Convert enum values to their respective names\r\n if (resolvedType && resolvedType instanceof ProtoBuf.Reflect.Enum) {\r\n var name = ProtoBuf.Reflect.Enum.getName(resolvedType.object, obj);\r\n if (name !== null)\r\n return name;\r\n }\r\n // Pass-through string, number, boolean, null...\r\n return obj;\r\n }\r\n // Convert ByteBuffers to raw buffer or strings\r\n if (ByteBuffer.isByteBuffer(obj))\r\n return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();\r\n // Convert Longs to proper objects or strings\r\n if (ProtoBuf.Long.isLong(obj))\r\n return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);\r\n var clone;\r\n // Clone arrays\r\n if (Array.isArray(obj)) {\r\n clone = [];\r\n obj.forEach(function(v, k) {\r\n clone[k] = cloneRaw(v, binaryAsBase64, longsAsStrings, resolvedType);\r\n });\r\n return clone;\r\n }\r\n clone = {};\r\n // Convert maps to objects\r\n if (obj instanceof ProtoBuf.Map) {\r\n var it = obj.entries();\r\n for (var e = it.next(); !e.done; e = it.next())\r\n clone[obj.keyElem.valueToString(e.value[0])] = cloneRaw(e.value[1], binaryAsBase64, longsAsStrings, obj.valueElem.resolvedType);\r\n return clone;\r\n }\r\n // Everything else is a non-null object\r\n var type = obj.$type,\r\n field = undefined;\r\n for (var i in obj)\r\n if (obj.hasOwnProperty(i)) {\r\n if (type && (field = type.getChild(i)))\r\n clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings, field.resolvedType);\r\n else\r\n clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings);\r\n }\r\n return clone;\r\n }\r\n\r\n /**\r\n * Returns the message's raw payload.\r\n * @param {boolean=} binaryAsBase64 Whether to include binary data as base64 strings instead of Buffers, defaults to `false`\r\n * @param {boolean} longsAsStrings Whether to encode longs as strings\r\n * @returns {Object.} Raw payload\r\n * @expose\r\n */\r\n MessagePrototype.toRaw = function(binaryAsBase64, longsAsStrings) {\r\n return cloneRaw(this, !!binaryAsBase64, !!longsAsStrings, this.$type);\r\n };\r\n\r\n /**\r\n * Encodes a message to JSON.\r\n * @returns {string} JSON string\r\n * @expose\r\n */\r\n MessagePrototype.encodeJSON = function() {\r\n return JSON.stringify(\r\n cloneRaw(this,\r\n /* binary-as-base64 */ true,\r\n /* longs-as-strings */ true,\r\n this.$type\r\n )\r\n );\r\n };\r\n\r\n /**\r\n * Decodes a message from the specified buffer or string.\r\n * @name ProtoBuf.Builder.Message.decode\r\n * @function\r\n * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from\r\n * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64\r\n * @return {!ProtoBuf.Builder.Message} Decoded message\r\n * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r\n * returns the decoded message with missing fields in the `decoded` property on the error.\r\n * @expose\r\n * @see ProtoBuf.Builder.Message.decode64\r\n * @see ProtoBuf.Builder.Message.decodeHex\r\n */\r\n Message.decode = function(buffer, enc) {\r\n if (typeof buffer === 'string')\r\n buffer = ByteBuffer.wrap(buffer, enc ? enc : \"base64\");\r\n buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw\r\n var le = buffer.littleEndian;\r\n try {\r\n var msg = T.decode(buffer.LE());\r\n buffer.LE(le);\r\n return msg;\r\n } catch (e) {\r\n buffer.LE(le);\r\n throw(e);\r\n }\r\n };\r\n\r\n /**\r\n * Decodes a varint32 length-delimited message from the specified buffer or string.\r\n * @name ProtoBuf.Builder.Message.decodeDelimited\r\n * @function\r\n * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from\r\n * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64\r\n * @return {ProtoBuf.Builder.Message} Decoded message or `null` if not enough bytes are available yet\r\n * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r\n * returns the decoded message with missing fields in the `decoded` property on the error.\r\n * @expose\r\n */\r\n Message.decodeDelimited = function(buffer, enc) {\r\n if (typeof buffer === 'string')\r\n buffer = ByteBuffer.wrap(buffer, enc ? enc : \"base64\");\r\n buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw\r\n if (buffer.remaining() < 1)\r\n return null;\r\n var off = buffer.offset,\r\n len = buffer.readVarint32();\r\n if (buffer.remaining() < len) {\r\n buffer.offset = off;\r\n return null;\r\n }\r\n try {\r\n var msg = T.decode(buffer.slice(buffer.offset, buffer.offset + len).LE());\r\n buffer.offset += len;\r\n return msg;\r\n } catch (err) {\r\n buffer.offset += len;\r\n throw err;\r\n }\r\n };\r\n\r\n /**\r\n * Decodes the message from the specified base64 encoded string.\r\n * @name ProtoBuf.Builder.Message.decode64\r\n * @function\r\n * @param {string} str String to decode from\r\n * @return {!ProtoBuf.Builder.Message} Decoded message\r\n * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r\n * returns the decoded message with missing fields in the `decoded` property on the error.\r\n * @expose\r\n */\r\n Message.decode64 = function(str) {\r\n return Message.decode(str, \"base64\");\r\n };\r\n\r\n /**\r\n * Decodes the message from the specified hex encoded string.\r\n * @name ProtoBuf.Builder.Message.decodeHex\r\n * @function\r\n * @param {string} str String to decode from\r\n * @return {!ProtoBuf.Builder.Message} Decoded message\r\n * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r\n * returns the decoded message with missing fields in the `decoded` property on the error.\r\n * @expose\r\n */\r\n Message.decodeHex = function(str) {\r\n return Message.decode(str, \"hex\");\r\n };\r\n\r\n /**\r\n * Decodes the message from a JSON string.\r\n * @name ProtoBuf.Builder.Message.decodeJSON\r\n * @function\r\n * @param {string} str String to decode from\r\n * @return {!ProtoBuf.Builder.Message} Decoded message\r\n * @throws {Error} If the message cannot be decoded or if required fields are\r\n * missing.\r\n * @expose\r\n */\r\n Message.decodeJSON = function(str) {\r\n return new Message(JSON.parse(str));\r\n };\r\n\r\n // Utility\r\n\r\n /**\r\n * Returns a string representation of this Message.\r\n * @name ProtoBuf.Builder.Message#toString\r\n * @function\r\n * @return {string} String representation as of \".Fully.Qualified.MessageName\"\r\n * @expose\r\n */\r\n MessagePrototype.toString = function() {\r\n return T.toString();\r\n };\r\n\r\n // Properties\r\n\r\n /**\r\n * Message options.\r\n * @name ProtoBuf.Builder.Message.$options\r\n * @type {Object.}\r\n * @expose\r\n */\r\n var $optionsS; // cc needs this\r\n\r\n /**\r\n * Message options.\r\n * @name ProtoBuf.Builder.Message#$options\r\n * @type {Object.}\r\n * @expose\r\n */\r\n var $options;\r\n\r\n /**\r\n * Reflection type.\r\n * @name ProtoBuf.Builder.Message.$type\r\n * @type {!ProtoBuf.Reflect.Message}\r\n * @expose\r\n */\r\n var $typeS;\r\n\r\n /**\r\n * Reflection type.\r\n * @name ProtoBuf.Builder.Message#$type\r\n * @type {!ProtoBuf.Reflect.Message}\r\n * @expose\r\n */\r\n var $type;\r\n\r\n if (Object.defineProperty)\r\n Object.defineProperty(Message, '$options', { \"value\": T.buildOpt() }),\r\n Object.defineProperty(MessagePrototype, \"$options\", { \"value\": Message[\"$options\"] }),\r\n Object.defineProperty(Message, \"$type\", { \"value\": T }),\r\n Object.defineProperty(MessagePrototype, \"$type\", { \"value\": T });\r\n\r\n return Message;\r\n\r\n })(ProtoBuf, this);\r\n\r\n // Static enums and prototyped sub-messages / cached collections\r\n this._fields = [];\r\n this._fieldsById = {};\r\n this._fieldsByName = {};\r\n for (var i=0, k=this.children.length, child; i>> 3;\r\n switch (wireType) {\r\n case ProtoBuf.WIRE_TYPES.VARINT:\r\n do tag = buf.readUint8();\r\n while ((tag & 0x80) === 0x80);\r\n break;\r\n case ProtoBuf.WIRE_TYPES.BITS64:\r\n buf.offset += 8;\r\n break;\r\n case ProtoBuf.WIRE_TYPES.LDELIM:\r\n tag = buf.readVarint32(); // reads the varint\r\n buf.offset += tag; // skips n bytes\r\n break;\r\n case ProtoBuf.WIRE_TYPES.STARTGROUP:\r\n skipTillGroupEnd(id, buf);\r\n break;\r\n case ProtoBuf.WIRE_TYPES.ENDGROUP:\r\n if (id === expectedId)\r\n return false;\r\n else\r\n throw Error(\"Illegal GROUPEND after unknown group: \"+id+\" (\"+expectedId+\" expected)\");\r\n case ProtoBuf.WIRE_TYPES.BITS32:\r\n buf.offset += 4;\r\n break;\r\n default:\r\n throw Error(\"Illegal wire type in unknown group \"+expectedId+\": \"+wireType);\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Decodes an encoded message and returns the decoded message.\r\n * @param {ByteBuffer} buffer ByteBuffer to decode from\r\n * @param {number=} length Message length. Defaults to decode all the available data.\r\n * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group\r\n * @return {ProtoBuf.Builder.Message} Decoded message\r\n * @throws {Error} If the message cannot be decoded\r\n * @expose\r\n */\r\n MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {\r\n length = typeof length === 'number' ? length : -1;\r\n var start = buffer.offset,\r\n msg = new (this.clazz)(),\r\n tag, wireType, id, field;\r\n while (buffer.offset < start+length || (length === -1 && buffer.remaining() > 0)) {\r\n tag = buffer.readVarint32();\r\n wireType = tag & 0x07;\r\n id = tag >>> 3;\r\n if (wireType === ProtoBuf.WIRE_TYPES.ENDGROUP) {\r\n if (id !== expectedGroupEndId)\r\n throw Error(\"Illegal group end indicator for \"+this.toString(true)+\": \"+id+\" (\"+(expectedGroupEndId ? expectedGroupEndId+\" expected\" : \"not a group\")+\")\");\r\n break;\r\n }\r\n if (!(field = this._fieldsById[id])) {\r\n // \"messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing.\"\r\n switch (wireType) {\r\n case ProtoBuf.WIRE_TYPES.VARINT:\r\n buffer.readVarint32();\r\n break;\r\n case ProtoBuf.WIRE_TYPES.BITS32:\r\n buffer.offset += 4;\r\n break;\r\n case ProtoBuf.WIRE_TYPES.BITS64:\r\n buffer.offset += 8;\r\n break;\r\n case ProtoBuf.WIRE_TYPES.LDELIM:\r\n var len = buffer.readVarint32();\r\n buffer.offset += len;\r\n break;\r\n case ProtoBuf.WIRE_TYPES.STARTGROUP:\r\n while (skipTillGroupEnd(id, buffer)) {}\r\n break;\r\n default:\r\n throw Error(\"Illegal wire type for unknown field \"+id+\" in \"+this.toString(true)+\"#decode: \"+wireType);\r\n }\r\n continue;\r\n }\r\n if (field.repeated && !field.options[\"packed\"]) {\r\n msg[field.name].push(field.decode(wireType, buffer));\r\n } else if (field.map) {\r\n var keyval = field.decode(wireType, buffer);\r\n msg[field.name].set(keyval[0], keyval[1]);\r\n } else {\r\n msg[field.name] = field.decode(wireType, buffer);\r\n if (field.oneof) { // Field is part of an OneOf (not a virtual OneOf field)\r\n var currentField = msg[field.oneof.name]; // Virtual field references currently set field\r\n if (currentField !== null && currentField !== field.name)\r\n msg[currentField] = null; // Clear currently set field\r\n msg[field.oneof.name] = field.name; // Point virtual field at this field\r\n }\r\n }\r\n }\r\n\r\n // Check if all required fields are present and set default values for optional fields that are not\r\n for (var i=0, k=this._fields.length; i=} options Options\r\n * @param {!ProtoBuf.Reflect.Message.OneOf=} oneof Enclosing OneOf\r\n * @param {string?} syntax The syntax level of this definition (e.g., proto3)\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.T\r\n */\r\n var Field = function(builder, message, rule, keytype, type, name, id, options, oneof, syntax) {\r\n T.call(this, builder, message, name);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Message.Field\";\r\n\r\n /**\r\n * Message field required flag.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.required = rule === \"required\";\r\n\r\n /**\r\n * Message field repeated flag.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.repeated = rule === \"repeated\";\r\n\r\n /**\r\n * Message field map flag.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.map = rule === \"map\";\r\n\r\n /**\r\n * Message field key type. Type reference string if unresolved, protobuf\r\n * type if resolved. Valid only if this.map === true, null otherwise.\r\n * @type {string|{name: string, wireType: number}|null}\r\n * @expose\r\n */\r\n this.keyType = keytype || null;\r\n\r\n /**\r\n * Message field type. Type reference string if unresolved, protobuf type if\r\n * resolved. In a map field, this is the value type.\r\n * @type {string|{name: string, wireType: number}}\r\n * @expose\r\n */\r\n this.type = type;\r\n\r\n /**\r\n * Resolved type reference inside the global namespace.\r\n * @type {ProtoBuf.Reflect.T|null}\r\n * @expose\r\n */\r\n this.resolvedType = null;\r\n\r\n /**\r\n * Unique message field id.\r\n * @type {number}\r\n * @expose\r\n */\r\n this.id = id;\r\n\r\n /**\r\n * Message field options.\r\n * @type {!Object.}\r\n * @dict\r\n * @expose\r\n */\r\n this.options = options || {};\r\n\r\n /**\r\n * Default value.\r\n * @type {*}\r\n * @expose\r\n */\r\n this.defaultValue = null;\r\n\r\n /**\r\n * Enclosing OneOf.\r\n * @type {?ProtoBuf.Reflect.Message.OneOf}\r\n * @expose\r\n */\r\n this.oneof = oneof || null;\r\n\r\n /**\r\n * Syntax level of this definition (e.g., proto3).\r\n * @type {string}\r\n * @expose\r\n */\r\n this.syntax = syntax || 'proto2';\r\n\r\n /**\r\n * Original field name.\r\n * @type {string}\r\n * @expose\r\n */\r\n this.originalName = this.name; // Used to revert camelcase transformation on naming collisions\r\n\r\n /**\r\n * Element implementation. Created in build() after types are resolved.\r\n * @type {ProtoBuf.Element}\r\n * @expose\r\n */\r\n this.element = null;\r\n\r\n /**\r\n * Key element implementation, for map fields. Created in build() after\r\n * types are resolved.\r\n * @type {ProtoBuf.Element}\r\n * @expose\r\n */\r\n this.keyElement = null;\r\n\r\n // Convert field names to camel case notation if the override is set\r\n if (this.builder.options['convertFieldsToCamelCase'] && !(this instanceof Message.ExtensionField))\r\n this.name = ProtoBuf.Util.toCamelCase(this.name);\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Message.Field.prototype\r\n * @inner\r\n */\r\n var FieldPrototype = Field.prototype = Object.create(T.prototype);\r\n\r\n /**\r\n * Builds the field.\r\n * @override\r\n * @expose\r\n */\r\n FieldPrototype.build = function() {\r\n this.element = new Element(this.type, this.resolvedType, false, this.syntax);\r\n if (this.map)\r\n this.keyElement = new Element(this.keyType, undefined, true, this.syntax);\r\n\r\n // In proto3, fields do not have field presence, and every field is set to\r\n // its type's default value (\"\", 0, 0.0, or false).\r\n if (this.syntax === 'proto3' && !this.repeated && !this.map)\r\n this.defaultValue = Element.defaultFieldValue(this.type);\r\n\r\n // Otherwise, default values are present when explicitly specified\r\n else if (typeof this.options['default'] !== 'undefined')\r\n this.defaultValue = this.verifyValue(this.options['default']);\r\n };\r\n\r\n /**\r\n * Checks if the given value can be set for this field.\r\n * @param {*} value Value to check\r\n * @param {boolean=} skipRepeated Whether to skip the repeated value check or not. Defaults to false.\r\n * @return {*} Verified, maybe adjusted, value\r\n * @throws {Error} If the value cannot be set for this field\r\n * @expose\r\n */\r\n FieldPrototype.verifyValue = function(value, skipRepeated) {\r\n skipRepeated = skipRepeated || false;\r\n var fail = function(val, msg) {\r\n throw Error(\"Illegal value for \"+this.toString(true)+\" of type \"+this.type.name+\": \"+val+\" (\"+msg+\")\");\r\n }.bind(this);\r\n if (value === null) { // NULL values for optional fields\r\n if (this.required)\r\n fail(typeof value, \"required\");\r\n if (this.syntax === 'proto3' && this.type !== ProtoBuf.TYPES[\"message\"])\r\n fail(typeof value, \"proto3 field without field presence cannot be null\");\r\n return null;\r\n }\r\n var i;\r\n if (this.repeated && !skipRepeated) { // Repeated values as arrays\r\n if (!Array.isArray(value))\r\n value = [value];\r\n var res = [];\r\n for (i=0; i 0;\r\n\r\n case ProtoBuf.TYPES[\"bytes\"]:\r\n return value.remaining() > 0;\r\n\r\n case ProtoBuf.TYPES[\"enum\"]:\r\n return value !== 0;\r\n\r\n case ProtoBuf.TYPES[\"message\"]:\r\n return value !== null;\r\n default:\r\n return true;\r\n }\r\n };\r\n\r\n /**\r\n * Encodes the specified field value to the specified buffer.\r\n * @param {*} value Verified field value\r\n * @param {ByteBuffer} buffer ByteBuffer to encode to\r\n * @param {!ProtoBuf.Builder.Message} message Runtime message\r\n * @return {ByteBuffer} The ByteBuffer for chaining\r\n * @throws {Error} If the field cannot be encoded\r\n * @expose\r\n */\r\n FieldPrototype.encode = function(value, buffer, message) {\r\n if (this.type === null || typeof this.type !== 'object')\r\n throw Error(\"[INTERNAL] Unresolved type in \"+this.toString(true)+\": \"+this.type);\r\n if (value === null || (this.repeated && value.length == 0))\r\n return buffer; // Optional omitted\r\n try {\r\n if (this.repeated) {\r\n var i;\r\n // \"Only repeated fields of primitive numeric types (types which use the varint, 32-bit, or 64-bit wire\r\n // types) can be declared 'packed'.\"\r\n if (this.options[\"packed\"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {\r\n // \"All of the elements of the field are packed into a single key-value pair with wire type 2\r\n // (length-delimited). Each element is encoded the same way it would be normally, except without a\r\n // tag preceding it.\"\r\n buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);\r\n buffer.ensureCapacity(buffer.offset += 1); // We do not know the length yet, so let's assume a varint of length 1\r\n var start = buffer.offset; // Remember where the contents begin\r\n for (i=0; i 1) { // We need to move the contents\r\n var contents = buffer.slice(start, buffer.offset);\r\n start += varintLen-1;\r\n buffer.offset = start;\r\n buffer.append(contents);\r\n }\r\n buffer.writeVarint32(len, start-varintLen);\r\n } else {\r\n // \"If your message definition has repeated elements (without the [packed=true] option), the encoded\r\n // message has zero or more key-value pairs with the same tag number\"\r\n for (i=0; i= 0) {\r\n n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);\r\n ni = 0;\r\n for (i=0; i= 0) {\r\n if (!skipRepeated) {\r\n nBytes = buffer.readVarint32();\r\n nBytes = buffer.offset + nBytes; // Limit\r\n var values = [];\r\n while (buffer.offset < nBytes)\r\n values.push(this.decode(this.type.wireType, buffer, true));\r\n return values;\r\n }\r\n // Read the next value otherwise...\r\n }\r\n\r\n // Handle maps.\r\n if (this.map) {\r\n // Read one (key, value) submessage, and return [key, value]\r\n var key = Element.defaultFieldValue(this.keyType);\r\n value = Element.defaultFieldValue(this.type);\r\n\r\n // Read the length\r\n nBytes = buffer.readVarint32();\r\n if (buffer.remaining() < nBytes)\r\n throw Error(\"Illegal number of bytes for \"+this.toString(true)+\": \"+nBytes+\" required but got only \"+buffer.remaining());\r\n\r\n // Get a sub-buffer of this key/value submessage\r\n var msgbuf = buffer.clone();\r\n msgbuf.limit = msgbuf.offset + nBytes;\r\n buffer.offset += nBytes;\r\n\r\n while (msgbuf.remaining() > 0) {\r\n var tag = msgbuf.readVarint32();\r\n wireType = tag & 0x07;\r\n var id = tag >>> 3;\r\n if (id === 1) {\r\n key = this.keyElement.decode(msgbuf, wireType, id);\r\n } else if (id === 2) {\r\n value = this.element.decode(msgbuf, wireType, id);\r\n } else {\r\n throw Error(\"Unexpected tag in map field key/value submessage\");\r\n }\r\n }\r\n\r\n return [key, value];\r\n }\r\n\r\n // Handle singular and non-packed repeated field values.\r\n return this.element.decode(buffer, wireType, this.id);\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Message.Field\r\n * @expose\r\n */\r\n Reflect.Message.Field = Field;\r\n\r\n /**\r\n * Constructs a new Message ExtensionField.\r\n * @exports ProtoBuf.Reflect.Message.ExtensionField\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.Message} message Message reference\r\n * @param {string} rule Rule, one of requried, optional, repeated\r\n * @param {string} type Data type, e.g. int32\r\n * @param {string} name Field name\r\n * @param {number} id Unique field id\r\n * @param {!Object.=} options Options\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.Message.Field\r\n */\r\n var ExtensionField = function(builder, message, rule, type, name, id, options) {\r\n Field.call(this, builder, message, rule, /* keytype = */ null, type, name, id, options);\r\n\r\n /**\r\n * Extension reference.\r\n * @type {!ProtoBuf.Reflect.Extension}\r\n * @expose\r\n */\r\n this.extension;\r\n };\r\n\r\n // Extends Field\r\n ExtensionField.prototype = Object.create(Field.prototype);\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Message.ExtensionField\r\n * @expose\r\n */\r\n Reflect.Message.ExtensionField = ExtensionField;\r\n\r\n /**\r\n * Constructs a new Message OneOf.\r\n * @exports ProtoBuf.Reflect.Message.OneOf\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.Message} message Message reference\r\n * @param {string} name OneOf name\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.T\r\n */\r\n var OneOf = function(builder, message, name) {\r\n T.call(this, builder, message, name);\r\n\r\n /**\r\n * Enclosed fields.\r\n * @type {!Array.}\r\n * @expose\r\n */\r\n this.fields = [];\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Message.OneOf\r\n * @expose\r\n */\r\n Reflect.Message.OneOf = OneOf;\r\n\r\n /**\r\n * Constructs a new Enum.\r\n * @exports ProtoBuf.Reflect.Enum\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object\r\n * @param {string} name Enum name\r\n * @param {Object.=} options Enum options\r\n * @param {string?} syntax The syntax level (e.g., proto3)\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.Namespace\r\n */\r\n var Enum = function(builder, parent, name, options, syntax) {\r\n Namespace.call(this, builder, parent, name, options, syntax);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Enum\";\r\n\r\n /**\r\n * Runtime enum object.\r\n * @type {Object.|null}\r\n * @expose\r\n */\r\n this.object = null;\r\n };\r\n\r\n /**\r\n * Gets the string name of an enum value.\r\n * @param {!ProtoBuf.Builder.Enum} enm Runtime enum\r\n * @param {number} value Enum value\r\n * @returns {?string} Name or `null` if not present\r\n * @expose\r\n */\r\n Enum.getName = function(enm, value) {\r\n var keys = Object.keys(enm);\r\n for (var i=0, key; i}\r\n * @expose\r\n */\r\n EnumPrototype.build = function(rebuild) {\r\n if (this.object && !rebuild)\r\n return this.object;\r\n var enm = new ProtoBuf.Builder.Enum(),\r\n values = this.getChildren(Enum.Value);\r\n for (var i=0, k=values.length; i=} options Options\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.Namespace\r\n */\r\n var Service = function(builder, root, name, options) {\r\n Namespace.call(this, builder, root, name, options);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Service\";\r\n\r\n /**\r\n * Built runtime service class.\r\n * @type {?function(new:ProtoBuf.Builder.Service)}\r\n */\r\n this.clazz = null;\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Service.prototype\r\n * @inner\r\n */\r\n var ServicePrototype = Service.prototype = Object.create(Namespace.prototype);\r\n\r\n /**\r\n * Builds the service and returns the runtime counterpart, which is a fully functional class.\r\n * @see ProtoBuf.Builder.Service\r\n * @param {boolean=} rebuild Whether to rebuild or not\r\n * @return {Function} Service class\r\n * @throws {Error} If the message cannot be built\r\n * @expose\r\n */\r\n ServicePrototype.build = function(rebuild) {\r\n if (this.clazz && !rebuild)\r\n return this.clazz;\r\n\r\n // Create the runtime Service class in its own scope\r\n return this.clazz = (function(ProtoBuf, T) {\r\n\r\n /**\r\n * Constructs a new runtime Service.\r\n * @name ProtoBuf.Builder.Service\r\n * @param {function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))=} rpcImpl RPC implementation receiving the method name and the message\r\n * @class Barebone of all runtime services.\r\n * @constructor\r\n * @throws {Error} If the service cannot be created\r\n */\r\n var Service = function(rpcImpl) {\r\n ProtoBuf.Builder.Service.call(this);\r\n\r\n /**\r\n * Service implementation.\r\n * @name ProtoBuf.Builder.Service#rpcImpl\r\n * @type {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))}\r\n * @expose\r\n */\r\n this.rpcImpl = rpcImpl || function(name, msg, callback) {\r\n // This is what a user has to implement: A function receiving the method name, the actual message to\r\n // send (type checked) and the callback that's either provided with the error as its first\r\n // argument or null and the actual response message.\r\n setTimeout(callback.bind(this, Error(\"Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services\")), 0); // Must be async!\r\n };\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Builder.Service.prototype\r\n * @inner\r\n */\r\n var ServicePrototype = Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype);\r\n\r\n /**\r\n * Asynchronously performs an RPC call using the given RPC implementation.\r\n * @name ProtoBuf.Builder.Service.[Method]\r\n * @function\r\n * @param {!function(string, ProtoBuf.Builder.Message, function(Error, ProtoBuf.Builder.Message=))} rpcImpl RPC implementation\r\n * @param {ProtoBuf.Builder.Message} req Request\r\n * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving\r\n * the error if any and the response either as a pre-parsed message or as its raw bytes\r\n * @abstract\r\n */\r\n\r\n /**\r\n * Asynchronously performs an RPC call using the instance's RPC implementation.\r\n * @name ProtoBuf.Builder.Service#[Method]\r\n * @function\r\n * @param {ProtoBuf.Builder.Message} req Request\r\n * @param {function(Error, (ProtoBuf.Builder.Message|ByteBuffer|Buffer|string)=)} callback Callback receiving\r\n * the error if any and the response either as a pre-parsed message or as its raw bytes\r\n * @abstract\r\n */\r\n\r\n var rpc = T.getChildren(ProtoBuf.Reflect.Service.RPCMethod);\r\n for (var i=0; i}\r\n * @expose\r\n */\r\n var $optionsS; // cc needs this\r\n\r\n /**\r\n * Service options.\r\n * @name ProtoBuf.Builder.Service#$options\r\n * @type {Object.}\r\n * @expose\r\n */\r\n var $options;\r\n\r\n /**\r\n * Reflection type.\r\n * @name ProtoBuf.Builder.Service.$type\r\n * @type {!ProtoBuf.Reflect.Service}\r\n * @expose\r\n */\r\n var $typeS;\r\n\r\n /**\r\n * Reflection type.\r\n * @name ProtoBuf.Builder.Service#$type\r\n * @type {!ProtoBuf.Reflect.Service}\r\n * @expose\r\n */\r\n var $type;\r\n\r\n if (Object.defineProperty)\r\n Object.defineProperty(Service, \"$options\", { \"value\": T.buildOpt() }),\r\n Object.defineProperty(ServicePrototype, \"$options\", { \"value\": Service[\"$options\"] }),\r\n Object.defineProperty(Service, \"$type\", { \"value\": T }),\r\n Object.defineProperty(ServicePrototype, \"$type\", { \"value\": T });\r\n\r\n return Service;\r\n\r\n })(ProtoBuf, this);\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Service\r\n * @expose\r\n */\r\n Reflect.Service = Service;\r\n\r\n /**\r\n * Abstract service method.\r\n * @exports ProtoBuf.Reflect.Service.Method\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.Service} svc Service\r\n * @param {string} name Method name\r\n * @param {Object.=} options Options\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.T\r\n */\r\n var Method = function(builder, svc, name, options) {\r\n T.call(this, builder, svc, name);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Service.Method\";\r\n\r\n /**\r\n * Options.\r\n * @type {Object.}\r\n * @expose\r\n */\r\n this.options = options || {};\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Service.Method.prototype\r\n * @inner\r\n */\r\n var MethodPrototype = Method.prototype = Object.create(T.prototype);\r\n\r\n /**\r\n * Builds the method's '$options' property.\r\n * @name ProtoBuf.Reflect.Service.Method#buildOpt\r\n * @function\r\n * @return {Object.}\r\n */\r\n MethodPrototype.buildOpt = NamespacePrototype.buildOpt;\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Service.Method\r\n * @expose\r\n */\r\n Reflect.Service.Method = Method;\r\n\r\n /**\r\n * RPC service method.\r\n * @exports ProtoBuf.Reflect.Service.RPCMethod\r\n * @param {!ProtoBuf.Builder} builder Builder reference\r\n * @param {!ProtoBuf.Reflect.Service} svc Service\r\n * @param {string} name Method name\r\n * @param {string} request Request message name\r\n * @param {string} response Response message name\r\n * @param {boolean} request_stream Whether requests are streamed\r\n * @param {boolean} response_stream Whether responses are streamed\r\n * @param {Object.=} options Options\r\n * @constructor\r\n * @extends ProtoBuf.Reflect.Service.Method\r\n */\r\n var RPCMethod = function(builder, svc, name, request, response, request_stream, response_stream, options) {\r\n Method.call(this, builder, svc, name, options);\r\n\r\n /**\r\n * @override\r\n */\r\n this.className = \"Service.RPCMethod\";\r\n\r\n /**\r\n * Request message name.\r\n * @type {string}\r\n * @expose\r\n */\r\n this.requestName = request;\r\n\r\n /**\r\n * Response message name.\r\n * @type {string}\r\n * @expose\r\n */\r\n this.responseName = response;\r\n\r\n /**\r\n * Whether requests are streamed\r\n * @type {bool}\r\n * @expose\r\n */\r\n this.requestStream = request_stream;\r\n\r\n /**\r\n * Whether responses are streamed\r\n * @type {bool}\r\n * @expose\r\n */\r\n this.responseStream = response_stream;\r\n\r\n /**\r\n * Resolved request message type.\r\n * @type {ProtoBuf.Reflect.Message}\r\n * @expose\r\n */\r\n this.resolvedRequestType = null;\r\n\r\n /**\r\n * Resolved response message type.\r\n * @type {ProtoBuf.Reflect.Message}\r\n * @expose\r\n */\r\n this.resolvedResponseType = null;\r\n };\r\n\r\n // Extends Method\r\n RPCMethod.prototype = Object.create(Method.prototype);\r\n\r\n /**\r\n * @alias ProtoBuf.Reflect.Service.RPCMethod\r\n * @expose\r\n */\r\n Reflect.Service.RPCMethod = RPCMethod;\r\n\r\n return Reflect;\r\n\r\n })(ProtoBuf);\r\n\r\n /**\r\n * @alias ProtoBuf.Builder\r\n * @expose\r\n */\r\n ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {\r\n \"use strict\";\r\n\r\n /**\r\n * Constructs a new Builder.\r\n * @exports ProtoBuf.Builder\r\n * @class Provides the functionality to build protocol messages.\r\n * @param {Object.=} options Options\r\n * @constructor\r\n */\r\n var Builder = function(options) {\r\n\r\n /**\r\n * Namespace.\r\n * @type {ProtoBuf.Reflect.Namespace}\r\n * @expose\r\n */\r\n this.ns = new Reflect.Namespace(this, null, \"\"); // Global namespace\r\n\r\n /**\r\n * Namespace pointer.\r\n * @type {ProtoBuf.Reflect.T}\r\n * @expose\r\n */\r\n this.ptr = this.ns;\r\n\r\n /**\r\n * Resolved flag.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.resolved = false;\r\n\r\n /**\r\n * The current building result.\r\n * @type {Object.|null}\r\n * @expose\r\n */\r\n this.result = null;\r\n\r\n /**\r\n * Imported files.\r\n * @type {Array.}\r\n * @expose\r\n */\r\n this.files = {};\r\n\r\n /**\r\n * Import root override.\r\n * @type {?string}\r\n * @expose\r\n */\r\n this.importRoot = null;\r\n\r\n /**\r\n * Options.\r\n * @type {!Object.}\r\n * @expose\r\n */\r\n this.options = options || {};\r\n };\r\n\r\n /**\r\n * @alias ProtoBuf.Builder.prototype\r\n * @inner\r\n */\r\n var BuilderPrototype = Builder.prototype;\r\n\r\n // ----- Definition tests -----\r\n\r\n /**\r\n * Tests if a definition most likely describes a message.\r\n * @param {!Object} def\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Builder.isMessage = function(def) {\r\n // Messages require a string name\r\n if (typeof def[\"name\"] !== 'string')\r\n return false;\r\n // Messages do not contain values (enum) or rpc methods (service)\r\n if (typeof def[\"values\"] !== 'undefined' || typeof def[\"rpc\"] !== 'undefined')\r\n return false;\r\n return true;\r\n };\r\n\r\n /**\r\n * Tests if a definition most likely describes a message field.\r\n * @param {!Object} def\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Builder.isMessageField = function(def) {\r\n // Message fields require a string rule, name and type and an id\r\n if (typeof def[\"rule\"] !== 'string' || typeof def[\"name\"] !== 'string' || typeof def[\"type\"] !== 'string' || typeof def[\"id\"] === 'undefined')\r\n return false;\r\n return true;\r\n };\r\n\r\n /**\r\n * Tests if a definition most likely describes an enum.\r\n * @param {!Object} def\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Builder.isEnum = function(def) {\r\n // Enums require a string name\r\n if (typeof def[\"name\"] !== 'string')\r\n return false;\r\n // Enums require at least one value\r\n if (typeof def[\"values\"] === 'undefined' || !Array.isArray(def[\"values\"]) || def[\"values\"].length === 0)\r\n return false;\r\n return true;\r\n };\r\n\r\n /**\r\n * Tests if a definition most likely describes a service.\r\n * @param {!Object} def\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Builder.isService = function(def) {\r\n // Services require a string name and an rpc object\r\n if (typeof def[\"name\"] !== 'string' || typeof def[\"rpc\"] !== 'object' || !def[\"rpc\"])\r\n return false;\r\n return true;\r\n };\r\n\r\n /**\r\n * Tests if a definition most likely describes an extended message\r\n * @param {!Object} def\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Builder.isExtend = function(def) {\r\n // Extends rquire a string ref\r\n if (typeof def[\"ref\"] !== 'string')\r\n return false;\r\n return true;\r\n };\r\n\r\n // ----- Building -----\r\n\r\n /**\r\n * Resets the pointer to the root namespace.\r\n * @returns {!ProtoBuf.Builder} this\r\n * @expose\r\n */\r\n BuilderPrototype.reset = function() {\r\n this.ptr = this.ns;\r\n return this;\r\n };\r\n\r\n /**\r\n * Defines a namespace on top of the current pointer position and places the pointer on it.\r\n * @param {string} namespace\r\n * @return {!ProtoBuf.Builder} this\r\n * @expose\r\n */\r\n BuilderPrototype.define = function(namespace) {\r\n if (typeof namespace !== 'string' || !Lang.TYPEREF.test(namespace))\r\n throw Error(\"illegal namespace: \"+namespace);\r\n namespace.split(\".\").forEach(function(part) {\r\n var ns = this.ptr.getChild(part);\r\n if (ns === null) // Keep existing\r\n this.ptr.addChild(ns = new Reflect.Namespace(this, this.ptr, part));\r\n this.ptr = ns;\r\n }, this);\r\n return this;\r\n };\r\n\r\n /**\r\n * Creates the specified definitions at the current pointer position.\r\n * @param {!Array.} defs Messages, enums or services to create\r\n * @returns {!ProtoBuf.Builder} this\r\n * @throws {Error} If a message definition is invalid\r\n * @expose\r\n */\r\n BuilderPrototype.create = function(defs) {\r\n if (!defs)\r\n return this; // Nothing to create\r\n if (!Array.isArray(defs))\r\n defs = [defs];\r\n else {\r\n if (defs.length === 0)\r\n return this;\r\n defs = defs.slice();\r\n }\r\n\r\n // It's quite hard to keep track of scopes and memory here, so let's do this iteratively.\r\n var stack = [defs];\r\n while (stack.length > 0) {\r\n defs = stack.pop();\r\n\r\n if (!Array.isArray(defs)) // Stack always contains entire namespaces\r\n throw Error(\"not a valid namespace: \"+JSON.stringify(defs));\r\n\r\n while (defs.length > 0) {\r\n var def = defs.shift(); // Namespaces always contain an array of messages, enums and services\r\n\r\n if (Builder.isMessage(def)) {\r\n var obj = new Reflect.Message(this, this.ptr, def[\"name\"], def[\"options\"], def[\"isGroup\"], def[\"syntax\"]);\r\n\r\n // Create OneOfs\r\n var oneofs = {};\r\n if (def[\"oneofs\"])\r\n Object.keys(def[\"oneofs\"]).forEach(function(name) {\r\n obj.addChild(oneofs[name] = new Reflect.Message.OneOf(this, obj, name));\r\n }, this);\r\n\r\n // Create fields\r\n if (def[\"fields\"])\r\n def[\"fields\"].forEach(function(fld) {\r\n if (obj.getChild(fld[\"id\"]|0) !== null)\r\n throw Error(\"duplicate or invalid field id in \"+obj.name+\": \"+fld['id']);\r\n if (fld[\"options\"] && typeof fld[\"options\"] !== 'object')\r\n throw Error(\"illegal field options in \"+obj.name+\"#\"+fld[\"name\"]);\r\n var oneof = null;\r\n if (typeof fld[\"oneof\"] === 'string' && !(oneof = oneofs[fld[\"oneof\"]]))\r\n throw Error(\"illegal oneof in \"+obj.name+\"#\"+fld[\"name\"]+\": \"+fld[\"oneof\"]);\r\n fld = new Reflect.Message.Field(this, obj, fld[\"rule\"], fld[\"keytype\"], fld[\"type\"], fld[\"name\"], fld[\"id\"], fld[\"options\"], oneof, def[\"syntax\"]);\r\n if (oneof)\r\n oneof.fields.push(fld);\r\n obj.addChild(fld);\r\n }, this);\r\n\r\n // Push children to stack\r\n var subObj = [];\r\n if (def[\"enums\"])\r\n def[\"enums\"].forEach(function(enm) {\r\n subObj.push(enm);\r\n });\r\n if (def[\"messages\"])\r\n def[\"messages\"].forEach(function(msg) {\r\n subObj.push(msg);\r\n });\r\n if (def[\"services\"])\r\n def[\"services\"].forEach(function(svc) {\r\n subObj.push(svc);\r\n });\r\n\r\n // Set extension range\r\n if (def[\"extensions\"]) {\r\n obj.extensions = def[\"extensions\"];\r\n if (obj.extensions[0] < ProtoBuf.ID_MIN)\r\n obj.extensions[0] = ProtoBuf.ID_MIN;\r\n if (obj.extensions[1] > ProtoBuf.ID_MAX)\r\n obj.extensions[1] = ProtoBuf.ID_MAX;\r\n }\r\n\r\n // Create on top of current namespace\r\n this.ptr.addChild(obj);\r\n if (subObj.length > 0) {\r\n stack.push(defs); // Push the current level back\r\n defs = subObj; // Continue processing sub level\r\n subObj = null;\r\n this.ptr = obj; // And move the pointer to this namespace\r\n obj = null;\r\n continue;\r\n }\r\n subObj = null;\r\n\r\n } else if (Builder.isEnum(def)) {\r\n\r\n obj = new Reflect.Enum(this, this.ptr, def[\"name\"], def[\"options\"], def[\"syntax\"]);\r\n def[\"values\"].forEach(function(val) {\r\n obj.addChild(new Reflect.Enum.Value(this, obj, val[\"name\"], val[\"id\"]));\r\n }, this);\r\n this.ptr.addChild(obj);\r\n\r\n } else if (Builder.isService(def)) {\r\n\r\n obj = new Reflect.Service(this, this.ptr, def[\"name\"], def[\"options\"]);\r\n Object.keys(def[\"rpc\"]).forEach(function(name) {\r\n var mtd = def[\"rpc\"][name];\r\n obj.addChild(new Reflect.Service.RPCMethod(this, obj, name, mtd[\"request\"], mtd[\"response\"], !!mtd[\"request_stream\"], !!mtd[\"response_stream\"], mtd[\"options\"]));\r\n }, this);\r\n this.ptr.addChild(obj);\r\n\r\n } else if (Builder.isExtend(def)) {\r\n\r\n obj = this.ptr.resolve(def[\"ref\"], true);\r\n if (obj) {\r\n def[\"fields\"].forEach(function(fld) {\r\n if (obj.getChild(fld['id']|0) !== null)\r\n throw Error(\"duplicate extended field id in \"+obj.name+\": \"+fld['id']);\r\n if (fld['id'] < obj.extensions[0] || fld['id'] > obj.extensions[1])\r\n throw Error(\"illegal extended field id in \"+obj.name+\": \"+fld['id']+\" (\"+obj.extensions.join(' to ')+\" expected)\");\r\n // Convert extension field names to camel case notation if the override is set\r\n var name = fld[\"name\"];\r\n if (this.options['convertFieldsToCamelCase'])\r\n name = ProtoBuf.Util.toCamelCase(name);\r\n // see #161: Extensions use their fully qualified name as their runtime key and...\r\n var field = new Reflect.Message.ExtensionField(this, obj, fld[\"rule\"], fld[\"type\"], this.ptr.fqn()+'.'+name, fld[\"id\"], fld[\"options\"]);\r\n // ...are added on top of the current namespace as an extension which is used for\r\n // resolving their type later on (the extension always keeps the original name to\r\n // prevent naming collisions)\r\n var ext = new Reflect.Extension(this, this.ptr, fld[\"name\"], field);\r\n field.extension = ext;\r\n this.ptr.addChild(ext);\r\n obj.addChild(field);\r\n }, this);\r\n\r\n } else if (!/\\.?google\\.protobuf\\./.test(def[\"ref\"])) // Silently skip internal extensions\r\n throw Error(\"extended message \"+def[\"ref\"]+\" is not defined\");\r\n\r\n } else\r\n throw Error(\"not a valid definition: \"+JSON.stringify(def));\r\n\r\n def = null;\r\n obj = null;\r\n }\r\n // Break goes here\r\n defs = null;\r\n this.ptr = this.ptr.parent; // Namespace done, continue at parent\r\n }\r\n this.resolved = false; // Require re-resolve\r\n this.result = null; // Require re-build\r\n return this;\r\n };\r\n\r\n /**\r\n * Propagates syntax to all children.\r\n * @param {!Object} parent\r\n * @inner\r\n */\r\n function propagateSyntax(parent) {\r\n if (parent['messages']) {\r\n parent['messages'].forEach(function(child) {\r\n child[\"syntax\"] = parent[\"syntax\"];\r\n propagateSyntax(child);\r\n });\r\n }\r\n if (parent['enums']) {\r\n parent['enums'].forEach(function(child) {\r\n child[\"syntax\"] = parent[\"syntax\"];\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Imports another definition into this builder.\r\n * @param {Object.} json Parsed import\r\n * @param {(string|{root: string, file: string})=} filename Imported file name\r\n * @returns {!ProtoBuf.Builder} this\r\n * @throws {Error} If the definition or file cannot be imported\r\n * @expose\r\n */\r\n BuilderPrototype[\"import\"] = function(json, filename) {\r\n var delim = '/';\r\n\r\n // Make sure to skip duplicate imports\r\n\r\n if (typeof filename === 'string') {\r\n\r\n if (ProtoBuf.Util.IS_NODE)\r\n filename = require(\"path\")['resolve'](filename);\r\n if (this.files[filename] === true)\r\n return this.reset();\r\n this.files[filename] = true;\r\n\r\n } else if (typeof filename === 'object') { // Object with root, file.\r\n\r\n var root = filename.root;\r\n if (ProtoBuf.Util.IS_NODE)\r\n root = require(\"path\")['resolve'](root);\r\n if (root.indexOf(\"\\\\\") >= 0 || filename.file.indexOf(\"\\\\\") >= 0)\r\n delim = '\\\\';\r\n var fname = root + delim + filename.file;\r\n if (this.files[fname] === true)\r\n return this.reset();\r\n this.files[fname] = true;\r\n }\r\n\r\n // Import imports\r\n\r\n if (json['imports'] && json['imports'].length > 0) {\r\n var importRoot,\r\n resetRoot = false;\r\n\r\n if (typeof filename === 'object') { // If an import root is specified, override\r\n\r\n this.importRoot = filename[\"root\"]; resetRoot = true; // ... and reset afterwards\r\n importRoot = this.importRoot;\r\n filename = filename[\"file\"];\r\n if (importRoot.indexOf(\"\\\\\") >= 0 || filename.indexOf(\"\\\\\") >= 0)\r\n delim = '\\\\';\r\n\r\n } else if (typeof filename === 'string') {\r\n\r\n if (this.importRoot) // If import root is overridden, use it\r\n importRoot = this.importRoot;\r\n else { // Otherwise compute from filename\r\n if (filename.indexOf(\"/\") >= 0) { // Unix\r\n importRoot = filename.replace(/\\/[^\\/]*$/, \"\");\r\n if (/* /file.proto */ importRoot === \"\")\r\n importRoot = \"/\";\r\n } else if (filename.indexOf(\"\\\\\") >= 0) { // Windows\r\n importRoot = filename.replace(/\\\\[^\\\\]*$/, \"\");\r\n delim = '\\\\';\r\n } else\r\n importRoot = \".\";\r\n }\r\n\r\n } else\r\n importRoot = null;\r\n\r\n for (var i=0; i)=} path Specifies what to return. If omitted, the entire namespace will be returned.\r\n * @returns {!ProtoBuf.Builder.Message|!Object.}\r\n * @throws {Error} If a type could not be resolved\r\n * @expose\r\n */\r\n BuilderPrototype.build = function(path) {\r\n this.reset();\r\n if (!this.resolved)\r\n this.resolveAll(),\r\n this.resolved = true,\r\n this.result = null; // Require re-build\r\n if (this.result === null) // (Re-)Build\r\n this.result = this.ns.build();\r\n if (!path)\r\n return this.result;\r\n var part = typeof path === 'string' ? path.split(\".\") : path,\r\n ptr = this.result; // Build namespace pointer (no hasChild etc.)\r\n for (var i=0; i=} contents Initial contents\r\n * @constructor\r\n */\r\n var Map = function(field, contents) {\r\n if (!field.map)\r\n throw Error(\"field is not a map\");\r\n\r\n /**\r\n * The field corresponding to this map.\r\n * @type {!ProtoBuf.Reflect.Field}\r\n */\r\n this.field = field;\r\n\r\n /**\r\n * Element instance corresponding to key type.\r\n * @type {!ProtoBuf.Reflect.Element}\r\n */\r\n this.keyElem = new Reflect.Element(field.keyType, null, true, field.syntax);\r\n\r\n /**\r\n * Element instance corresponding to value type.\r\n * @type {!ProtoBuf.Reflect.Element}\r\n */\r\n this.valueElem = new Reflect.Element(field.type, field.resolvedType, false, field.syntax);\r\n\r\n /**\r\n * Internal map: stores mapping of (string form of key) -> (key, value)\r\n * pair.\r\n *\r\n * We provide map semantics for arbitrary key types, but we build on top\r\n * of an Object, which has only string keys. In order to avoid the need\r\n * to convert a string key back to its native type in many situations,\r\n * we store the native key value alongside the value. Thus, we only need\r\n * a one-way mapping from a key type to its string form that guarantees\r\n * uniqueness and equality (i.e., str(K1) === str(K2) if and only if K1\r\n * === K2).\r\n *\r\n * @type {!Object}\r\n */\r\n this.map = {};\r\n\r\n /**\r\n * Returns the number of elements in the map.\r\n */\r\n Object.defineProperty(this, \"size\", {\r\n get: function() { return Object.keys(this.map).length; }\r\n });\r\n\r\n // Fill initial contents from a raw object.\r\n if (contents) {\r\n var keys = Object.keys(contents);\r\n for (var i = 0; i < keys.length; i++) {\r\n var key = this.keyElem.valueFromString(keys[i]);\r\n var val = this.valueElem.verifyValue(contents[keys[i]]);\r\n this.map[this.keyElem.valueToString(key)] =\r\n { key: key, value: val };\r\n }\r\n }\r\n };\r\n\r\n var MapPrototype = Map.prototype;\r\n\r\n /**\r\n * Helper: return an iterator over an array.\r\n * @param {!Array<*>} arr the array\r\n * @returns {!Object} an iterator\r\n * @inner\r\n */\r\n function arrayIterator(arr) {\r\n var idx = 0;\r\n return {\r\n next: function() {\r\n if (idx < arr.length)\r\n return { done: false, value: arr[idx++] };\r\n return { done: true };\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clears the map.\r\n */\r\n MapPrototype.clear = function() {\r\n this.map = {};\r\n };\r\n\r\n /**\r\n * Deletes a particular key from the map.\r\n * @returns {boolean} Whether any entry with this key was deleted.\r\n */\r\n MapPrototype[\"delete\"] = function(key) {\r\n var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));\r\n var hadKey = keyValue in this.map;\r\n delete this.map[keyValue];\r\n return hadKey;\r\n };\r\n\r\n /**\r\n * Returns an iterator over [key, value] pairs in the map.\r\n * @returns {Object} The iterator\r\n */\r\n MapPrototype.entries = function() {\r\n var entries = [];\r\n var strKeys = Object.keys(this.map);\r\n for (var i = 0, entry; i < strKeys.length; i++)\r\n entries.push([(entry=this.map[strKeys[i]]).key, entry.value]);\r\n return arrayIterator(entries);\r\n };\r\n\r\n /**\r\n * Returns an iterator over keys in the map.\r\n * @returns {Object} The iterator\r\n */\r\n MapPrototype.keys = function() {\r\n var keys = [];\r\n var strKeys = Object.keys(this.map);\r\n for (var i = 0; i < strKeys.length; i++)\r\n keys.push(this.map[strKeys[i]].key);\r\n return arrayIterator(keys);\r\n };\r\n\r\n /**\r\n * Returns an iterator over values in the map.\r\n * @returns {!Object} The iterator\r\n */\r\n MapPrototype.values = function() {\r\n var values = [];\r\n var strKeys = Object.keys(this.map);\r\n for (var i = 0; i < strKeys.length; i++)\r\n values.push(this.map[strKeys[i]].value);\r\n return arrayIterator(values);\r\n };\r\n\r\n /**\r\n * Iterates over entries in the map, calling a function on each.\r\n * @param {function(this:*, *, *, *)} cb The callback to invoke with value, key, and map arguments.\r\n * @param {Object=} thisArg The `this` value for the callback\r\n */\r\n MapPrototype.forEach = function(cb, thisArg) {\r\n var strKeys = Object.keys(this.map);\r\n for (var i = 0, entry; i < strKeys.length; i++)\r\n cb.call(thisArg, (entry=this.map[strKeys[i]]).value, entry.key, this);\r\n };\r\n\r\n /**\r\n * Sets a key in the map to the given value.\r\n * @param {*} key The key\r\n * @param {*} value The value\r\n * @returns {!ProtoBuf.Map} The map instance\r\n */\r\n MapPrototype.set = function(key, value) {\r\n var keyValue = this.keyElem.verifyValue(key);\r\n var valValue = this.valueElem.verifyValue(value);\r\n this.map[this.keyElem.valueToString(keyValue)] =\r\n { key: keyValue, value: valValue };\r\n return this;\r\n };\r\n\r\n /**\r\n * Gets the value corresponding to a key in the map.\r\n * @param {*} key The key\r\n * @returns {*|undefined} The value, or `undefined` if key not present\r\n */\r\n MapPrototype.get = function(key) {\r\n var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));\r\n if (!(keyValue in this.map))\r\n return undefined;\r\n return this.map[keyValue].value;\r\n };\r\n\r\n /**\r\n * Determines whether the given key is present in the map.\r\n * @param {*} key The key\r\n * @returns {boolean} `true` if the key is present\r\n */\r\n MapPrototype.has = function(key) {\r\n var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));\r\n return (keyValue in this.map);\r\n };\r\n\r\n return Map;\r\n })(ProtoBuf, ProtoBuf.Reflect);\r\n\r\n\r\n /**\r\n * Loads a .proto string and returns the Builder.\r\n * @param {string} proto .proto file contents\r\n * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted.\r\n * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r\n * @return {ProtoBuf.Builder} Builder to create new messages\r\n * @throws {Error} If the definition cannot be parsed or built\r\n * @expose\r\n */\r\n ProtoBuf.loadProto = function(proto, builder, filename) {\r\n if (typeof builder === 'string' || (builder && typeof builder[\"file\"] === 'string' && typeof builder[\"root\"] === 'string'))\r\n filename = builder,\r\n builder = undefined;\r\n return ProtoBuf.loadJson(ProtoBuf.DotProto.Parser.parse(proto), builder, filename);\r\n };\r\n\r\n /**\r\n * Loads a .proto string and returns the Builder. This is an alias of {@link ProtoBuf.loadProto}.\r\n * @function\r\n * @param {string} proto .proto file contents\r\n * @param {(ProtoBuf.Builder|string)=} builder Builder to append to. Will create a new one if omitted.\r\n * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r\n * @return {ProtoBuf.Builder} Builder to create new messages\r\n * @throws {Error} If the definition cannot be parsed or built\r\n * @expose\r\n */\r\n ProtoBuf.protoFromString = ProtoBuf.loadProto; // Legacy\r\n\r\n /**\r\n * Loads a .proto file and returns the Builder.\r\n * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with\r\n * an overridden 'root' path for all imported files.\r\n * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r\n * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r\n * file will be read synchronously and this function will return the Builder.\r\n * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r\n * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r\n * request has failed), else undefined\r\n * @expose\r\n */\r\n ProtoBuf.loadProtoFile = function(filename, callback, builder) {\r\n if (callback && typeof callback === 'object')\r\n builder = callback,\r\n callback = null;\r\n else if (!callback || typeof callback !== 'function')\r\n callback = null;\r\n if (callback)\r\n return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename[\"root\"]+\"/\"+filename[\"file\"], function(contents) {\r\n if (contents === null) {\r\n callback(Error(\"Failed to fetch file\"));\r\n return;\r\n }\r\n try {\r\n callback(null, ProtoBuf.loadProto(contents, builder, filename));\r\n } catch (e) {\r\n callback(e);\r\n }\r\n });\r\n var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename[\"root\"]+\"/\"+filename[\"file\"] : filename);\r\n return contents === null ? null : ProtoBuf.loadProto(contents, builder, filename);\r\n };\r\n\r\n /**\r\n * Loads a .proto file and returns the Builder. This is an alias of {@link ProtoBuf.loadProtoFile}.\r\n * @function\r\n * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with\r\n * an overridden 'root' path for all imported files.\r\n * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r\n * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r\n * file will be read synchronously and this function will return the Builder.\r\n * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r\n * @return {!ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r\n * request has failed), else undefined\r\n * @expose\r\n */\r\n ProtoBuf.protoFromFile = ProtoBuf.loadProtoFile; // Legacy\r\n\r\n\r\n /**\r\n * Constructs a new empty Builder.\r\n * @param {Object.=} options Builder options, defaults to global options set on ProtoBuf\r\n * @return {!ProtoBuf.Builder} Builder\r\n * @expose\r\n */\r\n ProtoBuf.newBuilder = function(options) {\r\n options = options || {};\r\n if (typeof options['convertFieldsToCamelCase'] === 'undefined')\r\n options['convertFieldsToCamelCase'] = ProtoBuf.convertFieldsToCamelCase;\r\n if (typeof options['populateAccessors'] === 'undefined')\r\n options['populateAccessors'] = ProtoBuf.populateAccessors;\r\n return new ProtoBuf.Builder(options);\r\n };\r\n\r\n /**\r\n * Loads a .json definition and returns the Builder.\r\n * @param {!*|string} json JSON definition\r\n * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted.\r\n * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r\n * @return {ProtoBuf.Builder} Builder to create new messages\r\n * @throws {Error} If the definition cannot be parsed or built\r\n * @expose\r\n */\r\n ProtoBuf.loadJson = function(json, builder, filename) {\r\n if (typeof builder === 'string' || (builder && typeof builder[\"file\"] === 'string' && typeof builder[\"root\"] === 'string'))\r\n filename = builder,\r\n builder = null;\r\n if (!builder || typeof builder !== 'object')\r\n builder = ProtoBuf.newBuilder();\r\n if (typeof json === 'string')\r\n json = JSON.parse(json);\r\n builder[\"import\"](json, filename);\r\n builder.resolveAll();\r\n return builder;\r\n };\r\n\r\n /**\r\n * Loads a .json file and returns the Builder.\r\n * @param {string|!{root: string, file: string}} filename Path to json file or an object specifying 'file' with\r\n * an overridden 'root' path for all imported files.\r\n * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r\n * the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r\n * file will be read synchronously and this function will return the Builder.\r\n * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r\n * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r\n * request has failed), else undefined\r\n * @expose\r\n */\r\n ProtoBuf.loadJsonFile = function(filename, callback, builder) {\r\n if (callback && typeof callback === 'object')\r\n builder = callback,\r\n callback = null;\r\n else if (!callback || typeof callback !== 'function')\r\n callback = null;\r\n if (callback)\r\n return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename[\"root\"]+\"/\"+filename[\"file\"], function(contents) {\r\n if (contents === null) {\r\n callback(Error(\"Failed to fetch file\"));\r\n return;\r\n }\r\n try {\r\n callback(null, ProtoBuf.loadJson(JSON.parse(contents), builder, filename));\r\n } catch (e) {\r\n callback(e);\r\n }\r\n });\r\n var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename[\"root\"]+\"/\"+filename[\"file\"] : filename);\r\n return contents === null ? null : ProtoBuf.loadJson(JSON.parse(contents), builder, filename);\r\n };\r\n\r\n return ProtoBuf;\r\n});\r\n","// shim for using process in browser\n\nvar process = module.exports = {};\nvar queue = [];\nvar draining = false;\nvar currentQueue;\nvar queueIndex = -1;\n\nfunction cleanUpNextTick() {\n draining = false;\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n if (queue.length) {\n drainQueue();\n }\n}\n\nfunction drainQueue() {\n if (draining) {\n return;\n }\n var timeout = setTimeout(cleanUpNextTick);\n draining = true;\n\n var len = queue.length;\n while(len) {\n currentQueue = queue;\n queue = [];\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n queueIndex = -1;\n len = queue.length;\n }\n currentQueue = null;\n draining = false;\n clearTimeout(timeout);\n}\n\nprocess.nextTick = function (fun) {\n var args = new Array(arguments.length - 1);\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n queue.push(new Item(fun, args));\n if (queue.length === 1 && !draining) {\n setTimeout(drainQueue, 0);\n }\n};\n\n// v8 likes predictible objects\nfunction Item(fun, array) {\n this.fun = fun;\n this.array = array;\n}\nItem.prototype.run = function () {\n this.fun.apply(null, this.array);\n};\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\nprocess.version = ''; // empty string to avoid regexp issues\nprocess.versions = {};\n\nfunction noop() {}\n\nprocess.on = noop;\nprocess.addListener = noop;\nprocess.once = noop;\nprocess.off = noop;\nprocess.removeListener = noop;\nprocess.removeAllListeners = noop;\nprocess.emit = noop;\n\nprocess.binding = function (name) {\n throw new Error('process.binding is not supported');\n};\n\nprocess.cwd = function () { return '/' };\nprocess.chdir = function (dir) {\n throw new Error('process.chdir is not supported');\n};\nprocess.umask = function() { return 0; };\n","/*\r\n Copyright 2013-2014 Daniel Wirtz \r\n\r\n Licensed under the Apache License, Version 2.0 (the \"License\");\r\n you may not use this file except in compliance with the License.\r\n You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License.\r\n */\r\n\r\n/**\r\n * @license bytebuffer.js (c) 2015 Daniel Wirtz \r\n * Backing buffer: ArrayBuffer, Accessor: Uint8Array\r\n * Released under the Apache License, Version 2.0\r\n * see: https://github.com/dcodeIO/bytebuffer.js for details\r\n */\r\n(function(global, factory) {\r\n\r\n /* AMD */ if (typeof define === 'function' && define[\"amd\"])\r\n define([\"long\"], factory);\r\n /* CommonJS */ else if (typeof require === 'function' && typeof module === \"object\" && module && module[\"exports\"])\r\n module['exports'] = (function() {\r\n var Long; try { Long = require(\"long\"); } catch (e) {}\r\n return factory(Long);\r\n })();\r\n /* Global */ else\r\n (global[\"dcodeIO\"] = global[\"dcodeIO\"] || {})[\"ByteBuffer\"] = factory(global[\"dcodeIO\"][\"Long\"]);\r\n\r\n})(this, function(Long) {\r\n \"use strict\";\r\n\r\n /**\r\n * Constructs a new ByteBuffer.\r\n * @class The swiss army knife for binary data in JavaScript.\r\n * @exports ByteBuffer\r\n * @constructor\r\n * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @expose\r\n */\r\n var ByteBuffer = function(capacity, littleEndian, noAssert) {\r\n if (typeof capacity === 'undefined')\r\n capacity = ByteBuffer.DEFAULT_CAPACITY;\r\n if (typeof littleEndian === 'undefined')\r\n littleEndian = ByteBuffer.DEFAULT_ENDIAN;\r\n if (typeof noAssert === 'undefined')\r\n noAssert = ByteBuffer.DEFAULT_NOASSERT;\r\n if (!noAssert) {\r\n capacity = capacity | 0;\r\n if (capacity < 0)\r\n throw RangeError(\"Illegal capacity\");\r\n littleEndian = !!littleEndian;\r\n noAssert = !!noAssert;\r\n }\r\n\r\n /**\r\n * Backing ArrayBuffer.\r\n * @type {!ArrayBuffer}\r\n * @expose\r\n */\r\n this.buffer = capacity === 0 ? EMPTY_BUFFER : new ArrayBuffer(capacity);\r\n\r\n /**\r\n * Uint8Array utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`.\r\n * @type {?Uint8Array}\r\n * @expose\r\n */\r\n this.view = capacity === 0 ? null : new Uint8Array(this.buffer);\r\n\r\n /**\r\n * Absolute read/write offset.\r\n * @type {number}\r\n * @expose\r\n * @see ByteBuffer#flip\r\n * @see ByteBuffer#clear\r\n */\r\n this.offset = 0;\r\n\r\n /**\r\n * Marked offset.\r\n * @type {number}\r\n * @expose\r\n * @see ByteBuffer#mark\r\n * @see ByteBuffer#reset\r\n */\r\n this.markedOffset = -1;\r\n\r\n /**\r\n * Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation.\r\n * @type {number}\r\n * @expose\r\n * @see ByteBuffer#flip\r\n * @see ByteBuffer#clear\r\n */\r\n this.limit = capacity;\r\n\r\n /**\r\n * Whether to use little endian byte order, defaults to `false` for big endian.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : false;\r\n\r\n /**\r\n * Whether to skip assertions of offsets and values, defaults to `false`.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.noAssert = !!noAssert;\r\n };\r\n\r\n /**\r\n * ByteBuffer version.\r\n * @type {string}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.VERSION = \"5.0.0\";\r\n\r\n /**\r\n * Little endian constant that can be used instead of its boolean value. Evaluates to `true`.\r\n * @type {boolean}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.LITTLE_ENDIAN = true;\r\n\r\n /**\r\n * Big endian constant that can be used instead of its boolean value. Evaluates to `false`.\r\n * @type {boolean}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.BIG_ENDIAN = false;\r\n\r\n /**\r\n * Default initial capacity of `16`.\r\n * @type {number}\r\n * @expose\r\n */\r\n ByteBuffer.DEFAULT_CAPACITY = 16;\r\n\r\n /**\r\n * Default endianess of `false` for big endian.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n ByteBuffer.DEFAULT_ENDIAN = ByteBuffer.BIG_ENDIAN;\r\n\r\n /**\r\n * Default no assertions flag of `false`.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n ByteBuffer.DEFAULT_NOASSERT = false;\r\n\r\n /**\r\n * A `Long` class for representing a 64-bit two's-complement integer value. May be `null` if Long.js has not been loaded\r\n * and int64 support is not available.\r\n * @type {?Long}\r\n * @const\r\n * @see https://github.com/dcodeIO/Long.js\r\n * @expose\r\n */\r\n ByteBuffer.Long = Long || null;\r\n\r\n /**\r\n * @alias ByteBuffer.prototype\r\n * @inner\r\n */\r\n var ByteBufferPrototype = ByteBuffer.prototype;\r\n\r\n /**\r\n * An indicator used to reliably determine if an object is a ByteBuffer or not.\r\n * @type {boolean}\r\n * @const\r\n * @expose\r\n * @private\r\n */\r\n ByteBufferPrototype.__isByteBuffer__;\r\n\r\n Object.defineProperty(ByteBufferPrototype, \"__isByteBuffer__\", {\r\n value: true,\r\n enumerable: false,\r\n configurable: false\r\n });\r\n\r\n // helpers\r\n\r\n /**\r\n * @type {!ArrayBuffer}\r\n * @inner\r\n */\r\n var EMPTY_BUFFER = new ArrayBuffer(0);\r\n\r\n /**\r\n * String.fromCharCode reference for compile-time renaming.\r\n * @type {function(...number):string}\r\n * @inner\r\n */\r\n var stringFromCharCode = String.fromCharCode;\r\n\r\n /**\r\n * Creates a source function for a string.\r\n * @param {string} s String to read from\r\n * @returns {function():number|null} Source function returning the next char code respectively `null` if there are\r\n * no more characters left.\r\n * @throws {TypeError} If the argument is invalid\r\n * @inner\r\n */\r\n function stringSource(s) {\r\n var i=0; return function() {\r\n return i < s.length ? s.charCodeAt(i++) : null;\r\n };\r\n }\r\n\r\n /**\r\n * Creates a destination function for a string.\r\n * @returns {function(number=):undefined|string} Destination function successively called with the next char code.\r\n * Returns the final string when called without arguments.\r\n * @inner\r\n */\r\n function stringDestination() {\r\n var cs = [], ps = []; return function() {\r\n if (arguments.length === 0)\r\n return ps.join('')+stringFromCharCode.apply(String, cs);\r\n if (cs.length + arguments.length > 1024)\r\n ps.push(stringFromCharCode.apply(String, cs)),\r\n cs.length = 0;\r\n Array.prototype.push.apply(cs, arguments);\r\n };\r\n }\r\n\r\n /**\r\n * Gets the accessor type.\r\n * @returns {Function} `Buffer` under node.js, `Uint8Array` respectively `DataView` in the browser (classes)\r\n * @expose\r\n */\r\n ByteBuffer.accessor = function() {\r\n return Uint8Array;\r\n };\r\n /**\r\n * Allocates a new ByteBuffer backed by a buffer of the specified capacity.\r\n * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer}\r\n * @expose\r\n */\r\n ByteBuffer.allocate = function(capacity, littleEndian, noAssert) {\r\n return new ByteBuffer(capacity, littleEndian, noAssert);\r\n };\r\n\r\n /**\r\n * Concatenates multiple ByteBuffers into one.\r\n * @param {!Array.} buffers Buffers to concatenate\r\n * @param {(string|boolean)=} encoding String encoding if `buffers` contains a string (\"base64\", \"hex\", \"binary\",\r\n * defaults to \"utf8\")\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order for the resulting ByteBuffer. Defaults\r\n * to {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values for the resulting ByteBuffer. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer} Concatenated ByteBuffer\r\n * @expose\r\n */\r\n ByteBuffer.concat = function(buffers, encoding, littleEndian, noAssert) {\r\n if (typeof encoding === 'boolean' || typeof encoding !== 'string') {\r\n noAssert = littleEndian;\r\n littleEndian = encoding;\r\n encoding = undefined;\r\n }\r\n var capacity = 0;\r\n for (var i=0, k=buffers.length, length; i 0) capacity += length;\r\n }\r\n if (capacity === 0)\r\n return new ByteBuffer(0, littleEndian, noAssert);\r\n var bb = new ByteBuffer(capacity, littleEndian, noAssert),\r\n bi;\r\n i=0; while (i} buffer Anything that can be wrapped\r\n * @param {(string|boolean)=} encoding String encoding if `buffer` is a string (\"base64\", \"hex\", \"binary\", defaults to\r\n * \"utf8\")\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer} A ByteBuffer wrapping `buffer`\r\n * @expose\r\n */\r\n ByteBuffer.wrap = function(buffer, encoding, littleEndian, noAssert) {\r\n if (typeof encoding !== 'string') {\r\n noAssert = littleEndian;\r\n littleEndian = encoding;\r\n encoding = undefined;\r\n }\r\n if (typeof buffer === 'string') {\r\n if (typeof encoding === 'undefined')\r\n encoding = \"utf8\";\r\n switch (encoding) {\r\n case \"base64\":\r\n return ByteBuffer.fromBase64(buffer, littleEndian);\r\n case \"hex\":\r\n return ByteBuffer.fromHex(buffer, littleEndian);\r\n case \"binary\":\r\n return ByteBuffer.fromBinary(buffer, littleEndian);\r\n case \"utf8\":\r\n return ByteBuffer.fromUTF8(buffer, littleEndian);\r\n case \"debug\":\r\n return ByteBuffer.fromDebug(buffer, littleEndian);\r\n default:\r\n throw Error(\"Unsupported encoding: \"+encoding);\r\n }\r\n }\r\n if (buffer === null || typeof buffer !== 'object')\r\n throw TypeError(\"Illegal buffer\");\r\n var bb;\r\n if (ByteBuffer.isByteBuffer(buffer)) {\r\n bb = ByteBufferPrototype.clone.call(buffer);\r\n bb.markedOffset = -1;\r\n return bb;\r\n }\r\n if (buffer instanceof Uint8Array) { // Extract ArrayBuffer from Uint8Array\r\n bb = new ByteBuffer(0, littleEndian, noAssert);\r\n if (buffer.length > 0) { // Avoid references to more than one EMPTY_BUFFER\r\n bb.buffer = buffer.buffer;\r\n bb.offset = buffer.byteOffset;\r\n bb.limit = buffer.byteOffset + buffer.byteLength;\r\n bb.view = new Uint8Array(buffer.buffer);\r\n }\r\n } else if (buffer instanceof ArrayBuffer) { // Reuse ArrayBuffer\r\n bb = new ByteBuffer(0, littleEndian, noAssert);\r\n if (buffer.byteLength > 0) {\r\n bb.buffer = buffer;\r\n bb.offset = 0;\r\n bb.limit = buffer.byteLength;\r\n bb.view = buffer.byteLength > 0 ? new Uint8Array(buffer) : null;\r\n }\r\n } else if (Object.prototype.toString.call(buffer) === \"[object Array]\") { // Create from octets\r\n bb = new ByteBuffer(buffer.length, littleEndian, noAssert);\r\n bb.limit = buffer.length;\r\n for (var i=0; i>>= 0;\n if (offset < 0 || offset + length > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+length+\") <= \"+this.buffer.byteLength);\n }\r\n var slice = this.slice(offset, offset + length);\r\n if (relative) this.offset += length;\n return slice;\r\n };\r\n\r\n /**\r\n * Writes a payload of bytes. This is an alias of {@link ByteBuffer#append}.\r\n * @function\r\n * @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to write. If `source` is a ByteBuffer, its offsets\r\n * will be modified according to the performed read operation.\r\n * @param {(string|number)=} encoding Encoding if `data` is a string (\"base64\", \"hex\", \"binary\", defaults to \"utf8\")\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeBytes = ByteBufferPrototype.append;\r\n\r\n // types/ints/int8\r\n\r\n /**\r\n * Writes an 8bit signed integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeInt8 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value |= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 1;\n var capacity0 = this.buffer.byteLength;\n if (offset > capacity0)\n this.resize((capacity0 *= 2) > offset ? capacity0 : offset);\n offset -= 1;\n this.view[offset] = value;\r\n if (relative) this.offset += 1;\n return this;\r\n };\r\n\r\n /**\r\n * Writes an 8bit signed integer. This is an alias of {@link ByteBuffer#writeInt8}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeByte = ByteBufferPrototype.writeInt8;\r\n\r\n /**\r\n * Reads an 8bit signed integer.\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readInt8 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n var value = this.view[offset];\r\n if ((value & 0x80) === 0x80) value = -(0xFF - value + 1); // Cast to signed\r\n if (relative) this.offset += 1;\n return value;\r\n };\r\n\r\n /**\r\n * Reads an 8bit signed integer. This is an alias of {@link ByteBuffer#readInt8}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readByte = ByteBufferPrototype.readInt8;\r\n\r\n /**\r\n * Writes an 8bit unsigned integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUint8 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value >>>= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 1;\n var capacity1 = this.buffer.byteLength;\n if (offset > capacity1)\n this.resize((capacity1 *= 2) > offset ? capacity1 : offset);\n offset -= 1;\n this.view[offset] = value;\r\n if (relative) this.offset += 1;\n return this;\r\n };\r\n\r\n /**\r\n * Writes an 8bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint8}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUInt8 = ByteBufferPrototype.writeUint8;\r\n\r\n /**\r\n * Reads an 8bit unsigned integer.\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUint8 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n var value = this.view[offset];\r\n if (relative) this.offset += 1;\n return value;\r\n };\r\n\r\n /**\r\n * Reads an 8bit unsigned integer. This is an alias of {@link ByteBuffer#readUint8}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUInt8 = ByteBufferPrototype.readUint8;\r\n\r\n // types/ints/int16\r\n\r\n /**\r\n * Writes a 16bit signed integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @throws {TypeError} If `offset` or `value` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeInt16 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value |= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 2;\n var capacity2 = this.buffer.byteLength;\n if (offset > capacity2)\n this.resize((capacity2 *= 2) > offset ? capacity2 : offset);\n offset -= 2;\n if (this.littleEndian) {\r\n this.view[offset+1] = (value & 0xFF00) >>> 8;\r\n this.view[offset ] = value & 0x00FF;\r\n } else {\r\n this.view[offset] = (value & 0xFF00) >>> 8;\r\n this.view[offset+1] = value & 0x00FF;\r\n }\r\n if (relative) this.offset += 2;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 16bit signed integer. This is an alias of {@link ByteBuffer#writeInt16}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @throws {TypeError} If `offset` or `value` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeShort = ByteBufferPrototype.writeInt16;\r\n\r\n /**\r\n * Reads a 16bit signed integer.\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @returns {number} Value read\r\n * @throws {TypeError} If `offset` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.readInt16 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 2 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+2+\") <= \"+this.buffer.byteLength);\n }\r\n var value = 0;\r\n if (this.littleEndian) {\r\n value = this.view[offset ];\r\n value |= this.view[offset+1] << 8;\r\n } else {\r\n value = this.view[offset ] << 8;\r\n value |= this.view[offset+1];\r\n }\r\n if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1); // Cast to signed\r\n if (relative) this.offset += 2;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 16bit signed integer. This is an alias of {@link ByteBuffer#readInt16}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @returns {number} Value read\r\n * @throws {TypeError} If `offset` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.readShort = ByteBufferPrototype.readInt16;\r\n\r\n /**\r\n * Writes a 16bit unsigned integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @throws {TypeError} If `offset` or `value` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUint16 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value >>>= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 2;\n var capacity3 = this.buffer.byteLength;\n if (offset > capacity3)\n this.resize((capacity3 *= 2) > offset ? capacity3 : offset);\n offset -= 2;\n if (this.littleEndian) {\r\n this.view[offset+1] = (value & 0xFF00) >>> 8;\r\n this.view[offset ] = value & 0x00FF;\r\n } else {\r\n this.view[offset] = (value & 0xFF00) >>> 8;\r\n this.view[offset+1] = value & 0x00FF;\r\n }\r\n if (relative) this.offset += 2;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 16bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint16}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @throws {TypeError} If `offset` or `value` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUInt16 = ByteBufferPrototype.writeUint16;\r\n\r\n /**\r\n * Reads a 16bit unsigned integer.\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @returns {number} Value read\r\n * @throws {TypeError} If `offset` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUint16 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 2 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+2+\") <= \"+this.buffer.byteLength);\n }\r\n var value = 0;\r\n if (this.littleEndian) {\r\n value = this.view[offset ];\r\n value |= this.view[offset+1] << 8;\r\n } else {\r\n value = this.view[offset ] << 8;\r\n value |= this.view[offset+1];\r\n }\r\n if (relative) this.offset += 2;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 16bit unsigned integer. This is an alias of {@link ByteBuffer#readUint16}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.\r\n * @returns {number} Value read\r\n * @throws {TypeError} If `offset` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUInt16 = ByteBufferPrototype.readUint16;\r\n\r\n // types/ints/int32\r\n\r\n /**\r\n * Writes a 32bit signed integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeInt32 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value |= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 4;\n var capacity4 = this.buffer.byteLength;\n if (offset > capacity4)\n this.resize((capacity4 *= 2) > offset ? capacity4 : offset);\n offset -= 4;\n if (this.littleEndian) {\n this.view[offset+3] = (value >>> 24) & 0xFF;\n this.view[offset+2] = (value >>> 16) & 0xFF;\n this.view[offset+1] = (value >>> 8) & 0xFF;\n this.view[offset ] = value & 0xFF;\n } else {\n this.view[offset ] = (value >>> 24) & 0xFF;\n this.view[offset+1] = (value >>> 16) & 0xFF;\n this.view[offset+2] = (value >>> 8) & 0xFF;\n this.view[offset+3] = value & 0xFF;\n }\n if (relative) this.offset += 4;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32;\r\n\r\n /**\r\n * Reads a 32bit signed integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readInt32 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 4 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+4+\") <= \"+this.buffer.byteLength);\n }\r\n var value = 0;\r\n if (this.littleEndian) {\n value = this.view[offset+2] << 16;\n value |= this.view[offset+1] << 8;\n value |= this.view[offset ];\n value += this.view[offset+3] << 24 >>> 0;\n } else {\n value = this.view[offset+1] << 16;\n value |= this.view[offset+2] << 8;\n value |= this.view[offset+3];\n value += this.view[offset ] << 24 >>> 0;\n }\n value |= 0; // Cast to signed\r\n if (relative) this.offset += 4;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 32bit signed integer. This is an alias of {@link ByteBuffer#readInt32}.\r\n * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32;\r\n\r\n /**\r\n * Writes a 32bit unsigned integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUint32 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value >>>= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 4;\n var capacity5 = this.buffer.byteLength;\n if (offset > capacity5)\n this.resize((capacity5 *= 2) > offset ? capacity5 : offset);\n offset -= 4;\n if (this.littleEndian) {\n this.view[offset+3] = (value >>> 24) & 0xFF;\n this.view[offset+2] = (value >>> 16) & 0xFF;\n this.view[offset+1] = (value >>> 8) & 0xFF;\n this.view[offset ] = value & 0xFF;\n } else {\n this.view[offset ] = (value >>> 24) & 0xFF;\n this.view[offset+1] = (value >>> 16) & 0xFF;\n this.view[offset+2] = (value >>> 8) & 0xFF;\n this.view[offset+3] = value & 0xFF;\n }\n if (relative) this.offset += 4;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 32bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint32}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32;\r\n\r\n /**\r\n * Reads a 32bit unsigned integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUint32 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 4 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+4+\") <= \"+this.buffer.byteLength);\n }\r\n var value = 0;\r\n if (this.littleEndian) {\n value = this.view[offset+2] << 16;\n value |= this.view[offset+1] << 8;\n value |= this.view[offset ];\n value += this.view[offset+3] << 24 >>> 0;\n } else {\n value = this.view[offset+1] << 16;\n value |= this.view[offset+2] << 8;\n value |= this.view[offset+3];\n value += this.view[offset ] << 24 >>> 0;\n }\n if (relative) this.offset += 4;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 32bit unsigned integer. This is an alias of {@link ByteBuffer#readUint32}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number} Value read\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32;\r\n\r\n // types/ints/int64\r\n\r\n if (Long) {\r\n\r\n /**\r\n * Writes a 64bit signed integer.\r\n * @param {number|!Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeInt64 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n else if (!(value && value instanceof Long))\n throw TypeError(\"Illegal value: \"+value+\" (not an integer or Long)\");\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n offset += 8;\n var capacity6 = this.buffer.byteLength;\n if (offset > capacity6)\n this.resize((capacity6 *= 2) > offset ? capacity6 : offset);\n offset -= 8;\n var lo = value.low,\r\n hi = value.high;\r\n if (this.littleEndian) {\r\n this.view[offset+3] = (lo >>> 24) & 0xFF;\n this.view[offset+2] = (lo >>> 16) & 0xFF;\n this.view[offset+1] = (lo >>> 8) & 0xFF;\n this.view[offset ] = lo & 0xFF;\n offset += 4;\r\n this.view[offset+3] = (hi >>> 24) & 0xFF;\n this.view[offset+2] = (hi >>> 16) & 0xFF;\n this.view[offset+1] = (hi >>> 8) & 0xFF;\n this.view[offset ] = hi & 0xFF;\n } else {\r\n this.view[offset ] = (hi >>> 24) & 0xFF;\n this.view[offset+1] = (hi >>> 16) & 0xFF;\n this.view[offset+2] = (hi >>> 8) & 0xFF;\n this.view[offset+3] = hi & 0xFF;\n offset += 4;\r\n this.view[offset ] = (lo >>> 24) & 0xFF;\n this.view[offset+1] = (lo >>> 16) & 0xFF;\n this.view[offset+2] = (lo >>> 8) & 0xFF;\n this.view[offset+3] = lo & 0xFF;\n }\r\n if (relative) this.offset += 8;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 64bit signed integer. This is an alias of {@link ByteBuffer#writeInt64}.\r\n * @param {number|!Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeLong = ByteBufferPrototype.writeInt64;\r\n\r\n /**\r\n * Reads a 64bit signed integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readInt64 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 8 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+8+\") <= \"+this.buffer.byteLength);\n }\r\n var lo = 0,\r\n hi = 0;\r\n if (this.littleEndian) {\r\n lo = this.view[offset+2] << 16;\n lo |= this.view[offset+1] << 8;\n lo |= this.view[offset ];\n lo += this.view[offset+3] << 24 >>> 0;\n offset += 4;\r\n hi = this.view[offset+2] << 16;\n hi |= this.view[offset+1] << 8;\n hi |= this.view[offset ];\n hi += this.view[offset+3] << 24 >>> 0;\n } else {\r\n hi = this.view[offset+1] << 16;\n hi |= this.view[offset+2] << 8;\n hi |= this.view[offset+3];\n hi += this.view[offset ] << 24 >>> 0;\n offset += 4;\r\n lo = this.view[offset+1] << 16;\n lo |= this.view[offset+2] << 8;\n lo |= this.view[offset+3];\n lo += this.view[offset ] << 24 >>> 0;\n }\r\n var value = new Long(lo, hi, false);\r\n if (relative) this.offset += 8;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 64bit signed integer. This is an alias of {@link ByteBuffer#readInt64}.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readLong = ByteBufferPrototype.readInt64;\r\n\r\n /**\r\n * Writes a 64bit unsigned integer.\r\n * @param {number|!Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUint64 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n else if (!(value && value instanceof Long))\n throw TypeError(\"Illegal value: \"+value+\" (not an integer or Long)\");\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n offset += 8;\n var capacity7 = this.buffer.byteLength;\n if (offset > capacity7)\n this.resize((capacity7 *= 2) > offset ? capacity7 : offset);\n offset -= 8;\n var lo = value.low,\r\n hi = value.high;\r\n if (this.littleEndian) {\r\n this.view[offset+3] = (lo >>> 24) & 0xFF;\n this.view[offset+2] = (lo >>> 16) & 0xFF;\n this.view[offset+1] = (lo >>> 8) & 0xFF;\n this.view[offset ] = lo & 0xFF;\n offset += 4;\r\n this.view[offset+3] = (hi >>> 24) & 0xFF;\n this.view[offset+2] = (hi >>> 16) & 0xFF;\n this.view[offset+1] = (hi >>> 8) & 0xFF;\n this.view[offset ] = hi & 0xFF;\n } else {\r\n this.view[offset ] = (hi >>> 24) & 0xFF;\n this.view[offset+1] = (hi >>> 16) & 0xFF;\n this.view[offset+2] = (hi >>> 8) & 0xFF;\n this.view[offset+3] = hi & 0xFF;\n offset += 4;\r\n this.view[offset ] = (lo >>> 24) & 0xFF;\n this.view[offset+1] = (lo >>> 16) & 0xFF;\n this.view[offset+2] = (lo >>> 8) & 0xFF;\n this.view[offset+3] = lo & 0xFF;\n }\r\n if (relative) this.offset += 8;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 64bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint64}.\r\n * @function\r\n * @param {number|!Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUInt64 = ByteBufferPrototype.writeUint64;\r\n\r\n /**\r\n * Reads a 64bit unsigned integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUint64 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 8 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+8+\") <= \"+this.buffer.byteLength);\n }\r\n var lo = 0,\r\n hi = 0;\r\n if (this.littleEndian) {\r\n lo = this.view[offset+2] << 16;\n lo |= this.view[offset+1] << 8;\n lo |= this.view[offset ];\n lo += this.view[offset+3] << 24 >>> 0;\n offset += 4;\r\n hi = this.view[offset+2] << 16;\n hi |= this.view[offset+1] << 8;\n hi |= this.view[offset ];\n hi += this.view[offset+3] << 24 >>> 0;\n } else {\r\n hi = this.view[offset+1] << 16;\n hi |= this.view[offset+2] << 8;\n hi |= this.view[offset+3];\n hi += this.view[offset ] << 24 >>> 0;\n offset += 4;\r\n lo = this.view[offset+1] << 16;\n lo |= this.view[offset+2] << 8;\n lo |= this.view[offset+3];\n lo += this.view[offset ] << 24 >>> 0;\n }\r\n var value = new Long(lo, hi, true);\r\n if (relative) this.offset += 8;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 64bit unsigned integer. This is an alias of {@link ByteBuffer#readUint64}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUInt64 = ByteBufferPrototype.readUint64;\r\n\r\n } // Long\r\n\r\n\r\n // types/floats/float32\r\n\r\n /*\r\n ieee754 - https://github.com/feross/ieee754\r\n\r\n The MIT License (MIT)\r\n\r\n Copyright (c) Feross Aboukhadijeh\r\n\r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n\r\n The above copyright notice and this permission notice shall be included in\r\n all copies or substantial portions of the Software.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n THE SOFTWARE.\r\n */\r\n\r\n /**\r\n * Reads an IEEE754 float from a byte array.\r\n * @param {!Array} buffer\r\n * @param {number} offset\r\n * @param {boolean} isLE\r\n * @param {number} mLen\r\n * @param {number} nBytes\r\n * @returns {number}\r\n * @inner\r\n */\r\n function ieee754_read(buffer, offset, isLE, mLen, nBytes) {\r\n var e, m,\r\n eLen = nBytes * 8 - mLen - 1,\r\n eMax = (1 << eLen) - 1,\r\n eBias = eMax >> 1,\r\n nBits = -7,\r\n i = isLE ? (nBytes - 1) : 0,\r\n d = isLE ? -1 : 1,\r\n s = buffer[offset + i];\r\n\r\n i += d;\r\n\r\n e = s & ((1 << (-nBits)) - 1);\r\n s >>= (-nBits);\r\n nBits += eLen;\r\n for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}\r\n\r\n m = e & ((1 << (-nBits)) - 1);\r\n e >>= (-nBits);\r\n nBits += mLen;\r\n for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}\r\n\r\n if (e === 0) {\r\n e = 1 - eBias;\r\n } else if (e === eMax) {\r\n return m ? NaN : ((s ? -1 : 1) * Infinity);\r\n } else {\r\n m = m + Math.pow(2, mLen);\r\n e = e - eBias;\r\n }\r\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen);\r\n }\r\n\r\n /**\r\n * Writes an IEEE754 float to a byte array.\r\n * @param {!Array} buffer\r\n * @param {number} value\r\n * @param {number} offset\r\n * @param {boolean} isLE\r\n * @param {number} mLen\r\n * @param {number} nBytes\r\n * @inner\r\n */\r\n function ieee754_write(buffer, value, offset, isLE, mLen, nBytes) {\r\n var e, m, c,\r\n eLen = nBytes * 8 - mLen - 1,\r\n eMax = (1 << eLen) - 1,\r\n eBias = eMax >> 1,\r\n rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),\r\n i = isLE ? 0 : (nBytes - 1),\r\n d = isLE ? 1 : -1,\r\n s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;\r\n\r\n value = Math.abs(value);\r\n\r\n if (isNaN(value) || value === Infinity) {\r\n m = isNaN(value) ? 1 : 0;\r\n e = eMax;\r\n } else {\r\n e = Math.floor(Math.log(value) / Math.LN2);\r\n if (value * (c = Math.pow(2, -e)) < 1) {\r\n e--;\r\n c *= 2;\r\n }\r\n if (e + eBias >= 1) {\r\n value += rt / c;\r\n } else {\r\n value += rt * Math.pow(2, 1 - eBias);\r\n }\r\n if (value * c >= 2) {\r\n e++;\r\n c /= 2;\r\n }\r\n\r\n if (e + eBias >= eMax) {\r\n m = 0;\r\n e = eMax;\r\n } else if (e + eBias >= 1) {\r\n m = (value * c - 1) * Math.pow(2, mLen);\r\n e = e + eBias;\r\n } else {\r\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);\r\n e = 0;\r\n }\r\n }\r\n\r\n for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}\r\n\r\n e = (e << mLen) | m;\r\n eLen += mLen;\r\n for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}\r\n\r\n buffer[offset + i - d] |= s * 128;\r\n }\r\n\r\n /**\r\n * Writes a 32bit float.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeFloat32 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number')\r\n throw TypeError(\"Illegal value: \"+value+\" (not a number)\");\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 4;\n var capacity8 = this.buffer.byteLength;\n if (offset > capacity8)\n this.resize((capacity8 *= 2) > offset ? capacity8 : offset);\n offset -= 4;\n ieee754_write(this.view, value, offset, this.littleEndian, 23, 4);\r\n if (relative) this.offset += 4;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 32bit float. This is an alias of {@link ByteBuffer#writeFloat32}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeFloat = ByteBufferPrototype.writeFloat32;\r\n\r\n /**\r\n * Reads a 32bit float.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readFloat32 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 4 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+4+\") <= \"+this.buffer.byteLength);\n }\r\n var value = ieee754_read(this.view, offset, this.littleEndian, 23, 4);\r\n if (relative) this.offset += 4;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 32bit float. This is an alias of {@link ByteBuffer#readFloat32}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.\r\n * @returns {number}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readFloat = ByteBufferPrototype.readFloat32;\r\n\r\n // types/floats/float64\r\n\r\n /**\r\n * Writes a 64bit float.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeFloat64 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number')\r\n throw TypeError(\"Illegal value: \"+value+\" (not a number)\");\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n offset += 8;\n var capacity9 = this.buffer.byteLength;\n if (offset > capacity9)\n this.resize((capacity9 *= 2) > offset ? capacity9 : offset);\n offset -= 8;\n ieee754_write(this.view, value, offset, this.littleEndian, 52, 8);\r\n if (relative) this.offset += 8;\n return this;\r\n };\r\n\r\n /**\r\n * Writes a 64bit float. This is an alias of {@link ByteBuffer#writeFloat64}.\r\n * @function\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64;\r\n\r\n /**\r\n * Reads a 64bit float.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {number}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readFloat64 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 8 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+8+\") <= \"+this.buffer.byteLength);\n }\r\n var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8);\r\n if (relative) this.offset += 8;\n return value;\r\n };\r\n\r\n /**\r\n * Reads a 64bit float. This is an alias of {@link ByteBuffer#readFloat64}.\r\n * @function\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.\r\n * @returns {number}\r\n * @expose\r\n */\r\n ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64;\r\n\r\n\r\n // types/varints/varint32\r\n\r\n /**\r\n * Maximum number of bytes required to store a 32bit base 128 variable-length integer.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.MAX_VARINT32_BYTES = 5;\r\n\r\n /**\r\n * Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer.\r\n * @param {number} value Value to encode\r\n * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES}\r\n * @expose\r\n */\r\n ByteBuffer.calculateVarint32 = function(value) {\r\n // ref: src/google/protobuf/io/coded_stream.cc\r\n value = value >>> 0;\r\n if (value < 1 << 7 ) return 1;\r\n else if (value < 1 << 14) return 2;\r\n else if (value < 1 << 21) return 3;\r\n else if (value < 1 << 28) return 4;\r\n else return 5;\r\n };\r\n\r\n /**\r\n * Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding.\r\n * @param {number} n Signed 32bit integer\r\n * @returns {number} Unsigned zigzag encoded 32bit integer\r\n * @expose\r\n */\r\n ByteBuffer.zigZagEncode32 = function(n) {\r\n return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; // ref: src/google/protobuf/wire_format_lite.h\r\n };\r\n\r\n /**\r\n * Decodes a zigzag encoded signed 32bit integer.\r\n * @param {number} n Unsigned zigzag encoded 32bit integer\r\n * @returns {number} Signed 32bit integer\r\n * @expose\r\n */\r\n ByteBuffer.zigZagDecode32 = function(n) {\r\n return ((n >>> 1) ^ -(n & 1)) | 0; // // ref: src/google/protobuf/wire_format_lite.h\r\n };\r\n\r\n /**\r\n * Writes a 32bit base 128 variable-length integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeVarint32 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value |= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n var size = ByteBuffer.calculateVarint32(value),\r\n b;\r\n offset += size;\n var capacity10 = this.buffer.byteLength;\n if (offset > capacity10)\n this.resize((capacity10 *= 2) > offset ? capacity10 : offset);\n offset -= size;\n value >>>= 0;\r\n while (value >= 0x80) {\r\n b = (value & 0x7f) | 0x80;\r\n this.view[offset++] = b;\r\n value >>>= 7;\r\n }\r\n this.view[offset++] = value;\r\n if (relative) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n return size;\r\n };\r\n\r\n /**\r\n * Writes a zig-zag encoded (signed) 32bit base 128 variable-length integer.\r\n * @param {number} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeVarint32ZigZag = function(value, offset) {\r\n return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset);\r\n };\r\n\r\n /**\r\n * Reads a 32bit base 128 variable-length integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read\r\n * and the actual number of bytes read.\r\n * @throws {Error} If it's not a valid varint. Has a property `truncated = true` if there is not enough data available\r\n * to fully decode the varint.\r\n * @expose\r\n */\r\n ByteBufferPrototype.readVarint32 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n var c = 0,\r\n value = 0 >>> 0,\r\n b;\r\n do {\r\n if (!this.noAssert && offset > this.limit) {\r\n var err = Error(\"Truncated\");\r\n err['truncated'] = true;\r\n throw err;\r\n }\r\n b = this.view[offset++];\r\n if (c < 5)\r\n value |= (b & 0x7f) << (7*c);\r\n ++c;\r\n } while ((b & 0x80) !== 0);\r\n value |= 0;\r\n if (relative) {\r\n this.offset = offset;\r\n return value;\r\n }\r\n return {\r\n \"value\": value,\r\n \"length\": c\r\n };\r\n };\r\n\r\n /**\r\n * Reads a zig-zag encoded (signed) 32bit base 128 variable-length integer.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read\r\n * and the actual number of bytes read.\r\n * @throws {Error} If it's not a valid varint\r\n * @expose\r\n */\r\n ByteBufferPrototype.readVarint32ZigZag = function(offset) {\r\n var val = this.readVarint32(offset);\r\n if (typeof val === 'object')\r\n val[\"value\"] = ByteBuffer.zigZagDecode32(val[\"value\"]);\r\n else\r\n val = ByteBuffer.zigZagDecode32(val);\r\n return val;\r\n };\r\n\r\n // types/varints/varint64\r\n\r\n if (Long) {\r\n\r\n /**\r\n * Maximum number of bytes required to store a 64bit base 128 variable-length integer.\r\n * @type {number}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.MAX_VARINT64_BYTES = 10;\r\n\r\n /**\r\n * Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer.\r\n * @param {number|!Long} value Value to encode\r\n * @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES}\r\n * @expose\r\n */\r\n ByteBuffer.calculateVarint64 = function(value) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n // ref: src/google/protobuf/io/coded_stream.cc\r\n var part0 = value.toInt() >>> 0,\r\n part1 = value.shiftRightUnsigned(28).toInt() >>> 0,\r\n part2 = value.shiftRightUnsigned(56).toInt() >>> 0;\r\n if (part2 == 0) {\r\n if (part1 == 0) {\r\n if (part0 < 1 << 14)\r\n return part0 < 1 << 7 ? 1 : 2;\r\n else\r\n return part0 < 1 << 21 ? 3 : 4;\r\n } else {\r\n if (part1 < 1 << 14)\r\n return part1 < 1 << 7 ? 5 : 6;\r\n else\r\n return part1 < 1 << 21 ? 7 : 8;\r\n }\r\n } else\r\n return part2 < 1 << 7 ? 9 : 10;\r\n };\r\n\r\n /**\r\n * Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding.\r\n * @param {number|!Long} value Signed long\r\n * @returns {!Long} Unsigned zigzag encoded long\r\n * @expose\r\n */\r\n ByteBuffer.zigZagEncode64 = function(value) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value, false);\n else if (typeof value === 'string')\n value = Long.fromString(value, false);\n else if (value.unsigned !== false) value = value.toSigned();\n // ref: src/google/protobuf/wire_format_lite.h\r\n return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned();\r\n };\r\n\r\n /**\r\n * Decodes a zigzag encoded signed 64bit integer.\r\n * @param {!Long|number} value Unsigned zigzag encoded long or JavaScript number\r\n * @returns {!Long} Signed long\r\n * @expose\r\n */\r\n ByteBuffer.zigZagDecode64 = function(value) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value, false);\n else if (typeof value === 'string')\n value = Long.fromString(value, false);\n else if (value.unsigned !== false) value = value.toSigned();\n // ref: src/google/protobuf/wire_format_lite.h\r\n return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned();\r\n };\r\n\r\n /**\r\n * Writes a 64bit base 128 variable-length integer.\r\n * @param {number|Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeVarint64 = function(value, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof value === 'number')\n value = Long.fromNumber(value);\n else if (typeof value === 'string')\n value = Long.fromString(value);\n else if (!(value && value instanceof Long))\n throw TypeError(\"Illegal value: \"+value+\" (not an integer or Long)\");\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n if (typeof value === 'number')\n value = Long.fromNumber(value, false);\n else if (typeof value === 'string')\n value = Long.fromString(value, false);\n else if (value.unsigned !== false) value = value.toSigned();\n var size = ByteBuffer.calculateVarint64(value),\r\n part0 = value.toInt() >>> 0,\r\n part1 = value.shiftRightUnsigned(28).toInt() >>> 0,\r\n part2 = value.shiftRightUnsigned(56).toInt() >>> 0;\r\n offset += size;\n var capacity11 = this.buffer.byteLength;\n if (offset > capacity11)\n this.resize((capacity11 *= 2) > offset ? capacity11 : offset);\n offset -= size;\n switch (size) {\r\n case 10: this.view[offset+9] = (part2 >>> 7) & 0x01;\r\n case 9 : this.view[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F;\r\n case 8 : this.view[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F;\r\n case 7 : this.view[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F;\r\n case 6 : this.view[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F;\r\n case 5 : this.view[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F;\r\n case 4 : this.view[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F;\r\n case 3 : this.view[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F;\r\n case 2 : this.view[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F;\r\n case 1 : this.view[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F;\r\n }\r\n if (relative) {\r\n this.offset += size;\r\n return this;\r\n } else {\r\n return size;\r\n }\r\n };\r\n\r\n /**\r\n * Writes a zig-zag encoded 64bit base 128 variable-length integer.\r\n * @param {number|Long} value Value to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeVarint64ZigZag = function(value, offset) {\r\n return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset);\r\n };\r\n\r\n /**\r\n * Reads a 64bit base 128 variable-length integer. Requires Long.js.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and\r\n * the actual number of bytes read.\r\n * @throws {Error} If it's not a valid varint\r\n * @expose\r\n */\r\n ByteBufferPrototype.readVarint64 = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n // ref: src/google/protobuf/io/coded_stream.cc\r\n var start = offset,\r\n part0 = 0,\r\n part1 = 0,\r\n part2 = 0,\r\n b = 0;\r\n b = this.view[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) {\r\n b = this.view[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n b = this.view[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {\r\n throw Error(\"Buffer overrun\"); }}}}}}}}}}\r\n var value = Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, false);\r\n if (relative) {\r\n this.offset = offset;\r\n return value;\r\n } else {\r\n return {\r\n 'value': value,\r\n 'length': offset-start\r\n };\r\n }\r\n };\r\n\r\n /**\r\n * Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and\r\n * the actual number of bytes read.\r\n * @throws {Error} If it's not a valid varint\r\n * @expose\r\n */\r\n ByteBufferPrototype.readVarint64ZigZag = function(offset) {\r\n var val = this.readVarint64(offset);\r\n if (val && val['value'] instanceof Long)\r\n val[\"value\"] = ByteBuffer.zigZagDecode64(val[\"value\"]);\r\n else\r\n val = ByteBuffer.zigZagDecode64(val);\r\n return val;\r\n };\r\n\r\n } // Long\r\n\r\n\r\n // types/strings/cstring\r\n\r\n /**\r\n * Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL\r\n * characters itself.\r\n * @param {string} str String to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * contained in `str` + 1 if omitted.\r\n * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeCString = function(str, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n var i,\r\n k = str.length;\r\n if (!this.noAssert) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"Illegal str: Not a string\");\r\n for (i=0; i>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n // UTF8 strings do not contain zero bytes in between except for the zero character, so:\r\n k = utfx.calculateUTF16asUTF8(stringSource(str))[1];\r\n offset += k+1;\n var capacity12 = this.buffer.byteLength;\n if (offset > capacity12)\n this.resize((capacity12 *= 2) > offset ? capacity12 : offset);\n offset -= k+1;\n utfx.encodeUTF16toUTF8(stringSource(str), function(b) {\r\n this.view[offset++] = b;\r\n }.bind(this));\r\n this.view[offset++] = 0;\r\n if (relative) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n return k;\r\n };\r\n\r\n /**\r\n * Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters\r\n * itself.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string\r\n * read and the actual number of bytes read.\r\n * @expose\r\n */\r\n ByteBufferPrototype.readCString = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n var start = offset,\r\n temp;\r\n // UTF8 strings do not contain zero bytes in between except for the zero character itself, so:\r\n var sd, b = -1;\r\n utfx.decodeUTF8toUTF16(function() {\r\n if (b === 0) return null;\r\n if (offset >= this.limit)\r\n throw RangeError(\"Illegal range: Truncated data, \"+offset+\" < \"+this.limit);\r\n b = this.view[offset++];\r\n return b === 0 ? null : b;\r\n }.bind(this), sd = stringDestination(), true);\r\n if (relative) {\r\n this.offset = offset;\r\n return sd();\r\n } else {\r\n return {\r\n \"string\": sd(),\r\n \"length\": offset - start\r\n };\r\n }\r\n };\r\n\r\n // types/strings/istring\r\n\r\n /**\r\n * Writes a length as uint32 prefixed UTF8 encoded string.\r\n * @param {string} str String to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written\r\n * @expose\r\n * @see ByteBuffer#writeVarint32\r\n */\r\n ByteBufferPrototype.writeIString = function(str, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"Illegal str: Not a string\");\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n var start = offset,\r\n k;\r\n k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];\r\n offset += 4+k;\n var capacity13 = this.buffer.byteLength;\n if (offset > capacity13)\n this.resize((capacity13 *= 2) > offset ? capacity13 : offset);\n offset -= 4+k;\n if (this.littleEndian) {\n this.view[offset+3] = (k >>> 24) & 0xFF;\n this.view[offset+2] = (k >>> 16) & 0xFF;\n this.view[offset+1] = (k >>> 8) & 0xFF;\n this.view[offset ] = k & 0xFF;\n } else {\n this.view[offset ] = (k >>> 24) & 0xFF;\n this.view[offset+1] = (k >>> 16) & 0xFF;\n this.view[offset+2] = (k >>> 8) & 0xFF;\n this.view[offset+3] = k & 0xFF;\n }\n offset += 4;\r\n utfx.encodeUTF16toUTF8(stringSource(str), function(b) {\r\n this.view[offset++] = b;\r\n }.bind(this));\r\n if (offset !== start + 4 + k)\r\n throw RangeError(\"Illegal range: Truncated data, \"+offset+\" == \"+(offset+4+k));\r\n if (relative) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n return offset - start;\r\n };\r\n\r\n /**\r\n * Reads a length as uint32 prefixed UTF8 encoded string.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string\r\n * read and the actual number of bytes read.\r\n * @expose\r\n * @see ByteBuffer#readVarint32\r\n */\r\n ByteBufferPrototype.readIString = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 4 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+4+\") <= \"+this.buffer.byteLength);\n }\r\n var start = offset;\r\n var len = this.readUint32(offset);\r\n var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);\r\n offset += str['length'];\r\n if (relative) {\r\n this.offset = offset;\r\n return str['string'];\r\n } else {\r\n return {\r\n 'string': str['string'],\r\n 'length': offset - start\r\n };\r\n }\r\n };\r\n\r\n // types/strings/utf8string\r\n\r\n /**\r\n * Metrics representing number of UTF8 characters. Evaluates to `c`.\r\n * @type {string}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.METRICS_CHARS = 'c';\r\n\r\n /**\r\n * Metrics representing number of bytes. Evaluates to `b`.\r\n * @type {string}\r\n * @const\r\n * @expose\r\n */\r\n ByteBuffer.METRICS_BYTES = 'b';\r\n\r\n /**\r\n * Writes an UTF8 encoded string.\r\n * @param {string} str String to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted.\r\n * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeUTF8String = function(str, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n var k;\r\n var start = offset;\r\n k = utfx.calculateUTF16asUTF8(stringSource(str))[1];\r\n offset += k;\n var capacity14 = this.buffer.byteLength;\n if (offset > capacity14)\n this.resize((capacity14 *= 2) > offset ? capacity14 : offset);\n offset -= k;\n utfx.encodeUTF16toUTF8(stringSource(str), function(b) {\r\n this.view[offset++] = b;\r\n }.bind(this));\r\n if (relative) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n return offset - start;\r\n };\r\n\r\n /**\r\n * Writes an UTF8 encoded string. This is an alias of {@link ByteBuffer#writeUTF8String}.\r\n * @function\r\n * @param {string} str String to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted.\r\n * @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written.\r\n * @expose\r\n */\r\n ByteBufferPrototype.writeString = ByteBufferPrototype.writeUTF8String;\r\n\r\n /**\r\n * Calculates the number of UTF8 characters of a string. JavaScript itself uses UTF-16, so that a string's\r\n * `length` property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF.\r\n * @param {string} str String to calculate\r\n * @returns {number} Number of UTF8 characters\r\n * @expose\r\n */\r\n ByteBuffer.calculateUTF8Chars = function(str) {\r\n return utfx.calculateUTF16asUTF8(stringSource(str))[0];\r\n };\r\n\r\n /**\r\n * Calculates the number of UTF8 bytes of a string.\r\n * @param {string} str String to calculate\r\n * @returns {number} Number of UTF8 bytes\r\n * @expose\r\n */\r\n ByteBuffer.calculateUTF8Bytes = function(str) {\r\n return utfx.calculateUTF16asUTF8(stringSource(str))[1];\r\n };\r\n\r\n /**\r\n * Calculates the number of UTF8 bytes of a string. This is an alias of {@link ByteBuffer.calculateUTF8Bytes}.\r\n * @function\r\n * @param {string} str String to calculate\r\n * @returns {number} Number of UTF8 bytes\r\n * @expose\r\n */\r\n ByteBuffer.calculateString = ByteBuffer.calculateUTF8Bytes;\r\n\r\n /**\r\n * Reads an UTF8 encoded string.\r\n * @param {number} length Number of characters or bytes to read.\r\n * @param {string=} metrics Metrics specifying what `length` is meant to count. Defaults to\r\n * {@link ByteBuffer.METRICS_CHARS}.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string\r\n * read and the actual number of bytes read.\r\n * @expose\r\n */\r\n ByteBufferPrototype.readUTF8String = function(length, metrics, offset) {\r\n if (typeof metrics === 'number') {\r\n offset = metrics;\r\n metrics = undefined;\r\n }\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS;\r\n if (!this.noAssert) {\r\n if (typeof length !== 'number' || length % 1 !== 0)\n throw TypeError(\"Illegal length: \"+length+\" (not an integer)\");\n length |= 0;\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n var i = 0,\r\n start = offset,\r\n sd;\r\n if (metrics === ByteBuffer.METRICS_CHARS) { // The same for node and the browser\r\n sd = stringDestination();\r\n utfx.decodeUTF8(function() {\r\n return i < length && offset < this.limit ? this.view[offset++] : null;\r\n }.bind(this), function(cp) {\r\n ++i; utfx.UTF8toUTF16(cp, sd);\r\n });\r\n if (i !== length)\r\n throw RangeError(\"Illegal range: Truncated data, \"+i+\" == \"+length);\r\n if (relative) {\r\n this.offset = offset;\r\n return sd();\r\n } else {\r\n return {\r\n \"string\": sd(),\r\n \"length\": offset - start\r\n };\r\n }\r\n } else if (metrics === ByteBuffer.METRICS_BYTES) {\r\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + length > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+length+\") <= \"+this.buffer.byteLength);\n }\r\n var k = offset + length;\r\n utfx.decodeUTF8toUTF16(function() {\r\n return offset < k ? this.view[offset++] : null;\r\n }.bind(this), sd = stringDestination(), this.noAssert);\r\n if (offset !== k)\r\n throw RangeError(\"Illegal range: Truncated data, \"+offset+\" == \"+k);\r\n if (relative) {\r\n this.offset = offset;\r\n return sd();\r\n } else {\r\n return {\r\n 'string': sd(),\r\n 'length': offset - start\r\n };\r\n }\r\n } else\r\n throw TypeError(\"Unsupported metrics: \"+metrics);\r\n };\r\n\r\n /**\r\n * Reads an UTF8 encoded string. This is an alias of {@link ByteBuffer#readUTF8String}.\r\n * @function\r\n * @param {number} length Number of characters or bytes to read\r\n * @param {number=} metrics Metrics specifying what `n` is meant to count. Defaults to\r\n * {@link ByteBuffer.METRICS_CHARS}.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string\r\n * read and the actual number of bytes read.\r\n * @expose\r\n */\r\n ByteBufferPrototype.readString = ByteBufferPrototype.readUTF8String;\r\n\r\n // types/strings/vstring\r\n\r\n /**\r\n * Writes a length as varint32 prefixed UTF8 encoded string.\r\n * @param {string} str String to write\r\n * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written\r\n * @expose\r\n * @see ByteBuffer#writeVarint32\r\n */\r\n ByteBufferPrototype.writeVString = function(str, offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"Illegal str: Not a string\");\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n var start = offset,\r\n k, l;\r\n k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];\r\n l = ByteBuffer.calculateVarint32(k);\r\n offset += l+k;\n var capacity15 = this.buffer.byteLength;\n if (offset > capacity15)\n this.resize((capacity15 *= 2) > offset ? capacity15 : offset);\n offset -= l+k;\n offset += this.writeVarint32(k, offset);\r\n utfx.encodeUTF16toUTF8(stringSource(str), function(b) {\r\n this.view[offset++] = b;\r\n }.bind(this));\r\n if (offset !== start+k+l)\r\n throw RangeError(\"Illegal range: Truncated data, \"+offset+\" == \"+(offset+k+l));\r\n if (relative) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n return offset - start;\r\n };\r\n\r\n /**\r\n * Reads a length as varint32 prefixed UTF8 encoded string.\r\n * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string\r\n * read and the actual number of bytes read.\r\n * @expose\r\n * @see ByteBuffer#readVarint32\r\n */\r\n ByteBufferPrototype.readVString = function(offset) {\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 1 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+1+\") <= \"+this.buffer.byteLength);\n }\r\n var start = offset;\r\n var len = this.readVarint32(offset);\r\n var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);\r\n offset += str['length'];\r\n if (relative) {\r\n this.offset = offset;\r\n return str['string'];\r\n } else {\r\n return {\r\n 'string': str['string'],\r\n 'length': offset - start\r\n };\r\n }\r\n };\r\n\r\n\r\n /**\r\n * Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended\r\n * data's length.\r\n * @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to append. If `source` is a ByteBuffer, its offsets\r\n * will be modified according to the performed read operation.\r\n * @param {(string|number)=} encoding Encoding if `data` is a string (\"base64\", \"hex\", \"binary\", defaults to \"utf8\")\r\n * @param {number=} offset Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n * @example A relative `<01 02>03.append(<04 05>)` will result in `<01 02 04 05>, 04 05|`\r\n * @example An absolute `<01 02>03.append(04 05>, 1)` will result in `<01 04>05, 04 05|`\r\n */\r\n ByteBufferPrototype.append = function(source, encoding, offset) {\r\n if (typeof encoding === 'number' || typeof encoding !== 'string') {\r\n offset = encoding;\r\n encoding = undefined;\r\n }\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n if (!(source instanceof ByteBuffer))\r\n source = ByteBuffer.wrap(source, encoding);\r\n var length = source.limit - source.offset;\r\n if (length <= 0) return this; // Nothing to append\r\n offset += length;\n var capacity16 = this.buffer.byteLength;\n if (offset > capacity16)\n this.resize((capacity16 *= 2) > offset ? capacity16 : offset);\n offset -= length;\n this.view.set(source.view.subarray(source.offset, source.limit), offset);\r\n source.offset += length;\r\n if (relative) this.offset += length;\n return this;\r\n };\r\n\r\n /**\r\n * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the\r\n specified offset up to the length of this ByteBuffer's data.\r\n * @param {!ByteBuffer} target Target ByteBuffer\r\n * @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * read if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n * @see ByteBuffer#append\r\n */\r\n ByteBufferPrototype.appendTo = function(target, offset) {\r\n target.append(this, offset);\r\n return this;\r\n };\r\n\r\n /**\r\n * Enables or disables assertions of argument types and offsets. Assertions are enabled by default but you can opt to\r\n * disable them if your code already makes sure that everything is valid.\r\n * @param {boolean} assert `true` to enable assertions, otherwise `false`\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.assert = function(assert) {\r\n this.noAssert = !assert;\r\n return this;\r\n };\r\n\r\n /**\r\n * Gets the capacity of this ByteBuffer's backing buffer.\r\n * @returns {number} Capacity of the backing buffer\r\n * @expose\r\n */\r\n ByteBufferPrototype.capacity = function() {\r\n return this.buffer.byteLength;\r\n };\r\n /**\r\n * Clears this ByteBuffer's offsets by setting {@link ByteBuffer#offset} to `0` and {@link ByteBuffer#limit} to the\r\n * backing buffer's capacity. Discards {@link ByteBuffer#markedOffset}.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.clear = function() {\r\n this.offset = 0;\r\n this.limit = this.buffer.byteLength;\r\n this.markedOffset = -1;\r\n return this;\r\n };\r\n\r\n /**\r\n * Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for {@link ByteBuffer#offset},\r\n * {@link ByteBuffer#markedOffset} and {@link ByteBuffer#limit}.\r\n * @param {boolean=} copy Whether to copy the backing buffer or to return another view on the same, defaults to `false`\r\n * @returns {!ByteBuffer} Cloned instance\r\n * @expose\r\n */\r\n ByteBufferPrototype.clone = function(copy) {\r\n var bb = new ByteBuffer(0, this.littleEndian, this.noAssert);\r\n if (copy) {\r\n bb.buffer = new ArrayBuffer(this.buffer.byteLength);\r\n bb.view = new Uint8Array(bb.buffer);\r\n } else {\r\n bb.buffer = this.buffer;\r\n bb.view = this.view;\r\n }\r\n bb.offset = this.offset;\r\n bb.markedOffset = this.markedOffset;\r\n bb.limit = this.limit;\r\n return bb;\r\n };\r\n\r\n /**\r\n * Compacts this ByteBuffer to be backed by a {@link ByteBuffer#buffer} of its contents' length. Contents are the bytes\r\n * between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will set `offset = 0` and `limit = capacity` and\r\n * adapt {@link ByteBuffer#markedOffset} to the same relative position if set.\r\n * @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset}\r\n * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.compact = function(begin, end) {\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n if (begin === 0 && end === this.buffer.byteLength)\r\n return this; // Already compacted\r\n var len = end - begin;\r\n if (len === 0) {\r\n this.buffer = EMPTY_BUFFER;\r\n this.view = null;\r\n if (this.markedOffset >= 0) this.markedOffset -= begin;\r\n this.offset = 0;\r\n this.limit = 0;\r\n return this;\r\n }\r\n var buffer = new ArrayBuffer(len);\r\n var view = new Uint8Array(buffer);\r\n view.set(this.view.subarray(begin, end));\r\n this.buffer = buffer;\r\n this.view = view;\r\n if (this.markedOffset >= 0) this.markedOffset -= begin;\r\n this.offset = 0;\r\n this.limit = len;\r\n return this;\r\n };\r\n\r\n /**\r\n * Creates a copy of this ByteBuffer's contents. Contents are the bytes between {@link ByteBuffer#offset} and\r\n * {@link ByteBuffer#limit}.\r\n * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}.\r\n * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.\r\n * @returns {!ByteBuffer} Copy\r\n * @expose\r\n */\r\n ByteBufferPrototype.copy = function(begin, end) {\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n if (begin === end)\r\n return new ByteBuffer(0, this.littleEndian, this.noAssert);\r\n var capacity = end - begin,\r\n bb = new ByteBuffer(capacity, this.littleEndian, this.noAssert);\r\n bb.offset = 0;\r\n bb.limit = capacity;\r\n if (bb.markedOffset >= 0) bb.markedOffset -= begin;\r\n this.copyTo(bb, 0, begin, end);\r\n return bb;\r\n };\r\n\r\n /**\r\n * Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between {@link ByteBuffer#offset} and\r\n * {@link ByteBuffer#limit}.\r\n * @param {!ByteBuffer} target Target ByteBuffer\r\n * @param {number=} targetOffset Offset to copy to. Will use and increase the target's {@link ByteBuffer#offset}\r\n * by the number of bytes copied if omitted.\r\n * @param {number=} sourceOffset Offset to start copying from. Will use and increase {@link ByteBuffer#offset} by the\r\n * number of bytes copied if omitted.\r\n * @param {number=} sourceLimit Offset to end copying from, defaults to {@link ByteBuffer#limit}\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.copyTo = function(target, targetOffset, sourceOffset, sourceLimit) {\r\n var relative,\r\n targetRelative;\r\n if (!this.noAssert) {\r\n if (!ByteBuffer.isByteBuffer(target))\r\n throw TypeError(\"Illegal target: Not a ByteBuffer\");\r\n }\r\n targetOffset = (targetRelative = typeof targetOffset === 'undefined') ? target.offset : targetOffset | 0;\r\n sourceOffset = (relative = typeof sourceOffset === 'undefined') ? this.offset : sourceOffset | 0;\r\n sourceLimit = typeof sourceLimit === 'undefined' ? this.limit : sourceLimit | 0;\r\n\r\n if (targetOffset < 0 || targetOffset > target.buffer.byteLength)\r\n throw RangeError(\"Illegal target range: 0 <= \"+targetOffset+\" <= \"+target.buffer.byteLength);\r\n if (sourceOffset < 0 || sourceLimit > this.buffer.byteLength)\r\n throw RangeError(\"Illegal source range: 0 <= \"+sourceOffset+\" <= \"+this.buffer.byteLength);\r\n\r\n var len = sourceLimit - sourceOffset;\r\n if (len === 0)\r\n return target; // Nothing to copy\r\n\r\n target.ensureCapacity(targetOffset + len);\r\n\r\n target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset);\r\n\r\n if (relative) this.offset += len;\r\n if (targetRelative) target.offset += len;\r\n\r\n return this;\r\n };\r\n\r\n /**\r\n * Makes sure that this ByteBuffer is backed by a {@link ByteBuffer#buffer} of at least the specified capacity. If the\r\n * current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity,\r\n * the required capacity will be used instead.\r\n * @param {number} capacity Required capacity\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.ensureCapacity = function(capacity) {\r\n var current = this.buffer.byteLength;\r\n if (current < capacity)\r\n return this.resize((current *= 2) > capacity ? current : capacity);\r\n return this;\r\n };\r\n\r\n /**\r\n * Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between\r\n * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.\r\n * @param {number|string} value Byte value to fill with. If given as a string, the first character is used.\r\n * @param {number=} begin Begin offset. Will use and increase {@link ByteBuffer#offset} by the number of bytes\r\n * written if omitted. defaults to {@link ByteBuffer#offset}.\r\n * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n * @example `someByteBuffer.clear().fill(0)` fills the entire backing buffer with zeroes\r\n */\r\n ByteBufferPrototype.fill = function(value, begin, end) {\r\n var relative = typeof begin === 'undefined';\n if (relative) begin = this.offset;\n if (typeof value === 'string' && value.length > 0)\r\n value = value.charCodeAt(0);\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof value !== 'number' || value % 1 !== 0)\n throw TypeError(\"Illegal value: \"+value+\" (not an integer)\");\n value |= 0;\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n if (begin >= end)\r\n return this; // Nothing to fill\r\n while (begin < end) this.view[begin++] = value;\r\n if (relative) this.offset = begin;\r\n return this;\r\n };\r\n\r\n /**\r\n * Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets `limit = offset` and\r\n * `offset = 0`. Make sure always to flip a ByteBuffer when all relative read or write operations are complete.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.flip = function() {\r\n this.limit = this.offset;\r\n this.offset = 0;\r\n return this;\r\n };\r\n /**\r\n * Marks an offset on this ByteBuffer to be used later.\r\n * @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}.\r\n * @returns {!ByteBuffer} this\r\n * @throws {TypeError} If `offset` is not a valid number\r\n * @throws {RangeError} If `offset` is out of bounds\r\n * @see ByteBuffer#reset\r\n * @expose\r\n */\r\n ByteBufferPrototype.mark = function(offset) {\r\n offset = typeof offset === 'undefined' ? this.offset : offset;\r\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n this.markedOffset = offset;\r\n return this;\r\n };\r\n /**\r\n * Sets the byte order.\r\n * @param {boolean} littleEndian `true` for little endian byte order, `false` for big endian\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.order = function(littleEndian) {\r\n if (!this.noAssert) {\r\n if (typeof littleEndian !== 'boolean')\r\n throw TypeError(\"Illegal littleEndian: Not a boolean\");\r\n }\r\n this.littleEndian = !!littleEndian;\r\n return this;\r\n };\r\n\r\n /**\r\n * Switches (to) little endian byte order.\r\n * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.LE = function(littleEndian) {\r\n this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true;\r\n return this;\r\n };\r\n\r\n /**\r\n * Switches (to) big endian byte order.\r\n * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.BE = function(bigEndian) {\r\n this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false;\r\n return this;\r\n };\r\n /**\r\n * Prepends some data to this ByteBuffer. This will overwrite any contents before the specified offset up to the\r\n * prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer\r\n * will be resized and its contents moved accordingly.\r\n * @param {!ByteBuffer|string|!ArrayBuffer} source Data to prepend. If `source` is a ByteBuffer, its offset will be\r\n * modified according to the performed read operation.\r\n * @param {(string|number)=} encoding Encoding if `data` is a string (\"base64\", \"hex\", \"binary\", defaults to \"utf8\")\r\n * @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes\r\n * prepended if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n * @example A relative `00<01 02 03>.prepend(<04 05>)` results in `<04 05 01 02 03>, 04 05|`\r\n * @example An absolute `00<01 02 03>.prepend(<04 05>, 2)` results in `04<05 02 03>, 04 05|`\r\n */\r\n ByteBufferPrototype.prepend = function(source, encoding, offset) {\r\n if (typeof encoding === 'number' || typeof encoding !== 'string') {\r\n offset = encoding;\r\n encoding = undefined;\r\n }\r\n var relative = typeof offset === 'undefined';\n if (relative) offset = this.offset;\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: \"+offset+\" (not an integer)\");\n offset >>>= 0;\n if (offset < 0 || offset + 0 > this.buffer.byteLength)\n throw RangeError(\"Illegal offset: 0 <= \"+offset+\" (+\"+0+\") <= \"+this.buffer.byteLength);\n }\r\n if (!(source instanceof ByteBuffer))\r\n source = ByteBuffer.wrap(source, encoding);\r\n var len = source.limit - source.offset;\r\n if (len <= 0) return this; // Nothing to prepend\r\n var diff = len - offset;\r\n if (diff > 0) { // Not enough space before offset, so resize + move\r\n var buffer = new ArrayBuffer(this.buffer.byteLength + diff);\r\n var view = new Uint8Array(buffer);\r\n view.set(this.view.subarray(offset, this.buffer.byteLength), len);\r\n this.buffer = buffer;\r\n this.view = view;\r\n this.offset += diff;\r\n if (this.markedOffset >= 0) this.markedOffset += diff;\r\n this.limit += diff;\r\n offset += diff;\r\n } else {\r\n var arrayView = new Uint8Array(this.buffer);\r\n }\r\n this.view.set(source.view.subarray(source.offset, source.limit), offset - len);\r\n\r\n source.offset = source.limit;\r\n if (relative)\r\n this.offset -= len;\r\n return this;\r\n };\r\n\r\n /**\r\n * Prepends this ByteBuffer to another ByteBuffer. This will overwrite any contents before the specified offset up to the\r\n * prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer\r\n * will be resized and its contents moved accordingly.\r\n * @param {!ByteBuffer} target Target ByteBuffer\r\n * @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes\r\n * prepended if omitted.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n * @see ByteBuffer#prepend\r\n */\r\n ByteBufferPrototype.prependTo = function(target, offset) {\r\n target.prepend(this, offset);\r\n return this;\r\n };\r\n /**\r\n * Prints debug information about this ByteBuffer's contents.\r\n * @param {function(string)=} out Output function to call, defaults to console.log\r\n * @expose\r\n */\r\n ByteBufferPrototype.printDebug = function(out) {\r\n if (typeof out !== 'function') out = console.log.bind(console);\r\n out(\r\n this.toString()+\"\\n\"+\r\n \"-------------------------------------------------------------------\\n\"+\r\n this.toDebug(/* columns */ true)\r\n );\r\n };\r\n\r\n /**\r\n * Gets the number of remaining readable bytes. Contents are the bytes between {@link ByteBuffer#offset} and\r\n * {@link ByteBuffer#limit}, so this returns `limit - offset`.\r\n * @returns {number} Remaining readable bytes. May be negative if `offset > limit`.\r\n * @expose\r\n */\r\n ByteBufferPrototype.remaining = function() {\r\n return this.limit - this.offset;\r\n };\r\n /**\r\n * Resets this ByteBuffer's {@link ByteBuffer#offset}. If an offset has been marked through {@link ByteBuffer#mark}\r\n * before, `offset` will be set to {@link ByteBuffer#markedOffset}, which will then be discarded. If no offset has been\r\n * marked, sets `offset = 0`.\r\n * @returns {!ByteBuffer} this\r\n * @see ByteBuffer#mark\r\n * @expose\r\n */\r\n ByteBufferPrototype.reset = function() {\r\n if (this.markedOffset >= 0) {\r\n this.offset = this.markedOffset;\r\n this.markedOffset = -1;\r\n } else {\r\n this.offset = 0;\r\n }\r\n return this;\r\n };\r\n /**\r\n * Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that\r\n * large or larger.\r\n * @param {number} capacity Capacity required\r\n * @returns {!ByteBuffer} this\r\n * @throws {TypeError} If `capacity` is not a number\r\n * @throws {RangeError} If `capacity < 0`\r\n * @expose\r\n */\r\n ByteBufferPrototype.resize = function(capacity) {\r\n if (!this.noAssert) {\r\n if (typeof capacity !== 'number' || capacity % 1 !== 0)\n throw TypeError(\"Illegal capacity: \"+capacity+\" (not an integer)\");\n capacity |= 0;\n if (capacity < 0)\r\n throw RangeError(\"Illegal capacity: 0 <= \"+capacity);\r\n }\r\n if (this.buffer.byteLength < capacity) {\r\n var buffer = new ArrayBuffer(capacity);\r\n var view = new Uint8Array(buffer);\r\n view.set(this.view);\r\n this.buffer = buffer;\r\n this.view = view;\r\n }\r\n return this;\r\n };\r\n /**\r\n * Reverses this ByteBuffer's contents.\r\n * @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset}\r\n * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.reverse = function(begin, end) {\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n if (begin === end)\r\n return this; // Nothing to reverse\r\n Array.prototype.reverse.call(this.view.subarray(begin, end));\r\n return this;\r\n };\r\n /**\r\n * Skips the next `length` bytes. This will just advance\r\n * @param {number} length Number of bytes to skip. May also be negative to move the offset back.\r\n * @returns {!ByteBuffer} this\r\n * @expose\r\n */\r\n ByteBufferPrototype.skip = function(length) {\r\n if (!this.noAssert) {\r\n if (typeof length !== 'number' || length % 1 !== 0)\n throw TypeError(\"Illegal length: \"+length+\" (not an integer)\");\n length |= 0;\n }\r\n var offset = this.offset + length;\r\n if (!this.noAssert) {\r\n if (offset < 0 || offset > this.buffer.byteLength)\r\n throw RangeError(\"Illegal length: 0 <= \"+this.offset+\" + \"+length+\" <= \"+this.buffer.byteLength);\r\n }\r\n this.offset = offset;\r\n return this;\r\n };\r\n\r\n /**\r\n * Slices this ByteBuffer by creating a cloned instance with `offset = begin` and `limit = end`.\r\n * @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}.\r\n * @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.\r\n * @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same {@link ByteBuffer#buffer}\r\n * @expose\r\n */\r\n ByteBufferPrototype.slice = function(begin, end) {\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n var bb = this.clone();\r\n bb.offset = begin;\r\n bb.limit = end;\r\n return bb;\r\n };\r\n /**\r\n * Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between\r\n * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.\r\n * @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory if\r\n * possible. Defaults to `false`\r\n * @returns {!ArrayBuffer} Contents as an ArrayBuffer\r\n * @expose\r\n */\r\n ByteBufferPrototype.toBuffer = function(forceCopy) {\r\n var offset = this.offset,\r\n limit = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof offset !== 'number' || offset % 1 !== 0)\n throw TypeError(\"Illegal offset: Not an integer\");\n offset >>>= 0;\n if (typeof limit !== 'number' || limit % 1 !== 0)\n throw TypeError(\"Illegal limit: Not an integer\");\n limit >>>= 0;\n if (offset < 0 || offset > limit || limit > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+offset+\" <= \"+limit+\" <= \"+this.buffer.byteLength);\n }\r\n // NOTE: It's not possible to have another ArrayBuffer reference the same memory as the backing buffer. This is\r\n // possible with Uint8Array#subarray only, but we have to return an ArrayBuffer by contract. So:\r\n if (!forceCopy && offset === 0 && limit === this.buffer.byteLength)\r\n return this.buffer;\r\n if (offset === limit)\r\n return EMPTY_BUFFER;\r\n var buffer = new ArrayBuffer(limit - offset);\r\n new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0);\r\n return buffer;\r\n };\r\n\r\n /**\r\n * Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between\r\n * {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. This is an alias of {@link ByteBuffer#toBuffer}.\r\n * @function\r\n * @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory.\r\n * Defaults to `false`\r\n * @returns {!ArrayBuffer} Contents as an ArrayBuffer\r\n * @expose\r\n */\r\n ByteBufferPrototype.toArrayBuffer = ByteBufferPrototype.toBuffer;\r\n\r\n /**\r\n * Converts the ByteBuffer's contents to a string.\r\n * @param {string=} encoding Output encoding. Returns an informative string representation if omitted but also allows\r\n * direct conversion to \"utf8\", \"hex\", \"base64\" and \"binary\" encoding. \"debug\" returns a hex representation with\r\n * highlighted offsets.\r\n * @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}\r\n * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}\r\n * @returns {string} String representation\r\n * @throws {Error} If `encoding` is invalid\r\n * @expose\r\n */\r\n ByteBufferPrototype.toString = function(encoding, begin, end) {\r\n if (typeof encoding === 'undefined')\r\n return \"ByteBufferAB(offset=\"+this.offset+\",markedOffset=\"+this.markedOffset+\",limit=\"+this.limit+\",capacity=\"+this.capacity()+\")\";\r\n if (typeof encoding === 'number')\r\n encoding = \"utf8\",\r\n begin = encoding,\r\n end = begin;\r\n switch (encoding) {\r\n case \"utf8\":\r\n return this.toUTF8(begin, end);\r\n case \"base64\":\r\n return this.toBase64(begin, end);\r\n case \"hex\":\r\n return this.toHex(begin, end);\r\n case \"binary\":\r\n return this.toBinary(begin, end);\r\n case \"debug\":\r\n return this.toDebug();\r\n case \"columns\":\r\n return this.toColumns();\r\n default:\r\n throw Error(\"Unsupported encoding: \"+encoding);\r\n }\r\n };\r\n\r\n // lxiv-embeddable\r\n\r\n /**\r\n * lxiv-embeddable (c) 2014 Daniel Wirtz \r\n * Released under the Apache License, Version 2.0\r\n * see: https://github.com/dcodeIO/lxiv for details\r\n */\r\n var lxiv = function() {\r\n \"use strict\";\r\n\r\n /**\r\n * lxiv namespace.\r\n * @type {!Object.}\r\n * @exports lxiv\r\n */\r\n var lxiv = {};\r\n\r\n /**\r\n * Character codes for output.\r\n * @type {!Array.}\r\n * @inner\r\n */\r\n var aout = [\r\n 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,\r\n 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,\r\n 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,\r\n 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47\r\n ];\r\n\r\n /**\r\n * Character codes for input.\r\n * @type {!Array.}\r\n * @inner\r\n */\r\n var ain = [];\r\n for (var i=0, k=aout.length; i>2)&0x3f]);\r\n t = (b&0x3)<<4;\r\n if ((b = src()) !== null) {\r\n t |= (b>>4)&0xf;\r\n dst(aout[(t|((b>>4)&0xf))&0x3f]);\r\n t = (b&0xf)<<2;\r\n if ((b = src()) !== null)\r\n dst(aout[(t|((b>>6)&0x3))&0x3f]),\r\n dst(aout[b&0x3f]);\r\n else\r\n dst(aout[t&0x3f]),\r\n dst(61);\r\n } else\r\n dst(aout[t&0x3f]),\r\n dst(61),\r\n dst(61);\r\n }\r\n };\r\n\r\n /**\r\n * Decodes base64 char codes to bytes.\r\n * @param {!function():number|null} src Characters source as a function returning the next char code respectively\r\n * `null` if there are no more characters left.\r\n * @param {!function(number)} dst Bytes destination as a function successively called with the next byte.\r\n * @throws {Error} If a character code is invalid\r\n */\r\n lxiv.decode = function(src, dst) {\r\n var c, t1, t2;\r\n function fail(c) {\r\n throw Error(\"Illegal character code: \"+c);\r\n }\r\n while ((c = src()) !== null) {\r\n t1 = ain[c];\r\n if (typeof t1 === 'undefined') fail(c);\r\n if ((c = src()) !== null) {\r\n t2 = ain[c];\r\n if (typeof t2 === 'undefined') fail(c);\r\n dst((t1<<2)>>>0|(t2&0x30)>>4);\r\n if ((c = src()) !== null) {\r\n t1 = ain[c];\r\n if (typeof t1 === 'undefined')\r\n if (c === 61) break; else fail(c);\r\n dst(((t2&0xf)<<4)>>>0|(t1&0x3c)>>2);\r\n if ((c = src()) !== null) {\r\n t2 = ain[c];\r\n if (typeof t2 === 'undefined')\r\n if (c === 61) break; else fail(c);\r\n dst(((t1&0x3)<<6)>>>0|t2);\r\n }\r\n }\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Tests if a string is valid base64.\r\n * @param {string} str String to test\r\n * @returns {boolean} `true` if valid, otherwise `false`\r\n */\r\n lxiv.test = function(str) {\r\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);\r\n };\r\n\r\n return lxiv;\r\n }();\r\n\r\n // encodings/base64\r\n\r\n /**\r\n * Encodes this ByteBuffer's contents to a base64 encoded string.\r\n * @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}.\r\n * @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}.\r\n * @returns {string} Base64 encoded string\r\n * @throws {RangeError} If `begin` or `end` is out of bounds\r\n * @expose\r\n */\r\n ByteBufferPrototype.toBase64 = function(begin, end) {\r\n if (typeof begin === 'undefined')\r\n begin = this.offset;\r\n if (typeof end === 'undefined')\r\n end = this.limit;\r\n begin = begin | 0; end = end | 0;\r\n if (begin < 0 || end > this.capacity || begin > end)\r\n throw RangeError(\"begin, end\");\r\n var sd; lxiv.encode(function() {\r\n return begin < end ? this.view[begin++] : null;\r\n }.bind(this), sd = stringDestination());\r\n return sd();\r\n };\r\n\r\n /**\r\n * Decodes a base64 encoded string to a ByteBuffer.\r\n * @param {string} str String to decode\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @returns {!ByteBuffer} ByteBuffer\r\n * @expose\r\n */\r\n ByteBuffer.fromBase64 = function(str, littleEndian) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"str\");\r\n var bb = new ByteBuffer(str.length/4*3, littleEndian),\r\n i = 0;\r\n lxiv.decode(stringSource(str), function(b) {\r\n bb.view[i++] = b;\r\n });\r\n bb.limit = i;\r\n return bb;\r\n };\r\n\r\n /**\r\n * Encodes a binary string to base64 like `window.btoa` does.\r\n * @param {string} str Binary string\r\n * @returns {string} Base64 encoded string\r\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa\r\n * @expose\r\n */\r\n ByteBuffer.btoa = function(str) {\r\n return ByteBuffer.fromBinary(str).toBase64();\r\n };\r\n\r\n /**\r\n * Decodes a base64 encoded string to binary like `window.atob` does.\r\n * @param {string} b64 Base64 encoded string\r\n * @returns {string} Binary string\r\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window.atob\r\n * @expose\r\n */\r\n ByteBuffer.atob = function(b64) {\r\n return ByteBuffer.fromBase64(b64).toBinary();\r\n };\r\n\r\n // encodings/binary\r\n\r\n /**\r\n * Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes.\r\n * @param {number=} begin Offset to begin at. Defaults to {@link ByteBuffer#offset}.\r\n * @param {number=} end Offset to end at. Defaults to {@link ByteBuffer#limit}.\r\n * @returns {string} Binary encoded string\r\n * @throws {RangeError} If `offset > limit`\r\n * @expose\r\n */\r\n ByteBufferPrototype.toBinary = function(begin, end) {\r\n if (typeof begin === 'undefined')\r\n begin = this.offset;\r\n if (typeof end === 'undefined')\r\n end = this.limit;\r\n begin |= 0; end |= 0;\r\n if (begin < 0 || end > this.capacity() || begin > end)\r\n throw RangeError(\"begin, end\");\r\n if (begin === end)\r\n return \"\";\r\n var chars = [],\r\n parts = [];\r\n while (begin < end) {\r\n chars.push(this.view[begin++]);\r\n if (chars.length >= 1024)\r\n parts.push(String.fromCharCode.apply(String, chars)),\r\n chars = [];\r\n }\r\n return parts.join('') + String.fromCharCode.apply(String, chars);\r\n };\r\n\r\n /**\r\n * Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.\r\n * @param {string} str String to decode\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @returns {!ByteBuffer} ByteBuffer\r\n * @expose\r\n */\r\n ByteBuffer.fromBinary = function(str, littleEndian) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"str\");\r\n var i = 0,\r\n k = str.length,\r\n charCode,\r\n bb = new ByteBuffer(k, littleEndian);\r\n while (i 0xff)\r\n throw RangeError(\"illegal char code: \"+charCode);\r\n bb.view[i++] = charCode;\r\n }\r\n bb.limit = k;\r\n return bb;\r\n };\r\n\r\n // encodings/debug\r\n\r\n /**\r\n * Encodes this ByteBuffer to a hex encoded string with marked offsets. Offset symbols are:\r\n * * `<` : offset,\r\n * * `'` : markedOffset,\r\n * * `>` : limit,\r\n * * `|` : offset and limit,\r\n * * `[` : offset and markedOffset,\r\n * * `]` : markedOffset and limit,\r\n * * `!` : offset, markedOffset and limit\r\n * @param {boolean=} columns If `true` returns two columns hex + ascii, defaults to `false`\r\n * @returns {string|!Array.} Debug string or array of lines if `asArray = true`\r\n * @expose\r\n * @example `>00'01 02<03` contains four bytes with `limit=0, markedOffset=1, offset=3`\r\n * @example `00[01 02 03>` contains four bytes with `offset=markedOffset=1, limit=4`\r\n * @example `00|01 02 03` contains four bytes with `offset=limit=1, markedOffset=-1`\r\n * @example `|` contains zero bytes with `offset=limit=0, markedOffset=-1`\r\n */\r\n ByteBufferPrototype.toDebug = function(columns) {\r\n var i = -1,\r\n k = this.buffer.byteLength,\r\n b,\r\n hex = \"\",\r\n asc = \"\",\r\n out = \"\";\r\n while (i 32 && b < 127 ? String.fromCharCode(b) : '.';\r\n }\r\n ++i;\r\n if (columns) {\r\n if (i > 0 && i % 16 === 0 && i !== k) {\r\n while (hex.length < 3*16+3) hex += \" \";\r\n out += hex+asc+\"\\n\";\r\n hex = asc = \"\";\r\n }\r\n }\r\n if (i === this.offset && i === this.limit)\r\n hex += i === this.markedOffset ? \"!\" : \"|\";\r\n else if (i === this.offset)\r\n hex += i === this.markedOffset ? \"[\" : \"<\";\r\n else if (i === this.limit)\r\n hex += i === this.markedOffset ? \"]\" : \">\";\r\n else\r\n hex += i === this.markedOffset ? \"'\" : (columns || (i !== 0 && i !== k) ? \" \" : \"\");\r\n }\r\n if (columns && hex !== \" \") {\r\n while (hex.length < 3*16+3)\r\n hex += \" \";\r\n out += hex + asc + \"\\n\";\r\n }\r\n return columns ? out : hex;\r\n };\r\n\r\n /**\r\n * Decodes a hex encoded string with marked offsets to a ByteBuffer.\r\n * @param {string} str Debug string to decode (not be generated with `columns = true`)\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer} ByteBuffer\r\n * @expose\r\n * @see ByteBuffer#toDebug\r\n */\r\n ByteBuffer.fromDebug = function(str, littleEndian, noAssert) {\r\n var k = str.length,\r\n bb = new ByteBuffer(((k+1)/3)|0, littleEndian, noAssert);\r\n var i = 0, j = 0, ch, b,\r\n rs = false, // Require symbol next\r\n ho = false, hm = false, hl = false, // Already has offset (ho), markedOffset (hm), limit (hl)?\r\n fail = false;\r\n while (i':\r\n if (!noAssert) {\r\n if (hl) {\r\n fail = true;\r\n break;\r\n }\r\n hl = true;\r\n }\r\n bb.limit = j;\r\n rs = false;\r\n break;\r\n case \"'\":\r\n if (!noAssert) {\r\n if (hm) {\r\n fail = true;\r\n break;\r\n }\r\n hm = true;\r\n }\r\n bb.markedOffset = j;\r\n rs = false;\r\n break;\r\n case ' ':\r\n rs = false;\r\n break;\r\n default:\r\n if (!noAssert) {\r\n if (rs) {\r\n fail = true;\r\n break;\r\n }\r\n }\r\n b = parseInt(ch+str.charAt(i++), 16);\r\n if (!noAssert) {\r\n if (isNaN(b) || b < 0 || b > 255)\r\n throw TypeError(\"Illegal str: Not a debug encoded string\");\r\n }\r\n bb.view[j++] = b;\r\n rs = true;\r\n }\r\n if (fail)\r\n throw TypeError(\"Illegal str: Invalid symbol at \"+i);\r\n }\r\n if (!noAssert) {\r\n if (!ho || !hl)\r\n throw TypeError(\"Illegal str: Missing offset or limit\");\r\n if (j>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n var out = new Array(end - begin),\r\n b;\r\n while (begin < end) {\r\n b = this.view[begin++];\r\n if (b < 0x10)\r\n out.push(\"0\", b.toString(16));\r\n else out.push(b.toString(16));\r\n }\r\n return out.join('');\r\n };\r\n\r\n /**\r\n * Decodes a hex encoded string to a ByteBuffer.\r\n * @param {string} str String to decode\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer} ByteBuffer\r\n * @expose\r\n */\r\n ByteBuffer.fromHex = function(str, littleEndian, noAssert) {\r\n if (!noAssert) {\r\n if (typeof str !== 'string')\r\n throw TypeError(\"Illegal str: Not a string\");\r\n if (str.length % 2 !== 0)\r\n throw TypeError(\"Illegal str: Length not a multiple of 2\");\r\n }\r\n var k = str.length,\r\n bb = new ByteBuffer((k / 2) | 0, littleEndian),\r\n b;\r\n for (var i=0, j=0; i 255)\r\n throw TypeError(\"Illegal str: Contains non-hex characters\");\r\n bb.view[j++] = b;\r\n }\r\n bb.limit = j;\r\n return bb;\r\n };\r\n\r\n // utfx-embeddable\r\n\r\n /**\r\n * utfx-embeddable (c) 2014 Daniel Wirtz \r\n * Released under the Apache License, Version 2.0\r\n * see: https://github.com/dcodeIO/utfx for details\r\n */\r\n var utfx = function() {\r\n \"use strict\";\r\n\r\n /**\r\n * utfx namespace.\r\n * @inner\r\n * @type {!Object.}\r\n */\r\n var utfx = {};\r\n\r\n /**\r\n * Maximum valid code point.\r\n * @type {number}\r\n * @const\r\n */\r\n utfx.MAX_CODEPOINT = 0x10FFFF;\r\n\r\n /**\r\n * Encodes UTF8 code points to UTF8 bytes.\r\n * @param {(!function():number|null) | number} src Code points source, either as a function returning the next code point\r\n * respectively `null` if there are no more code points left or a single numeric code point.\r\n * @param {!function(number)} dst Bytes destination as a function successively called with the next byte\r\n */\r\n utfx.encodeUTF8 = function(src, dst) {\r\n var cp = null;\r\n if (typeof src === 'number')\r\n cp = src,\r\n src = function() { return null; };\r\n while (cp !== null || (cp = src()) !== null) {\r\n if (cp < 0x80)\r\n dst(cp&0x7F);\r\n else if (cp < 0x800)\r\n dst(((cp>>6)&0x1F)|0xC0),\r\n dst((cp&0x3F)|0x80);\r\n else if (cp < 0x10000)\r\n dst(((cp>>12)&0x0F)|0xE0),\r\n dst(((cp>>6)&0x3F)|0x80),\r\n dst((cp&0x3F)|0x80);\r\n else\r\n dst(((cp>>18)&0x07)|0xF0),\r\n dst(((cp>>12)&0x3F)|0x80),\r\n dst(((cp>>6)&0x3F)|0x80),\r\n dst((cp&0x3F)|0x80);\r\n cp = null;\r\n }\r\n };\r\n\r\n /**\r\n * Decodes UTF8 bytes to UTF8 code points.\r\n * @param {!function():number|null} src Bytes source as a function returning the next byte respectively `null` if there\r\n * are no more bytes left.\r\n * @param {!function(number)} dst Code points destination as a function successively called with each decoded code point.\r\n * @throws {RangeError} If a starting byte is invalid in UTF8\r\n * @throws {Error} If the last sequence is truncated. Has an array property `bytes` holding the\r\n * remaining bytes.\r\n */\r\n utfx.decodeUTF8 = function(src, dst) {\r\n var a, b, c, d, fail = function(b) {\r\n b = b.slice(0, b.indexOf(null));\r\n var err = Error(b.toString());\r\n err.name = \"TruncatedError\";\r\n err['bytes'] = b;\r\n throw err;\r\n };\r\n while ((a = src()) !== null) {\r\n if ((a&0x80) === 0)\r\n dst(a);\r\n else if ((a&0xE0) === 0xC0)\r\n ((b = src()) === null) && fail([a, b]),\r\n dst(((a&0x1F)<<6) | (b&0x3F));\r\n else if ((a&0xF0) === 0xE0)\r\n ((b=src()) === null || (c=src()) === null) && fail([a, b, c]),\r\n dst(((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F));\r\n else if ((a&0xF8) === 0xF0)\r\n ((b=src()) === null || (c=src()) === null || (d=src()) === null) && fail([a, b, c ,d]),\r\n dst(((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F));\r\n else throw RangeError(\"Illegal starting byte: \"+a);\r\n }\r\n };\r\n\r\n /**\r\n * Converts UTF16 characters to UTF8 code points.\r\n * @param {!function():number|null} src Characters source as a function returning the next char code respectively\r\n * `null` if there are no more characters left.\r\n * @param {!function(number)} dst Code points destination as a function successively called with each converted code\r\n * point.\r\n */\r\n utfx.UTF16toUTF8 = function(src, dst) {\r\n var c1, c2 = null;\r\n while (true) {\r\n if ((c1 = c2 !== null ? c2 : src()) === null)\r\n break;\r\n if (c1 >= 0xD800 && c1 <= 0xDFFF) {\r\n if ((c2 = src()) !== null) {\r\n if (c2 >= 0xDC00 && c2 <= 0xDFFF) {\r\n dst((c1-0xD800)*0x400+c2-0xDC00+0x10000);\r\n c2 = null; continue;\r\n }\r\n }\r\n }\r\n dst(c1);\r\n }\r\n if (c2 !== null) dst(c2);\r\n };\r\n\r\n /**\r\n * Converts UTF8 code points to UTF16 characters.\r\n * @param {(!function():number|null) | number} src Code points source, either as a function returning the next code point\r\n * respectively `null` if there are no more code points left or a single numeric code point.\r\n * @param {!function(number)} dst Characters destination as a function successively called with each converted char code.\r\n * @throws {RangeError} If a code point is out of range\r\n */\r\n utfx.UTF8toUTF16 = function(src, dst) {\r\n var cp = null;\r\n if (typeof src === 'number')\r\n cp = src, src = function() { return null; };\r\n while (cp !== null || (cp = src()) !== null) {\r\n if (cp <= 0xFFFF)\r\n dst(cp);\r\n else\r\n cp -= 0x10000,\r\n dst((cp>>10)+0xD800),\r\n dst((cp%0x400)+0xDC00);\r\n cp = null;\r\n }\r\n };\r\n\r\n /**\r\n * Converts and encodes UTF16 characters to UTF8 bytes.\r\n * @param {!function():number|null} src Characters source as a function returning the next char code respectively `null`\r\n * if there are no more characters left.\r\n * @param {!function(number)} dst Bytes destination as a function successively called with the next byte.\r\n */\r\n utfx.encodeUTF16toUTF8 = function(src, dst) {\r\n utfx.UTF16toUTF8(src, function(cp) {\r\n utfx.encodeUTF8(cp, dst);\r\n });\r\n };\r\n\r\n /**\r\n * Decodes and converts UTF8 bytes to UTF16 characters.\r\n * @param {!function():number|null} src Bytes source as a function returning the next byte respectively `null` if there\r\n * are no more bytes left.\r\n * @param {!function(number)} dst Characters destination as a function successively called with each converted char code.\r\n * @throws {RangeError} If a starting byte is invalid in UTF8\r\n * @throws {Error} If the last sequence is truncated. Has an array property `bytes` holding the remaining bytes.\r\n */\r\n utfx.decodeUTF8toUTF16 = function(src, dst) {\r\n utfx.decodeUTF8(src, function(cp) {\r\n utfx.UTF8toUTF16(cp, dst);\r\n });\r\n };\r\n\r\n /**\r\n * Calculates the byte length of an UTF8 code point.\r\n * @param {number} cp UTF8 code point\r\n * @returns {number} Byte length\r\n */\r\n utfx.calculateCodePoint = function(cp) {\r\n return (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;\r\n };\r\n\r\n /**\r\n * Calculates the number of UTF8 bytes required to store UTF8 code points.\r\n * @param {(!function():number|null)} src Code points source as a function returning the next code point respectively\r\n * `null` if there are no more code points left.\r\n * @returns {number} The number of UTF8 bytes required\r\n */\r\n utfx.calculateUTF8 = function(src) {\r\n var cp, l=0;\r\n while ((cp = src()) !== null)\r\n l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;\r\n return l;\r\n };\r\n\r\n /**\r\n * Calculates the number of UTF8 code points respectively UTF8 bytes required to store UTF16 char codes.\r\n * @param {(!function():number|null)} src Characters source as a function returning the next char code respectively\r\n * `null` if there are no more characters left.\r\n * @returns {!Array.} The number of UTF8 code points at index 0 and the number of UTF8 bytes required at index 1.\r\n */\r\n utfx.calculateUTF16asUTF8 = function(src) {\r\n var n=0, l=0;\r\n utfx.UTF16toUTF8(src, function(cp) {\r\n ++n; l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;\r\n });\r\n return [n,l];\r\n };\r\n\r\n return utfx;\r\n }();\r\n\r\n // encodings/utf8\r\n\r\n /**\r\n * Encodes this ByteBuffer's contents between {@link ByteBuffer#offset} and {@link ByteBuffer#limit} to an UTF8 encoded\r\n * string.\r\n * @returns {string} Hex encoded string\r\n * @throws {RangeError} If `offset > limit`\r\n * @expose\r\n */\r\n ByteBufferPrototype.toUTF8 = function(begin, end) {\r\n if (typeof begin === 'undefined') begin = this.offset;\r\n if (typeof end === 'undefined') end = this.limit;\r\n if (!this.noAssert) {\r\n if (typeof begin !== 'number' || begin % 1 !== 0)\n throw TypeError(\"Illegal begin: Not an integer\");\n begin >>>= 0;\n if (typeof end !== 'number' || end % 1 !== 0)\n throw TypeError(\"Illegal end: Not an integer\");\n end >>>= 0;\n if (begin < 0 || begin > end || end > this.buffer.byteLength)\n throw RangeError(\"Illegal range: 0 <= \"+begin+\" <= \"+end+\" <= \"+this.buffer.byteLength);\n }\r\n var sd; try {\r\n utfx.decodeUTF8toUTF16(function() {\r\n return begin < end ? this.view[begin++] : null;\r\n }.bind(this), sd = stringDestination());\r\n } catch (e) {\r\n if (begin !== end)\r\n throw RangeError(\"Illegal range: Truncated data, \"+begin+\" != \"+end);\r\n }\r\n return sd();\r\n };\r\n\r\n /**\r\n * Decodes an UTF8 encoded string to a ByteBuffer.\r\n * @param {string} str String to decode\r\n * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to\r\n * {@link ByteBuffer.DEFAULT_ENDIAN}.\r\n * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to\r\n * {@link ByteBuffer.DEFAULT_NOASSERT}.\r\n * @returns {!ByteBuffer} ByteBuffer\r\n * @expose\r\n */\r\n ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) {\r\n if (!noAssert)\r\n if (typeof str !== 'string')\r\n throw TypeError(\"Illegal str: Not a string\");\r\n var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert),\r\n i = 0;\r\n utfx.encodeUTF16toUTF8(stringSource(str), function(b) {\r\n bb.view[i++] = b;\r\n });\r\n bb.limit = i;\r\n return bb;\r\n };\r\n\r\n return ByteBuffer;\r\n});\r\n","/*\r\n Copyright 2013 Daniel Wirtz \r\n Copyright 2009 The Closure Library Authors. All Rights Reserved.\r\n\r\n Licensed under the Apache License, Version 2.0 (the \"License\");\r\n you may not use this file except in compliance with the License.\r\n You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS-IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License.\r\n */\r\n\r\n/**\r\n * @license long.js (c) 2013 Daniel Wirtz \r\n * Released under the Apache License, Version 2.0\r\n * see: https://github.com/dcodeIO/long.js for details\r\n */\r\n(function(global, factory) {\r\n\r\n /* AMD */ if (typeof define === 'function' && define[\"amd\"])\r\n define([], factory);\r\n /* CommonJS */ else if (typeof require === 'function' && typeof module === \"object\" && module && module[\"exports\"])\r\n module[\"exports\"] = factory();\r\n /* Global */ else\r\n (global[\"dcodeIO\"] = global[\"dcodeIO\"] || {})[\"Long\"] = factory();\r\n\r\n})(this, function() {\r\n \"use strict\";\r\n\r\n /**\r\n * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.\r\n * See the from* functions below for more convenient ways of constructing Longs.\r\n * @exports Long\r\n * @class A Long class for representing a 64 bit two's-complement integer value.\r\n * @param {number} low The low (signed) 32 bits of the long\r\n * @param {number} high The high (signed) 32 bits of the long\r\n * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed\r\n * @constructor\r\n */\r\n function Long(low, high, unsigned) {\r\n\r\n /**\r\n * The low 32 bits as a signed value.\r\n * @type {number}\r\n * @expose\r\n */\r\n this.low = low|0;\r\n\r\n /**\r\n * The high 32 bits as a signed value.\r\n * @type {number}\r\n * @expose\r\n */\r\n this.high = high|0;\r\n\r\n /**\r\n * Whether unsigned or not.\r\n * @type {boolean}\r\n * @expose\r\n */\r\n this.unsigned = !!unsigned;\r\n }\r\n\r\n // The internal representation of a long is the two given signed, 32-bit values.\r\n // We use 32-bit pieces because these are the size of integers on which\r\n // Javascript performs bit-operations. For operations like addition and\r\n // multiplication, we split each number into 16 bit pieces, which can easily be\r\n // multiplied within Javascript's floating-point representation without overflow\r\n // or change in sign.\r\n //\r\n // In the algorithms below, we frequently reduce the negative case to the\r\n // positive case by negating the input(s) and then post-processing the result.\r\n // Note that we must ALWAYS check specially whether those values are MIN_VALUE\r\n // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as\r\n // a positive number, it overflows back into a negative). Not handling this\r\n // case would often result in infinite recursion.\r\n //\r\n // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*\r\n // methods on which they depend.\r\n\r\n /**\r\n * An indicator used to reliably determine if an object is a Long or not.\r\n * @type {boolean}\r\n * @const\r\n * @expose\r\n * @private\r\n */\r\n Long.__isLong__;\r\n\r\n Object.defineProperty(Long.prototype, \"__isLong__\", {\r\n value: true,\r\n enumerable: false,\r\n configurable: false\r\n });\r\n\r\n /**\r\n * Tests if the specified object is a Long.\r\n * @param {*} obj Object\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n Long.isLong = function isLong(obj) {\r\n return (obj && obj[\"__isLong__\"]) === true;\r\n };\r\n\r\n /**\r\n * A cache of the Long representations of small integer values.\r\n * @type {!Object}\r\n * @inner\r\n */\r\n var INT_CACHE = {};\r\n\r\n /**\r\n * A cache of the Long representations of small unsigned integer values.\r\n * @type {!Object}\r\n * @inner\r\n */\r\n var UINT_CACHE = {};\r\n\r\n /**\r\n * Returns a Long representing the given 32 bit integer value.\r\n * @param {number} value The 32 bit integer in question\r\n * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed\r\n * @returns {!Long} The corresponding Long value\r\n * @expose\r\n */\r\n Long.fromInt = function fromInt(value, unsigned) {\r\n var obj, cachedObj, cache;\r\n if (!unsigned) {\r\n value = value | 0;\r\n if (cache = (-128 <= value && value < 128)) {\r\n cachedObj = INT_CACHE[value];\r\n if (cachedObj)\r\n return cachedObj;\r\n }\r\n obj = new Long(value, value < 0 ? -1 : 0, false);\r\n if (cache)\r\n INT_CACHE[value] = obj;\r\n return obj;\r\n } else {\r\n value = value >>> 0;\r\n if (cache = (0 <= value && value < 256)) {\r\n cachedObj = UINT_CACHE[value];\r\n if (cachedObj)\r\n return cachedObj;\r\n }\r\n obj = new Long(value, (value | 0) < 0 ? -1 : 0, true);\r\n if (cache)\r\n UINT_CACHE[value] = obj;\r\n return obj;\r\n }\r\n };\r\n\r\n /**\r\n * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.\r\n * @param {number} value The number in question\r\n * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed\r\n * @returns {!Long} The corresponding Long value\r\n * @expose\r\n */\r\n Long.fromNumber = function fromNumber(value, unsigned) {\r\n unsigned = !!unsigned;\r\n if (isNaN(value) || !isFinite(value))\r\n return Long.ZERO;\r\n if (!unsigned && value <= -TWO_PWR_63_DBL)\r\n return Long.MIN_VALUE;\r\n if (!unsigned && value + 1 >= TWO_PWR_63_DBL)\r\n return Long.MAX_VALUE;\r\n if (unsigned && value >= TWO_PWR_64_DBL)\r\n return Long.MAX_UNSIGNED_VALUE;\r\n if (value < 0)\r\n return Long.fromNumber(-value, unsigned).neg();\r\n return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);\r\n };\r\n\r\n /**\r\n * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is\r\n * assumed to use 32 bits.\r\n * @param {number} lowBits The low 32 bits\r\n * @param {number} highBits The high 32 bits\r\n * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed\r\n * @returns {!Long} The corresponding Long value\r\n * @expose\r\n */\r\n Long.fromBits = function fromBits(lowBits, highBits, unsigned) {\r\n return new Long(lowBits, highBits, unsigned);\r\n };\r\n\r\n /**\r\n * Returns a Long representation of the given string, written using the specified radix.\r\n * @param {string} str The textual representation of the Long\r\n * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed\r\n * @param {number=} radix The radix in which the text is written (2-36), defaults to 10\r\n * @returns {!Long} The corresponding Long value\r\n * @expose\r\n */\r\n Long.fromString = function fromString(str, unsigned, radix) {\r\n if (str.length === 0)\r\n throw Error('number format error: empty string');\r\n if (str === \"NaN\" || str === \"Infinity\" || str === \"+Infinity\" || str === \"-Infinity\")\r\n return Long.ZERO;\r\n if (typeof unsigned === 'number') // For goog.math.long compatibility\r\n radix = unsigned,\r\n unsigned = false;\r\n radix = radix || 10;\r\n if (radix < 2 || 36 < radix)\r\n throw Error('radix out of range: ' + radix);\r\n\r\n var p;\r\n if ((p = str.indexOf('-')) > 0)\r\n throw Error('number format error: interior \"-\" character: ' + str);\r\n else if (p === 0)\r\n return Long.fromString(str.substring(1), unsigned, radix).neg();\r\n\r\n // Do several (8) digits each time through the loop, so as to\r\n // minimize the calls to the very expensive emulated div.\r\n var radixToPower = Long.fromNumber(Math.pow(radix, 8));\r\n\r\n var result = Long.ZERO;\r\n for (var i = 0; i < str.length; i += 8) {\r\n var size = Math.min(8, str.length - i);\r\n var value = parseInt(str.substring(i, i + size), radix);\r\n if (size < 8) {\r\n var power = Long.fromNumber(Math.pow(radix, size));\r\n result = result.mul(power).add(Long.fromNumber(value));\r\n } else {\r\n result = result.mul(radixToPower);\r\n result = result.add(Long.fromNumber(value));\r\n }\r\n }\r\n result.unsigned = unsigned;\r\n return result;\r\n };\r\n\r\n /**\r\n * Converts the specified value to a Long.\r\n * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n Long.fromValue = function fromValue(val) {\r\n if (val /* is compatible */ instanceof Long)\r\n return val;\r\n if (typeof val === 'number')\r\n return Long.fromNumber(val);\r\n if (typeof val === 'string')\r\n return Long.fromString(val);\r\n // Throws for non-objects, converts non-instanceof Long:\r\n return new Long(val.low, val.high, val.unsigned);\r\n };\r\n\r\n // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be\r\n // no runtime penalty for these.\r\n\r\n /**\r\n * @type {number}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_16_DBL = 1 << 16;\r\n\r\n /**\r\n * @type {number}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_24_DBL = 1 << 24;\r\n\r\n /**\r\n * @type {number}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;\r\n\r\n /**\r\n * @type {number}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;\r\n\r\n /**\r\n * @type {number}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;\r\n\r\n /**\r\n * @type {!Long}\r\n * @const\r\n * @inner\r\n */\r\n var TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);\r\n\r\n /**\r\n * Signed zero.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.ZERO = Long.fromInt(0);\r\n\r\n /**\r\n * Unsigned zero.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.UZERO = Long.fromInt(0, true);\r\n\r\n /**\r\n * Signed one.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.ONE = Long.fromInt(1);\r\n\r\n /**\r\n * Unsigned one.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.UONE = Long.fromInt(1, true);\r\n\r\n /**\r\n * Signed negative one.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.NEG_ONE = Long.fromInt(-1);\r\n\r\n /**\r\n * Maximum signed value.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.MAX_VALUE = new Long(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);\r\n\r\n /**\r\n * Maximum unsigned value.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.MAX_UNSIGNED_VALUE = new Long(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);\r\n\r\n /**\r\n * Minimum signed value.\r\n * @type {!Long}\r\n * @expose\r\n */\r\n Long.MIN_VALUE = new Long(0, 0x80000000|0, false);\r\n\r\n /**\r\n * @alias Long.prototype\r\n * @inner\r\n */\r\n var LongPrototype = Long.prototype;\r\n\r\n /**\r\n * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.\r\n * @returns {number}\r\n * @expose\r\n */\r\n LongPrototype.toInt = function toInt() {\r\n return this.unsigned ? this.low >>> 0 : this.low;\r\n };\r\n\r\n /**\r\n * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).\r\n * @returns {number}\r\n * @expose\r\n */\r\n LongPrototype.toNumber = function toNumber() {\r\n if (this.unsigned) {\r\n return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);\r\n }\r\n return this.high * TWO_PWR_32_DBL + (this.low >>> 0);\r\n };\r\n\r\n /**\r\n * Converts the Long to a string written in the specified radix.\r\n * @param {number=} radix Radix (2-36), defaults to 10\r\n * @returns {string}\r\n * @override\r\n * @throws {RangeError} If `radix` is out of range\r\n * @expose\r\n */\r\n LongPrototype.toString = function toString(radix) {\r\n radix = radix || 10;\r\n if (radix < 2 || 36 < radix)\r\n throw RangeError('radix out of range: ' + radix);\r\n if (this.isZero())\r\n return '0';\r\n var rem;\r\n if (this.isNegative()) { // Unsigned Longs are never negative\r\n if (this.eq(Long.MIN_VALUE)) {\r\n // We need to change the Long value before it can be negated, so we remove\r\n // the bottom-most digit in this base and then recurse to do the rest.\r\n var radixLong = Long.fromNumber(radix);\r\n var div = this.div(radixLong);\r\n rem = div.mul(radixLong).sub(this);\r\n return div.toString(radix) + rem.toInt().toString(radix);\r\n } else\r\n return '-' + this.neg().toString(radix);\r\n }\r\n\r\n // Do several (6) digits each time through the loop, so as to\r\n // minimize the calls to the very expensive emulated div.\r\n var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);\r\n rem = this;\r\n var result = '';\r\n while (true) {\r\n var remDiv = rem.div(radixToPower),\r\n intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,\r\n digits = intval.toString(radix);\r\n rem = remDiv;\r\n if (rem.isZero())\r\n return digits + result;\r\n else {\r\n while (digits.length < 6)\r\n digits = '0' + digits;\r\n result = '' + digits + result;\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Gets the high 32 bits as a signed integer.\r\n * @returns {number} Signed high bits\r\n * @expose\r\n */\r\n LongPrototype.getHighBits = function getHighBits() {\r\n return this.high;\r\n };\r\n\r\n /**\r\n * Gets the high 32 bits as an unsigned integer.\r\n * @returns {number} Unsigned high bits\r\n * @expose\r\n */\r\n LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {\r\n return this.high >>> 0;\r\n };\r\n\r\n /**\r\n * Gets the low 32 bits as a signed integer.\r\n * @returns {number} Signed low bits\r\n * @expose\r\n */\r\n LongPrototype.getLowBits = function getLowBits() {\r\n return this.low;\r\n };\r\n\r\n /**\r\n * Gets the low 32 bits as an unsigned integer.\r\n * @returns {number} Unsigned low bits\r\n * @expose\r\n */\r\n LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {\r\n return this.low >>> 0;\r\n };\r\n\r\n /**\r\n * Gets the number of bits needed to represent the absolute value of this Long.\r\n * @returns {number}\r\n * @expose\r\n */\r\n LongPrototype.getNumBitsAbs = function getNumBitsAbs() {\r\n if (this.isNegative()) // Unsigned Longs are never negative\r\n return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();\r\n var val = this.high != 0 ? this.high : this.low;\r\n for (var bit = 31; bit > 0; bit--)\r\n if ((val & (1 << bit)) != 0)\r\n break;\r\n return this.high != 0 ? bit + 33 : bit + 1;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value equals zero.\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.isZero = function isZero() {\r\n return this.high === 0 && this.low === 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is negative.\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.isNegative = function isNegative() {\r\n return !this.unsigned && this.high < 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is positive.\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.isPositive = function isPositive() {\r\n return this.unsigned || this.high >= 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is odd.\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.isOdd = function isOdd() {\r\n return (this.low & 1) === 1;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is even.\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.isEven = function isEven() {\r\n return (this.low & 1) === 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value equals the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.equals = function equals(other) {\r\n if (!Long.isLong(other))\r\n other = Long.fromValue(other);\r\n if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)\r\n return false;\r\n return this.high === other.high && this.low === other.low;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.eq = LongPrototype.equals;\r\n\r\n /**\r\n * Tests if this Long's value differs from the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.notEquals = function notEquals(other) {\r\n return !this.eq(/* validates */ other);\r\n };\r\n\r\n /**\r\n * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.neq = LongPrototype.notEquals;\r\n\r\n /**\r\n * Tests if this Long's value is less than the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.lessThan = function lessThan(other) {\r\n return this.compare(/* validates */ other) < 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.lt = LongPrototype.lessThan;\r\n\r\n /**\r\n * Tests if this Long's value is less than or equal the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {\r\n return this.compare(/* validates */ other) <= 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.lte = LongPrototype.lessThanOrEqual;\r\n\r\n /**\r\n * Tests if this Long's value is greater than the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.greaterThan = function greaterThan(other) {\r\n return this.compare(/* validates */ other) > 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.gt = LongPrototype.greaterThan;\r\n\r\n /**\r\n * Tests if this Long's value is greater than or equal the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {\r\n return this.compare(/* validates */ other) >= 0;\r\n };\r\n\r\n /**\r\n * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {boolean}\r\n * @expose\r\n */\r\n LongPrototype.gte = LongPrototype.greaterThanOrEqual;\r\n\r\n /**\r\n * Compares this Long's value with the specified's.\r\n * @param {!Long|number|string} other Other value\r\n * @returns {number} 0 if they are the same, 1 if the this is greater and -1\r\n * if the given one is greater\r\n * @expose\r\n */\r\n LongPrototype.compare = function compare(other) {\r\n if (!Long.isLong(other))\r\n other = Long.fromValue(other);\r\n if (this.eq(other))\r\n return 0;\r\n var thisNeg = this.isNegative(),\r\n otherNeg = other.isNegative();\r\n if (thisNeg && !otherNeg)\r\n return -1;\r\n if (!thisNeg && otherNeg)\r\n return 1;\r\n // At this point the sign bits are the same\r\n if (!this.unsigned)\r\n return this.sub(other).isNegative() ? -1 : 1;\r\n // Both are positive if at least one is unsigned\r\n return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;\r\n };\r\n\r\n /**\r\n * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.\r\n * @function\r\n * @param {!Long|number|string} other Other value\r\n * @returns {number} 0 if they are the same, 1 if the this is greater and -1\r\n * if the given one is greater\r\n * @expose\r\n */\r\n LongPrototype.comp = LongPrototype.compare;\r\n\r\n /**\r\n * Negates this Long's value.\r\n * @returns {!Long} Negated Long\r\n * @expose\r\n */\r\n LongPrototype.negate = function negate() {\r\n if (!this.unsigned && this.eq(Long.MIN_VALUE))\r\n return Long.MIN_VALUE;\r\n return this.not().add(Long.ONE);\r\n };\r\n\r\n /**\r\n * Negates this Long's value. This is an alias of {@link Long#negate}.\r\n * @function\r\n * @returns {!Long} Negated Long\r\n * @expose\r\n */\r\n LongPrototype.neg = LongPrototype.negate;\r\n\r\n /**\r\n * Returns the sum of this and the specified Long.\r\n * @param {!Long|number|string} addend Addend\r\n * @returns {!Long} Sum\r\n * @expose\r\n */\r\n LongPrototype.add = function add(addend) {\r\n if (!Long.isLong(addend))\r\n addend = Long.fromValue(addend);\r\n\r\n // Divide each number into 4 chunks of 16 bits, and then sum the chunks.\r\n\r\n var a48 = this.high >>> 16;\r\n var a32 = this.high & 0xFFFF;\r\n var a16 = this.low >>> 16;\r\n var a00 = this.low & 0xFFFF;\r\n\r\n var b48 = addend.high >>> 16;\r\n var b32 = addend.high & 0xFFFF;\r\n var b16 = addend.low >>> 16;\r\n var b00 = addend.low & 0xFFFF;\r\n\r\n var c48 = 0, c32 = 0, c16 = 0, c00 = 0;\r\n c00 += a00 + b00;\r\n c16 += c00 >>> 16;\r\n c00 &= 0xFFFF;\r\n c16 += a16 + b16;\r\n c32 += c16 >>> 16;\r\n c16 &= 0xFFFF;\r\n c32 += a32 + b32;\r\n c48 += c32 >>> 16;\r\n c32 &= 0xFFFF;\r\n c48 += a48 + b48;\r\n c48 &= 0xFFFF;\r\n return new Long((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns the difference of this and the specified Long.\r\n * @param {!Long|number|string} subtrahend Subtrahend\r\n * @returns {!Long} Difference\r\n * @expose\r\n */\r\n LongPrototype.subtract = function subtract(subtrahend) {\r\n if (!Long.isLong(subtrahend))\r\n subtrahend = Long.fromValue(subtrahend);\r\n return this.add(subtrahend.neg());\r\n };\r\n\r\n /**\r\n * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.\r\n * @function\r\n * @param {!Long|number|string} subtrahend Subtrahend\r\n * @returns {!Long} Difference\r\n * @expose\r\n */\r\n LongPrototype.sub = LongPrototype.subtract;\r\n\r\n /**\r\n * Returns the product of this and the specified Long.\r\n * @param {!Long|number|string} multiplier Multiplier\r\n * @returns {!Long} Product\r\n * @expose\r\n */\r\n LongPrototype.multiply = function multiply(multiplier) {\r\n if (this.isZero())\r\n return Long.ZERO;\r\n if (!Long.isLong(multiplier))\r\n multiplier = Long.fromValue(multiplier);\r\n if (multiplier.isZero())\r\n return Long.ZERO;\r\n if (this.eq(Long.MIN_VALUE))\r\n return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;\r\n if (multiplier.eq(Long.MIN_VALUE))\r\n return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;\r\n\r\n if (this.isNegative()) {\r\n if (multiplier.isNegative())\r\n return this.neg().mul(multiplier.neg());\r\n else\r\n return this.neg().mul(multiplier).neg();\r\n } else if (multiplier.isNegative())\r\n return this.mul(multiplier.neg()).neg();\r\n\r\n // If both longs are small, use float multiplication\r\n if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))\r\n return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);\r\n\r\n // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.\r\n // We can skip products that would overflow.\r\n\r\n var a48 = this.high >>> 16;\r\n var a32 = this.high & 0xFFFF;\r\n var a16 = this.low >>> 16;\r\n var a00 = this.low & 0xFFFF;\r\n\r\n var b48 = multiplier.high >>> 16;\r\n var b32 = multiplier.high & 0xFFFF;\r\n var b16 = multiplier.low >>> 16;\r\n var b00 = multiplier.low & 0xFFFF;\r\n\r\n var c48 = 0, c32 = 0, c16 = 0, c00 = 0;\r\n c00 += a00 * b00;\r\n c16 += c00 >>> 16;\r\n c00 &= 0xFFFF;\r\n c16 += a16 * b00;\r\n c32 += c16 >>> 16;\r\n c16 &= 0xFFFF;\r\n c16 += a00 * b16;\r\n c32 += c16 >>> 16;\r\n c16 &= 0xFFFF;\r\n c32 += a32 * b00;\r\n c48 += c32 >>> 16;\r\n c32 &= 0xFFFF;\r\n c32 += a16 * b16;\r\n c48 += c32 >>> 16;\r\n c32 &= 0xFFFF;\r\n c32 += a00 * b32;\r\n c48 += c32 >>> 16;\r\n c32 &= 0xFFFF;\r\n c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;\r\n c48 &= 0xFFFF;\r\n return new Long((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.\r\n * @function\r\n * @param {!Long|number|string} multiplier Multiplier\r\n * @returns {!Long} Product\r\n * @expose\r\n */\r\n LongPrototype.mul = LongPrototype.multiply;\r\n\r\n /**\r\n * Returns this Long divided by the specified.\r\n * @param {!Long|number|string} divisor Divisor\r\n * @returns {!Long} Quotient\r\n * @expose\r\n */\r\n LongPrototype.divide = function divide(divisor) {\r\n if (!Long.isLong(divisor))\r\n divisor = Long.fromValue(divisor);\r\n if (divisor.isZero())\r\n throw Error('division by zero');\r\n if (this.isZero())\r\n return this.unsigned ? Long.UZERO : Long.ZERO;\r\n var approx, rem, res;\r\n if (this.eq(Long.MIN_VALUE)) {\r\n if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE))\r\n return Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE\r\n else if (divisor.eq(Long.MIN_VALUE))\r\n return Long.ONE;\r\n else {\r\n // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.\r\n var halfThis = this.shr(1);\r\n approx = halfThis.div(divisor).shl(1);\r\n if (approx.eq(Long.ZERO)) {\r\n return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;\r\n } else {\r\n rem = this.sub(divisor.mul(approx));\r\n res = approx.add(rem.div(divisor));\r\n return res;\r\n }\r\n }\r\n } else if (divisor.eq(Long.MIN_VALUE))\r\n return this.unsigned ? Long.UZERO : Long.ZERO;\r\n if (this.isNegative()) {\r\n if (divisor.isNegative())\r\n return this.neg().div(divisor.neg());\r\n return this.neg().div(divisor).neg();\r\n } else if (divisor.isNegative())\r\n return this.div(divisor.neg()).neg();\r\n\r\n // Repeat the following until the remainder is less than other: find a\r\n // floating-point that approximates remainder / other *from below*, add this\r\n // into the result, and subtract it from the remainder. It is critical that\r\n // the approximate value is less than or equal to the real value so that the\r\n // remainder never becomes negative.\r\n res = Long.ZERO;\r\n rem = this;\r\n while (rem.gte(divisor)) {\r\n // Approximate the result of division. This may be a little greater or\r\n // smaller than the actual value.\r\n approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));\r\n\r\n // We will tweak the approximate result by changing it in the 48-th digit or\r\n // the smallest non-fractional digit, whichever is larger.\r\n var log2 = Math.ceil(Math.log(approx) / Math.LN2),\r\n delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48),\r\n\r\n // Decrease the approximation until it is smaller than the remainder. Note\r\n // that if it is too large, the product overflows and is negative.\r\n approxRes = Long.fromNumber(approx),\r\n approxRem = approxRes.mul(divisor);\r\n while (approxRem.isNegative() || approxRem.gt(rem)) {\r\n approx -= delta;\r\n approxRes = Long.fromNumber(approx, this.unsigned);\r\n approxRem = approxRes.mul(divisor);\r\n }\r\n\r\n // We know the answer can't be zero... and actually, zero would cause\r\n // infinite recursion since we would make no progress.\r\n if (approxRes.isZero())\r\n approxRes = Long.ONE;\r\n\r\n res = res.add(approxRes);\r\n rem = rem.sub(approxRem);\r\n }\r\n return res;\r\n };\r\n\r\n /**\r\n * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.\r\n * @function\r\n * @param {!Long|number|string} divisor Divisor\r\n * @returns {!Long} Quotient\r\n * @expose\r\n */\r\n LongPrototype.div = LongPrototype.divide;\r\n\r\n /**\r\n * Returns this Long modulo the specified.\r\n * @param {!Long|number|string} divisor Divisor\r\n * @returns {!Long} Remainder\r\n * @expose\r\n */\r\n LongPrototype.modulo = function modulo(divisor) {\r\n if (!Long.isLong(divisor))\r\n divisor = Long.fromValue(divisor);\r\n return this.sub(this.div(divisor).mul(divisor));\r\n };\r\n\r\n /**\r\n * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.\r\n * @function\r\n * @param {!Long|number|string} divisor Divisor\r\n * @returns {!Long} Remainder\r\n * @expose\r\n */\r\n LongPrototype.mod = LongPrototype.modulo;\r\n\r\n /**\r\n * Returns the bitwise NOT of this Long.\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n LongPrototype.not = function not() {\r\n return new Long(~this.low, ~this.high, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns the bitwise AND of this Long and the specified.\r\n * @param {!Long|number|string} other Other Long\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n LongPrototype.and = function and(other) {\r\n if (!Long.isLong(other))\r\n other = Long.fromValue(other);\r\n return new Long(this.low & other.low, this.high & other.high, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns the bitwise OR of this Long and the specified.\r\n * @param {!Long|number|string} other Other Long\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n LongPrototype.or = function or(other) {\r\n if (!Long.isLong(other))\r\n other = Long.fromValue(other);\r\n return new Long(this.low | other.low, this.high | other.high, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns the bitwise XOR of this Long and the given one.\r\n * @param {!Long|number|string} other Other Long\r\n * @returns {!Long}\r\n * @expose\r\n */\r\n LongPrototype.xor = function xor(other) {\r\n if (!Long.isLong(other))\r\n other = Long.fromValue(other);\r\n return new Long(this.low ^ other.low, this.high ^ other.high, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns this Long with bits shifted to the left by the given amount.\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shiftLeft = function shiftLeft(numBits) {\r\n if (Long.isLong(numBits))\r\n numBits = numBits.toInt();\r\n if ((numBits &= 63) === 0)\r\n return this;\r\n else if (numBits < 32)\r\n return new Long(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);\r\n else\r\n return new Long(0, this.low << (numBits - 32), this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.\r\n * @function\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shl = LongPrototype.shiftLeft;\r\n\r\n /**\r\n * Returns this Long with bits arithmetically shifted to the right by the given amount.\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shiftRight = function shiftRight(numBits) {\r\n if (Long.isLong(numBits))\r\n numBits = numBits.toInt();\r\n if ((numBits &= 63) === 0)\r\n return this;\r\n else if (numBits < 32)\r\n return new Long((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);\r\n else\r\n return new Long(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);\r\n };\r\n\r\n /**\r\n * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.\r\n * @function\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shr = LongPrototype.shiftRight;\r\n\r\n /**\r\n * Returns this Long with bits logically shifted to the right by the given amount.\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {\r\n if (Long.isLong(numBits))\r\n numBits = numBits.toInt();\r\n numBits &= 63;\r\n if (numBits === 0)\r\n return this;\r\n else {\r\n var high = this.high;\r\n if (numBits < 32) {\r\n var low = this.low;\r\n return new Long((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);\r\n } else if (numBits === 32)\r\n return new Long(high, 0, this.unsigned);\r\n else\r\n return new Long(high >>> (numBits - 32), 0, this.unsigned);\r\n }\r\n };\r\n\r\n /**\r\n * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.\r\n * @function\r\n * @param {number|!Long} numBits Number of bits\r\n * @returns {!Long} Shifted Long\r\n * @expose\r\n */\r\n LongPrototype.shru = LongPrototype.shiftRightUnsigned;\r\n\r\n /**\r\n * Converts this Long to signed.\r\n * @returns {!Long} Signed long\r\n * @expose\r\n */\r\n LongPrototype.toSigned = function toSigned() {\r\n if (!this.unsigned)\r\n return this;\r\n return new Long(this.low, this.high, false);\r\n };\r\n\r\n /**\r\n * Converts this Long to unsigned.\r\n * @returns {!Long} Unsigned long\r\n * @expose\r\n */\r\n LongPrototype.toUnsigned = function toUnsigned() {\r\n if (this.unsigned)\r\n return this;\r\n return new Long(this.low, this.high, true);\r\n };\r\n\r\n return Long;\r\n});\r\n"]} \ No newline at end of file diff --git a/js/examples/decoding_message_container.js b/js/examples/decoding_message_container.js new file mode 100644 index 000000000..ddb9e7777 --- /dev/null +++ b/js/examples/decoding_message_container.js @@ -0,0 +1,9 @@ +var machinetalkProtobuf = require('../index.js'); + +var encodedBuffer = new Buffer([0x08, 0xd2, 0x01]); + +// Decode the message. +var decodedMessageContainer = machinetalkProtobuf.message.Container.decode(encodedBuffer); + +// decodedMessageContainer.type === machinetalkProtobuf.message.ContainerType.MT_PING +console.log(decodedMessageContainer); diff --git a/js/examples/encoding_message_container.js b/js/examples/encoding_message_container.js new file mode 100644 index 000000000..23d072698 --- /dev/null +++ b/js/examples/encoding_message_container.js @@ -0,0 +1,15 @@ +var machinetalkProtobuf = require('../index.js'); + +// Define the message we want to encode. +var messageContainer = { + type: machinetalkProtobuf.message.ContainerType.MT_PING +}; + +// Encode the message. +var encodedMessageContainer = machinetalkProtobuf.message.Container.encode(messageContainer); + +// Strip off excess bytes from the resulting buffer. +var encodedBuffer = encodedMessageContainer.buffer.slice(encodedMessageContainer.offset, encodedMessageContainer.limit); + +// Print the buffer. +console.log(encodedBuffer); \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100644 index 000000000..efca1ca89 --- /dev/null +++ b/js/index.js @@ -0,0 +1 @@ +module.exports = require('../build/js/protoexport.js'); diff --git a/js/scripts/bundle.js b/js/scripts/bundle.js new file mode 100755 index 000000000..0bda70d9b --- /dev/null +++ b/js/scripts/bundle.js @@ -0,0 +1,60 @@ +#!/usr/bin/env node +var path = require('path'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); +var browserify = require('browserify') +var exec = require('child_process').exec; +var destinationPath = path.join(__dirname, '../../dist'); +var inputFile = path.join(__dirname, '../../build/js/protoexport.js'); + +function makeBundle() { + var bundler = new browserify({standalone: 'machinetalk.protobuf'}); + bundler.add(inputFile); + + bundler.bundle(function (err, src, map) { + if (err) { + console.log('Error:', err); + } + + mkdirp.sync(destinationPath); + fs.writeFileSync(path.join(destinationPath, 'machinetalk-protobuf.js'), src); + + console.log('bundle created'); + }); +} + +function makeMinBundle() { + // As of browserify 5, you must enable debug mode in the constructor to use minifyify + var bundler = new browserify({debug: true, standalone: 'machinetalk.protobuf'}); + bundler.add(inputFile); + bundler.plugin('minifyify', {map: 'machinetalk-protobuf.min.map.json'}); + + bundler.bundle(function (err, src, map) { + if (err) { + console.log('Error:', err); + } + + mkdirp.sync(destinationPath); + fs.writeFileSync(path.join(destinationPath, 'machinetalk-protobuf.min.js'), src); + fs.writeFileSync(path.join(destinationPath, 'machinetalk-protobuf.min.map.json'), map); + + console.log('minified bundle created'); + + makeMinGzBundle(path.join(destinationPath, 'machinetalk-protobuf.min.js')); + }); +} + +function makeMinGzBundle(file) { + var cmd = 'gzip -k -f -9 ' + file; + + exec(cmd, function(err, stdout, stderr) { + if (err) { + console.log('Error:', err); + } + + console.log('Gzipped bundle created'); + }); +} + +makeBundle(); +makeMinBundle(); diff --git a/js/scripts/install.js b/js/scripts/install.js new file mode 100755 index 000000000..0f9a65b52 --- /dev/null +++ b/js/scripts/install.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node +var path = require('path'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); +var child_process = require('child_process'); +var sourcePath = path.join(__dirname, '/../../src'); +var destinationPath = path.join(__dirname, '/../../build/js'); + +var namespace = 'machinetalk/protobuf'; + +// Create list of information for protobuf files. +var protos = fs.readdirSync(path.join(sourcePath, namespace)) + .filter(function(filename) { + // Only handle .proto files. + return /\.proto$/.test(filename); + }) + .map(function(filename) { + var name = path.basename(filename, '.proto'); + var fullname = path.join(namespace, name); + return { + filename: filename, + name: name, + fullname: fullname, + protopath: path.join(sourcePath, namespace, filename), + jspath: path.join(destinationPath, namespace, name + '.js') + }; + }); + +// Generate js file for each proto file +protos.forEach(function(protos) { + mkdirp.sync(path.dirname(protos.jspath)); + child_process.execFileSync('pbjs', ['--target', 'commonjs', '--out', protos.jspath, '--path', sourcePath, protos.protopath]); +}); + + +// Generate json file to direct index.js to the generated js files. +var protosjson = protos.map(function(proto) { + return { + name: proto.name, + fullname: proto.fullname + }; +}); + +mkdirp.sync(destinationPath); +var text = ''; +protosjson.forEach(function(proto) { + text += 'module.exports[\'' + proto.name + '\'] = require(\'./' + proto.fullname + '.js\').pb;\n'; +}); +fs.writeFileSync(path.join(destinationPath, 'protoexport.js'), text); diff --git a/package.json b/package.json new file mode 100644 index 000000000..579e1dafb --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "machinetalk-protobuf", + "version": "1.0.1", + "description": "Protobuf definitions to communicate with Machinetalk", + "main": "js/index.js", + "scripts": { + "prepublish": "js/scripts/install.js", + "bundle": "js/scripts/bundle.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/machinekit/machinetalk-protobuf.git" + }, + "author": "Bob van der Linden ", + "keywords": [ + "machinetalk", + "machinekit", + "protobuf" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/machinekit/machinetalk-protobuf/issues" + }, + "homepage": "https://github.com/machinekit/machinetalk-protobuf#readme", + "dependencies": { + "mkdirp": "0.5.1", + "protobufjs": "5.0.0" + }, + "devDependencies": { + "browserify": "^13.0.0", + "minifyify": "^7.1.0" + } +} diff --git a/proto/preview.proto b/proto/preview.proto deleted file mode 100644 index 554cbdac1..000000000 --- a/proto/preview.proto +++ /dev/null @@ -1,115 +0,0 @@ -package pb; - -// see README.msgid -// msgid base: 800 -import "nanopb.proto"; - - -// experimental axis/joint representation -enum KinematicsType { - KT_JOINT = 1; - KT_TRIVKINS = 2; - KT_DELTA = 3; - // and so forth -} - -message Position { - - option (nanopb_msgopt).msgid = 800; // see README.msgid - - - optional double x = 3; - optional double y = 4; - optional double z = 5; - optional double a = 6; - optional double b = 7; - optional double c = 8; - optional double u = 9; - optional double v = 10; - optional double w = 11; -} - - -enum PreviewOpType { - PV_STRAIGHT_PROBE = 1; - PV_RIGID_TAP = 2; - PV_STRAIGHT_FEED = 3; - PV_ARC_FEED = 4; - PV_STRAIGHT_TRAVERSE = 5; - PV_SET_G5X_OFFSET = 6; - PV_SET_G92_OFFSET = 7; - PV_SET_XY_ROTATION = 8; - PV_SELECT_PLANE = 9; - PV_SET_TRAVERSE_RATE = 10; - PV_SET_FEED_RATE = 11; - PV_CHANGE_TOOL = 12; - PV_CHANGE_TOOL_NUMBER = 13; - PV_DWELL = 14; - PV_MESSAGE = 15; - PV_COMMENT = 16; - PV_USE_TOOL_OFFSET = 17; - PV_SET_PARAMS = 18; // kins, axismask, angle_units, length_units - PV_SET_FEED_MODE = 19; - PV_SOURCE_CONTEXT = 20; -} - -enum SourceType { - ST_NGC_FILE = 1; // an NGC filename - ST_NGC_STRING = 2; // an MDI string - ST_PYTHON_METHOD = 3; -}; - -message Preview { - - option (nanopb_msgopt).msgid = 801; - - required PreviewOpType type = 1; - optional int32 line_number = 2; - - // move dest pos/offset for PV_STRAIGHT_*, PV_RIGID_TAP, PV_SET_* _OFFSET - // _position for PV_ARC_FEED, PV_USE_TOOL_OFFSET - optional Position pos = 3; - - // for PV_ARC_FEED only: - optional double first_end = 4; - optional double second_end = 5; - optional double first_axis = 6; - optional double second_axis = 7; - optional int32 rotation = 8; - optional double axis_end_point = 9; - - // for PV_SET_XY_ROTATION: - optional double xy_rotation = 10; - - // for PV_SELECT_PLANE: - optional int32 plane = 11; - - // for PV_SET_TRAVERSE_RATE, PV_SET_FEED_RATE - optional double rate = 12; - - // PV_SET_FEED_MODE - optional int32 feed_mode = 13; - - // PV_DWELL - optional double time = 14; - - // PV_COMMENT, PV_MESSAGE - optional string text = 15; - - // rarely used: - optional double angular_units = 101; - optional double length_units = 102; - optional int32 probetype = 103; - optional KinematicsType kins = 104 [ default = KT_JOINT ]; - optional int32 axismask = 105; - optional int32 g5_index = 106; - - // PV_CHANGE_TOOL, PV_CHANGE_TOOL_NUMBER - optional int32 pocket = 107; - - // PV_SOURCE_CONTEXT - optional SourceType stype = 110; - optional string filename = 111; // an NGC - optional string cmdstring = 112; // an MDI command - optional int32 call_level = 113; // call stack depth -} diff --git a/proto/status.proto b/proto/status.proto deleted file mode 100644 index 41bbf4b5a..000000000 --- a/proto/status.proto +++ /dev/null @@ -1,378 +0,0 @@ -import "nanopb.proto"; -import "types.proto"; -import "preview.proto"; -import "emcclass.proto"; -import "motcmds.proto"; - -// see README.msgid -// msgid base: 1100 - -package pb; - -enum EmcTaskExecStateType { - EMC_TASK_EXEC_ERROR = 1; - EMC_TASK_EXEC_DONE = 2; - EMC_TASK_EXEC_WAITING_FOR_MOTION = 3; - EMC_TASK_EXEC_WAITING_FOR_MOTION_QUEUE = 4; - EMC_TASK_EXEC_WAITING_FOR_IO = 5; - EMC_TASK_EXEC_WAITING_FOR_MOTION_AND_IO = 7; - EMC_TASK_EXEC_WAITING_FOR_DELAY = 8; - EMC_TASK_EXEC_WAITING_FOR_SYSTEM_CMD = 9; - EMC_TASK_EXEC_WAITING_FOR_SPINDLE_ORIENTED = 10; -} - -enum EmcInterpStateType { - EMC_TASK_INTERP_IDLE = 1; - EMC_TASK_INTERP_READING = 2; - EMC_TASK_INTERP_PAUSED = 3; - EMC_TASK_INTERP_WAITING = 4; -} - -enum EmcInterpExitCodeType { - EMC_INTERP_EXIT_OK = 0; - EMC_INTERP_EXIT_EXIT = 1; - EMC_INTERP_EXIT_EXECUTE_FINISH = 2; - EMC_INTERP_EXIT_ENDFILE = 3; - EMC_INTERP_EXIT_FILE_NOT_OPEN = 4; - EMC_INTERP_EXIT_ERROR = 5; -} - -enum EmcKinematicsType { - KINEMATICS_IDENTITY = 1; - KINEMATICS_FORWARD_ONLY = 2; - KINEMATICS_INVERSE_ONLY = 3; - KINEMATICS_BOTH = 4; -} - -enum EmcTrajectoryModeType { - EMC_TRAJ_MODE_FREE = 1; - EMC_TRAJ_MODE_COORD = 2; - EMC_TRAJ_MODE_TELEOP = 3; -} - -enum EmcCanonUnitsType { - CANON_UNITS_INCHES = 1; - CANON_UNITS_MM = 2; - CANON_UNITS_CM = 3; -} - -enum EmcTimeUnitsType { - TIME_UNITS_MINUTE = 1; - TIME_UNITS_SECOND = 2; -} - -enum EmcTaskModeType { - EMC_TASK_MODE_MANUAL = 1; - EMC_TASK_MODE_AUTO = 2; - EMC_TASK_MODE_MDI = 3; -} - -enum EmcTaskStateType { - EMC_TASK_STATE_ESTOP = 1; - EMC_TASK_STATE_ESTOP_RESET = 2; - EMC_TASK_STATE_OFF = 3; - EMC_TASK_STATE_ON = 4; -} - -enum EmcAxisType { - EMC_AXIS_LINEAR = 1; - EMC_AXIS_ANGULAR = 2; -} - -enum EmcPositionOffsetType { - EMC_CONFIG_RELATIVE_OFFSET = 1; - EMC_CONFIG_MACHINE_OFFSET = 2; -} - -enum EmcPositionFeedbackType { - EMC_CONFIG_ACTUAL_FEEDBACK = 1; - EMC_CONFIG_COMMANDED_FEEDBACK = 2; -} - -message EmcToolData { - - option (nanopb_msgopt).msgid = 1100; // see README.msgid - - - required int32 index = 1; - optional int32 id = 2; - optional double xOffset = 3; - optional double yOffset = 4; - optional double zOffset = 5; - optional double aOffset = 6; - optional double bOffset = 7; - optional double cOffset = 8; - optional double uOffset = 9; - optional double vOffset = 10; - optional double wOffset = 11; - optional double diameter = 12; - optional double frontangle = 13; - optional double backangle = 14; - optional int32 orientation = 15; -} - -message EmcStatusMotionAxis { - - option (nanopb_msgopt).msgid = 1101; - - required int32 index = 1; - optional bool enabled = 2; - optional bool fault = 3; - optional double ferror_current = 4; - optional double ferror_highmark = 5; - optional bool homed = 6; - optional bool homing = 7; - optional bool inpos = 8; - optional double input = 9; - optional bool max_hard_limit = 10; - optional bool max_soft_limit = 11; - optional bool min_hard_limit = 12; - optional bool min_soft_limit = 13; - optional double output = 14; - optional bool override_limits = 15; - optional double velocity = 16; -} - -message EmcStatusConfigAxis { - - option (nanopb_msgopt).msgid = 1102; - - required int32 index = 1; - optional EmcAxisType axisType = 2; - optional double backlash = 3; - optional double max_ferror = 4; - optional double max_position_limit = 5; - optional double min_ferror = 6; - optional double min_position_limit = 7; - optional double units = 8; - optional int32 home_sequence = 9; - optional double max_acceleration = 10; - optional double max_velocity = 11; - optional string increments = 12; -} - -message EmcProgramExtension { - - option (nanopb_msgopt).msgid = 1103; - - required int32 index = 1; - optional string extension = 2; -} - -message EmcStatusAnalogIO { - - option (nanopb_msgopt).msgid = 1104; - - required int32 index = 1; - optional double value = 2; -} - -message EmcStatusDigitalIO { - - option (nanopb_msgopt).msgid = 1105; - - required int32 index = 1; - optional bool value = 2; -} - -message EmcStatusLimit { - - option (nanopb_msgopt).msgid = 1106; - - required int32 index = 1; - optional int32 value = 2; -} - -message EmcStatusGCode { - - option (nanopb_msgopt).msgid = 1107; - - required int32 index = 1; - optional int32 value = 2; -} - -message EmcStatusMCode { - - option (nanopb_msgopt).msgid = 1108; - - required int32 index = 1; - optional int32 value = 2; -} - -message EmcStatusSetting { - - option (nanopb_msgopt).msgid = 1109; - - required int32 index = 1; - optional double value = 2; -} - -message EmcStatusConfig { - - option (nanopb_msgopt).msgid = 1110; - - optional double default_acceleration = 1; - optional double angular_units = 2; - optional int32 axes = 3; - repeated EmcStatusConfigAxis axis = 4; - optional int32 axis_mask = 5; - optional double cycle_time = 6; - optional int32 debug = 7; - optional EmcKinematicsType kinematics_type = 8; - optional double linear_units = 9; - optional double max_acceleration = 10; - optional double max_velocity = 11; - optional EmcCanonUnitsType program_units = 12; - optional double default_velocity = 13; - repeated EmcProgramExtension program_extension = 14; - optional EmcPositionOffsetType position_offset = 15; - optional EmcPositionFeedbackType position_feedback = 16; - optional double max_feed_override = 17; - optional double min_feed_override = 18; - optional double max_spindle_override = 19; - optional double min_spindle_override = 20; - optional double default_spindle_speed = 21; - optional double default_linear_velocity = 22; - optional double min_velocity = 23; - optional double max_linear_velocity = 24; - optional double min_linear_velocity = 25; - optional double default_angular_velocity = 26; - optional double max_angular_velocity = 27; - optional double min_angular_velocity = 28; - optional string increments = 29; - optional string grids = 30; - optional bool lathe = 31; - optional string geometry = 32; - optional uint32 arcdivision = 33; - optional bool no_force_homing = 34; - optional string remote_path = 35; - optional EmcTimeUnitsType time_units = 36; - optional string name = 37; - repeated EmcStatusUserCommand user_command = 38; -} - -message EmcStatusMotion { - - option (nanopb_msgopt).msgid = 1111; - - optional int32 active_queue = 1; - optional Position actual_position = 2; - optional bool adaptive_feed_enabled = 3; - repeated EmcStatusAnalogIO ain = 4; - repeated EmcStatusAnalogIO aout = 5; - repeated EmcStatusMotionAxis axis = 6; - optional bool block_delete = 7; - optional int32 current_line = 8; - optional double current_vel = 9; - optional double delay_left = 10; - repeated EmcStatusDigitalIO din = 11; - optional double distance_to_go = 12; - repeated EmcStatusDigitalIO dout = 13; - optional Position dtg = 14; - optional bool enabled = 15; - optional bool feed_hold_enabled = 16; - optional bool feed_override_enabled = 17; - optional double feedrate = 18; - optional OriginIndex g5x_index = 19; - optional Position g5x_offset = 20; - optional Position g92_offset = 21; - optional int32 id = 23; - optional bool inpos = 24; - optional Position joint_actual_position = 25; - optional Position joint_position = 26; - repeated EmcStatusLimit limit = 27; - optional int32 motion_line = 28; - optional MotionType motion_type = 29; - optional EmcTrajectoryModeType motion_mode = 30; - optional bool paused = 31; - optional Position position = 32; - optional bool probe_tripped = 33; - optional int32 probe_val = 34; - optional Position probed_position = 35; - optional bool probing = 36; - optional int32 queue = 37; - optional bool queue_full = 38; - optional double rotation_xy = 39; - optional bool spindle_brake = 40; - optional int32 spindle_direction = 41; - optional bool spindle_enabled = 42; - optional int32 spindle_increasing = 43; - optional bool spindle_override_enabled = 44; - optional double spindle_speed = 45; - optional double spindlerate = 46; - optional RCS_STATUS state = 47; - optional double max_velocity = 48; - optional double max_acceleration = 49; -} - -message EmcStatusIo { - - option (nanopb_msgopt).msgid = 1112; - - optional bool estop = 1; - optional bool flood = 2; - optional bool lube = 3; - optional bool lube_level = 4; - optional bool mist = 5; - optional bool pocket_prepped = 6; - optional bool tool_in_spindle = 7; - optional Position tool_offset = 8; - repeated EmcToolData tool_table = 9; -} - -message EmcStatusTask { - - option (nanopb_msgopt).msgid = 1113; - - optional int32 echo_serial_number = 1; - optional EmcTaskExecStateType exec_state = 2; - optional string file = 3; - optional bool input_timeout = 4; - optional bool optional_stop = 5; - optional int32 read_line = 6; - optional EmcTaskModeType task_mode = 7; - optional int32 task_paused = 8; - optional EmcTaskStateType task_state = 9; - optional int32 total_lines = 10; -} - -message EmcStatusInterp { - - option (nanopb_msgopt).msgid = 1114; - - optional string command = 1; - repeated EmcStatusGCode gcodes = 2; - optional EmcInterpStateType interp_state = 3; - optional EmcInterpExitCodeType interpreter_errcode = 4; - repeated EmcStatusMCode mcodes = 5; - repeated EmcStatusSetting settings = 6; -} - -message EmcCommandParameters { - - option (nanopb_msgopt).msgid = 1115; - - optional uint32 index = 1; - optional uint32 debug_level = 2; - optional int32 line_number = 3; - optional double scale = 4; - optional double velocity = 5; - optional double distance = 6; - optional double value = 7; - optional bool enable = 8; - optional string command = 9; - optional string path = 10; - optional EmcTaskModeType task_mode = 100; - optional EmcTaskStateType task_state = 101; - optional EmcTrajectoryModeType traj_mode = 102; - optional EmcPose pose = 103; - optional EmcToolData tool_data = 104; -} - -message EmcStatusUserCommand { - - option (nanopb_msgopt).msgid = 1116; - - required int32 index = 1; - optional string command = 2; -} diff --git a/python/examples/decode_message_container.py b/python/examples/decode_message_container.py new file mode 100644 index 000000000..379a209ff --- /dev/null +++ b/python/examples/decode_message_container.py @@ -0,0 +1,13 @@ +from machinetalk.protobuf.message_pb2 import Container +from machinetalk.protobuf.types_pb2 import * + +encodedBuffer = ''.join(chr(x) for x in [0x08, 0xd2, 0x01]) + +# create the message container, reuse is more efficient +rx = Container() + +# parse the encoded message +rx.ParseFromString(encodedBuffer) + +# print the decoded message +print(rx) diff --git a/python/examples/encode_message_container.py b/python/examples/encode_message_container.py new file mode 100644 index 000000000..aa24f562a --- /dev/null +++ b/python/examples/encode_message_container.py @@ -0,0 +1,15 @@ +from machinetalk.protobuf.message_pb2 import Container +from machinetalk.protobuf.types_pb2 import * + +# create the message container, reuse is more efficient +tx = Container() + +# define the message +tx.Clear() +tx.type = MT_PING + +# encode the message +encodedBuffer = tx.SerializeToString() + +# print the buffer +print(encodedBuffer) diff --git a/python/machinetalk/__init__.py b/python/machinetalk/__init__.py new file mode 100644 index 000000000..b0d643371 --- /dev/null +++ b/python/machinetalk/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/python/machinetalk/protobuf/__init__.py b/python/machinetalk/protobuf/__init__.py new file mode 100644 index 000000000..b0d643371 --- /dev/null +++ b/python/machinetalk/protobuf/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 000000000..7b3872561 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python + +from distutils.core import setup + +#! /usr/bin/env python +# +# See README for usage instructions. +import glob +import os +import subprocess +import sys + +# We must use setuptools, not distutils, because we need to use the +# namespace_packages option for the "google" package. +try: + from setuptools import setup, Extension, find_packages +except ImportError: + try: + from ez_setup import use_setuptools + use_setuptools() + from setuptools import setup, Extension, find_packages + except ImportError: + sys.stderr.write( + "Could not import setuptools; make sure you have setuptools or " + "ez_setup installed.\n" + ) + raise + +from distutils.command.clean import clean as _clean + +if sys.version_info[0] == 3: + # Python 3 + from distutils.command.build_py import build_py_2to3 as _build_py +else: + # Python 2 + from distutils.command.build_py import build_py as _build_py +from distutils.spawn import find_executable + +# Find the Protocol Compiler. +if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): + protoc = os.environ['PROTOC'] +elif os.path.exists("../src/protoc"): + protoc = "../src/protoc" +elif os.path.exists("../src/protoc.exe"): + protoc = "../src/protoc.exe" +elif os.path.exists("../vsprojects/Debug/protoc.exe"): + protoc = "../vsprojects/Debug/protoc.exe" +elif os.path.exists("../vsprojects/Release/protoc.exe"): + protoc = "../vsprojects/Release/protoc.exe" +else: + protoc = find_executable("protoc") + +google_protobuf_includedir = subprocess.check_output(["pkg-config", "--variable=includedir", "protobuf"]).decode().strip() + +def generate_proto(source, require = True): + """Invokes the Protocol Compiler to generate a _pb2.py from the given + .proto file. Does nothing if the output already exists and is newer than + the input.""" + + if not require and not os.path.exists(source): + return + + output = source.replace(".proto", "_pb2.py").replace("../src/", "") + + if (not os.path.exists(output) or + (os.path.exists(source) and + os.path.getmtime(source) > os.path.getmtime(output))): + print("Generating %s..." % output) + + if not os.path.exists(source): + sys.stderr.write("Can't find required file: %s\n" % source) + sys.exit(-1) + + if protoc is None: + sys.stderr.write( + "protoc is not installed nor found in ../src. " + "Please compile it or install the binary package.\n" + ) + sys.exit(-1) + + protoc_command = [protoc, "-I../src", "-I" + google_protobuf_includedir, "--python_out=.", source] + print("Command: %s" % protoc_command) + if subprocess.call(protoc_command) != 0: + sys.exit(-1) + +class clean(_clean): + def run(self): + # Delete generated files in the code tree. + for (dirpath, dirnames, filenames) in os.walk("."): + for filename in filenames: + filepath = os.path.join(dirpath, filename) + if filepath.endswith("_pb2.py") or filepath.endswith(".pyc"): + os.remove(filepath) + # _clean is an old-style class, so super() doesn't work. + _clean.run(self) + + +class build_py(_build_py): + def run(self): + # Generate necessary .proto file if it doesn't exist. + generate_proto("../src/machinetalk/protobuf/canon.proto") + generate_proto("../src/machinetalk/protobuf/config.proto") + generate_proto("../src/machinetalk/protobuf/emcclass.proto") + generate_proto("../src/machinetalk/protobuf/log.proto") + generate_proto("../src/machinetalk/protobuf/message.proto") + generate_proto("../src/machinetalk/protobuf/motcmds.proto") + generate_proto("../src/machinetalk/protobuf/nanopb.proto") + generate_proto("../src/machinetalk/protobuf/object.proto") + generate_proto("../src/machinetalk/protobuf/preview.proto") + generate_proto("../src/machinetalk/protobuf/rtapi_message.proto") + generate_proto("../src/machinetalk/protobuf/rtapicommand.proto") + generate_proto("../src/machinetalk/protobuf/status.proto") + generate_proto("../src/machinetalk/protobuf/task.proto") + generate_proto("../src/machinetalk/protobuf/test.proto") + generate_proto("../src/machinetalk/protobuf/types.proto") + generate_proto("../src/machinetalk/protobuf/value.proto") + + # _build_py is an old-style class, so super() doesn't work. + _build_py.run(self) + +if __name__ == '__main__': + setup(name="machinetalk_protobuf", + version="1.0", + description="Protobuf Python modules for Machinetalk", + url="https://github.com/machinekit/machinetalk-protobuf", + namespace_packages=['machinetalk'], + packages=find_packages(), + install_requires=['setuptools'], + cmdclass={ + 'clean': clean, + 'build_py': build_py, + } + ) diff --git a/scripts/asciidoc.mustache b/scripts/asciidoc.mustache new file mode 100644 index 000000000..a29dc666e --- /dev/null +++ b/scripts/asciidoc.mustache @@ -0,0 +1,45 @@ += Machinetalk Protobuf Documentation +:toc: + +{{#files}} + +== {{file_name}} + +{{#file_description}}{{file_description}}{{/file_description}} + +{{#file_messages}} + +=== {{message_long_name}} +{{message_description}} + +|=========================================== +|*Field* |*Type* |*Label* |*Description* +{{#message_fields}} +|{{field_name}} | <<{{field_long_type}},{{field_long_type}}>> |{{field_label}} |{{#nobr}}{{field_description}}{{/nobr}} +{{/message_fields}} +|=========================================== +{{/file_messages}} + +{{#file_enums}} + +[[{{enum_long_name}}]] +=== {{enum_long_name}} +{{enum_description}} + +|===================================== +|*Name* |*Number* |*Description* +{{#enum_values}} +|{{value_name}} |{{value_number}} |{{#nobr}}{{value_description}}{{/nobr}} +{{/enum_values}} +|===================================== +{{/file_enums}} +{{/files}} + +== Scalar Value Types + +|============================================================== +|*.proto Type* |*Notes* |*C++ Type* |*Java Type* |*Python Type* +{{#scalar_value_types}} +|[[{{scalar_value_proto_type}}]] ((({{scalar_value_proto_type}}))) {{scalar_value_proto_type}} |{{scalar_value_notes}} |{{scalar_value_cpp_type}} |{{scalar_value_java_type}} |{{scalar_value_python_type}} +{{/scalar_value_types}} +|============================================================== diff --git a/scripts/markdown.mustache b/scripts/markdown.mustache new file mode 100644 index 000000000..cc62331f8 --- /dev/null +++ b/scripts/markdown.mustache @@ -0,0 +1,56 @@ +# Protocol Documentation + + +## Table of Contents +{{#files}} +* [{{file_name}}](#{{file_name}}) + {{#file_messages}} + * [{{message_long_name}}](#{{message_full_name}}) + {{/file_messages}} + {{#file_enums}} + * [{{enum_long_name}}](#{{enum_full_name}}) + {{/file_enums}} +{{/files}} +* [Scalar Value Types](#scalar-value-types) + +{{#files}} + +

Top

+ +## {{file_name}} + +{{#file_messages}} + +### {{message_long_name}} +{{message_description}} + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +{{#message_fields}} +| {{field_name}} | [{{field_long_type}}](#{{field_full_type}}) | {{field_label}} | {{#nobr}}{{field_description}}{{/nobr}} | +{{/message_fields}} + +{{/file_messages}} + +{{#file_enums}} + +### {{enum_long_name}} +{{enum_description}} + +| Name | Number | Description | +| ---- | ------ | ----------- | +{{#enum_values}} +| {{value_name}} | {{value_number}} | {{#nobr}}{{value_description}}{{/nobr}} | +{{/enum_values}} + +{{/file_enums}} +{{/files}} + + +## Scalar Value Types + +| .proto Type | Notes | C++ Type | Java Type | Python Type | +| ----------- | ----- | -------- | --------- | ----------- | +{{#scalar_value_types}} +| {{scalar_value_proto_type}} | {{scalar_value_notes}} | {{scalar_value_cpp_type}} | {{scalar_value_java_type}} | {{scalar_value_python_type}} | +{{/scalar_value_types}} diff --git a/scripts/protoc-gen-depends b/scripts/protoc-gen-depends index 6cdd1bae4..aeef97499 100755 --- a/scripts/protoc-gen-depends +++ b/scripts/protoc-gen-depends @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # protoc plugin to generate dependeny files # # the .d file format is rather project specific @@ -21,8 +21,15 @@ from optparse import OptionParser import sys import os, string +if sys.version_info >= (3, 0): + # Python 3 does handle encoding differently + # Read all bytes (without text-encoding) from stdin to input_str + input_str = sys.stdin.buffer.raw.readall() +else: + input_str = sys.stdin.read() + req = CodeGeneratorRequest() -req.MergeFromString(''.join(stdin.readlines())) +req.MergeFromString(input_str) optparser = OptionParser() optparser.add_option("-v","--vpath", dest="vpath", metavar="DIR", action="append", default=[], help="list of directories to search for proto files.") @@ -81,4 +88,8 @@ def add_depends(fd): res.file.extend([add_depends(fileDescriptor) for fileDescriptor in req.proto_file]) -stdout.write(res.SerializeToString()) +if sys.version_info >= (3, 0): + # With Python 3 we write to buffer + stdout.buffer.write(res.SerializeToString()) +else: + stdout.write(res.SerializeToString()) diff --git a/proto/README.msgid b/src/README.msgid similarity index 100% rename from proto/README.msgid rename to src/README.msgid diff --git a/proto/canon.proto b/src/machinetalk/protobuf/canon.proto similarity index 96% rename from proto/canon.proto rename to src/machinetalk/protobuf/canon.proto index e9cad16f4..6c0dfda30 100644 --- a/proto/canon.proto +++ b/src/machinetalk/protobuf/canon.proto @@ -1,11 +1,11 @@ -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 100 -import "types.proto"; -import "emcclass.proto"; -import "motcmds.proto"; +import "machinetalk/protobuf/types.proto"; +import "machinetalk/protobuf/emcclass.proto"; +import "machinetalk/protobuf/motcmds.proto"; package pb; diff --git a/proto/config.proto b/src/machinetalk/protobuf/config.proto similarity index 98% rename from proto/config.proto rename to src/machinetalk/protobuf/config.proto index 71c151d72..d79fa23b0 100644 --- a/proto/config.proto +++ b/src/machinetalk/protobuf/config.proto @@ -1,4 +1,4 @@ -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 200 diff --git a/proto/emcclass.proto b/src/machinetalk/protobuf/emcclass.proto similarity index 96% rename from proto/emcclass.proto rename to src/machinetalk/protobuf/emcclass.proto index 34e019797..961e89c31 100644 --- a/proto/emcclass.proto +++ b/src/machinetalk/protobuf/emcclass.proto @@ -1,4 +1,4 @@ -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 300 diff --git a/proto/log.proto b/src/machinetalk/protobuf/log.proto similarity index 81% rename from proto/log.proto rename to src/machinetalk/protobuf/log.proto index c3b0ead6e..8535ca6c3 100644 --- a/proto/log.proto +++ b/src/machinetalk/protobuf/log.proto @@ -2,8 +2,8 @@ package pb; // see README.msgid // msgid base: 400 -import "nanopb.proto"; -import "types.proto"; +import "machinetalk/protobuf/nanopb.proto"; +import "machinetalk/protobuf/types.proto"; message LogMessage { diff --git a/proto/message.proto b/src/machinetalk/protobuf/message.proto similarity index 94% rename from proto/message.proto rename to src/machinetalk/protobuf/message.proto index 6c15934de..78f9bb48d 100644 --- a/proto/message.proto +++ b/src/machinetalk/protobuf/message.proto @@ -7,20 +7,20 @@ package pb; -import "nanopb.proto"; -import "types.proto"; -import "object.proto"; -import "log.proto"; -import "motcmds.proto"; -//import "test.proto"; -import "task.proto"; -import "canon.proto"; -import "value.proto"; -import "rtapicommand.proto"; -import "rtapi_message.proto"; -import "config.proto"; -import "preview.proto"; -import "status.proto"; +import "machinetalk/protobuf/nanopb.proto"; +import "machinetalk/protobuf/types.proto"; +import "machinetalk/protobuf/object.proto"; +import "machinetalk/protobuf/log.proto"; +import "machinetalk/protobuf/motcmds.proto"; +//import "machinetalk/protobuf/test.proto"; +import "machinetalk/protobuf/task.proto"; +import "machinetalk/protobuf/canon.proto"; +import "machinetalk/protobuf/value.proto"; +import "machinetalk/protobuf/rtapicommand.proto"; +import "machinetalk/protobuf/rtapi_message.proto"; +import "machinetalk/protobuf/config.proto"; +import "machinetalk/protobuf/preview.proto"; +import "machinetalk/protobuf/status.proto"; message Container { diff --git a/proto/motcmds.proto b/src/machinetalk/protobuf/motcmds.proto similarity index 99% rename from proto/motcmds.proto rename to src/machinetalk/protobuf/motcmds.proto index af2d14a06..9cda03509 100644 --- a/proto/motcmds.proto +++ b/src/machinetalk/protobuf/motcmds.proto @@ -3,8 +3,8 @@ package pb; // see README.msgid // msgid base: 600 -import "emcclass.proto"; -import "nanopb.proto"; +import "machinetalk/protobuf/emcclass.proto"; +import "machinetalk/protobuf/nanopb.proto"; // an uncleaned first transliteration diff --git a/proto/nanopb.proto b/src/machinetalk/protobuf/nanopb.proto similarity index 100% rename from proto/nanopb.proto rename to src/machinetalk/protobuf/nanopb.proto diff --git a/proto/object.proto b/src/machinetalk/protobuf/object.proto similarity index 98% rename from proto/object.proto rename to src/machinetalk/protobuf/object.proto index 501f31232..0a578a54d 100644 --- a/proto/object.proto +++ b/src/machinetalk/protobuf/object.proto @@ -4,8 +4,8 @@ // msgid base: 700 -import "nanopb.proto"; -import "types.proto"; +import "machinetalk/protobuf/nanopb.proto"; +import "machinetalk/protobuf/types.proto"; package pb; diff --git a/src/machinetalk/protobuf/preview.proto b/src/machinetalk/protobuf/preview.proto new file mode 100644 index 000000000..6913e35ed --- /dev/null +++ b/src/machinetalk/protobuf/preview.proto @@ -0,0 +1,127 @@ +package pb; + +// see README.msgid +// msgid base: 800 +import "machinetalk/protobuf/nanopb.proto"; + +/** + * Experimental axis/joint representation. + */ +enum KinematicsType { + KT_JOINT = 1; /// Joint kinematics. + KT_TRIVKINS = 2; /// Trivial kinematics. + KT_DELTA = 3; /// Delta kinematics. + // and so forth +} + +/** + * Preview position. + */ +message Position { + + option (nanopb_msgopt).msgid = 800; // see README.msgid + + optional double x = 3; + optional double y = 4; + optional double z = 5; + optional double a = 6; + optional double b = 7; + optional double c = 8; + optional double u = 9; + optional double v = 10; + optional double w = 11; +} + +/** + * Type for preview operations. + */ +enum PreviewOpType { + PV_STRAIGHT_PROBE = 1; /// Straight probe. + PV_RIGID_TAP = 2; /// Rigid tap. + PV_STRAIGHT_FEED = 3; /// Straight feed move. + PV_ARC_FEED = 4; /// Arc feed move. + PV_STRAIGHT_TRAVERSE = 5; /// Straight traverse move. + PV_SET_G5X_OFFSET = 6; /// Set G5x offset. + PV_SET_G92_OFFSET = 7; /// Set G92 offset. + PV_SET_XY_ROTATION = 8; /// Set XY rotation. + PV_SELECT_PLANE = 9; /// Select plane. + PV_SET_TRAVERSE_RATE = 10; /// Set feedrate for traverse moves. + PV_SET_FEED_RATE = 11; /// Set feedrate for normal moves. + PV_CHANGE_TOOL = 12; /// Change tool. + PV_CHANGE_TOOL_NUMBER = 13; /// Change tool number. + PV_DWELL = 14; /// Dwell. + PV_MESSAGE = 15; /// Print message. + PV_COMMENT = 16; /// GCode comment. + PV_USE_TOOL_OFFSET = 17; /// Use tool offset. + PV_SET_PARAMS = 18; /// kins, axismask, angle_units, length_units + PV_SET_FEED_MODE = 19; /// Set the feed mode. + PV_SOURCE_CONTEXT = 20; /// Change the source context. +} + +/** + * Preview source types.. + */ +enum SourceType { + ST_NGC_FILE = 1; /// An NGC file. + ST_NGC_STRING = 2; /// A MDI string. + ST_PYTHON_METHOD = 3; /// A Python method. +}; + +/** + * The preview data structure. + */ +message Preview { + + option (nanopb_msgopt).msgid = 801; + + required PreviewOpType type = 1; /// Type of the preview operation. + optional int32 line_number = 2; /// The line number this preview command corresponds to. + + /** move dest pos/offset for PV_STRAIGHT_*, PV_RIGID_TAP, PV_SET_* _OFFSET + * _position for PV_ARC_FEED, PV_USE_TOOL_OFFSET + */ + optional Position pos = 3; + + // for PV_ARC_FEED only: + optional double first_end = 4; /// First point for PV_ARC_FEED. + optional double second_end = 5; /// Second point for PV_ARC_FEED. + optional double first_axis = 6; /// First axis for PV_ARC_FEED. + optional double second_axis = 7; /// Second axis for PV_ARC_FEED. + optional int32 rotation = 8; /// Rotation for PV_ARC_FEED. + optional double axis_end_point = 9; /// Axis endpoint for PV_ARC_FEED. + + // for PV_SET_XY_ROTATION: + optional double xy_rotation = 10; /// XY rotation for PV_SET_XY_ROTATION. + + // for PV_SELECT_PLANE: + optional int32 plane = 11; /// Plane for PV_SET_XY_ROTATION. + + // for PV_SET_TRAVERSE_RATE, PV_SET_FEED_RATE + optional double rate = 12; /// feedrate for PV_SET_TRAVERSE_RATE and PV_SET_FEED_RATE. + + // PV_SET_FEED_MODE + optional int32 feed_mode = 13; /// Mode for PV_SET_FEED_MODE. + + // PV_DWELL + optional double time = 14; /// Time for PV_DWELL. + + // PV_COMMENT, PV_MESSAGE + optional string text = 15; /// Text for PV_COMMENT and PV_MESSAGE. + + // rarely used: + optional double angular_units = 101; /// Angular units: rarely used. + optional double length_units = 102; /// Length units: rarely used. + optional int32 probetype = 103; /// Probe type: rarely used. + optional KinematicsType kins = 104 [ default = KT_JOINT ]; /// Kinematics type: rarely used. + optional int32 axismask = 105; /// Axis mask: rarely used. + optional int32 g5_index = 106; /// g5_index: rarely used. + + // PV_CHANGE_TOOL, PV_CHANGE_TOOL_NUMBER + optional int32 pocket = 107; /// Pocket for PV_CHANGE_TOOL and PV_CHANGE_TOOL_NUMBER. + + // PV_SOURCE_CONTEXT + optional SourceType stype = 110; /// Source type for PV_SOURCE_CONTEXT. + optional string filename = 111; /// File name if source type is a NGC file. + optional string cmdstring = 112; /// Command string if source type is a MDI command. + optional int32 call_level = 113; /// Call stack depth. +} diff --git a/proto/rtapi_message.proto b/src/machinetalk/protobuf/rtapi_message.proto similarity index 85% rename from proto/rtapi_message.proto rename to src/machinetalk/protobuf/rtapi_message.proto index 51b42d3ce..b0140a852 100644 --- a/proto/rtapi_message.proto +++ b/src/machinetalk/protobuf/rtapi_message.proto @@ -1,5 +1,5 @@ -import "nanopb.proto"; -import "value.proto"; +import "machinetalk/protobuf/nanopb.proto"; +import "machinetalk/protobuf/value.proto"; // see README.msgid // msgid base: 1000 diff --git a/proto/rtapicommand.proto b/src/machinetalk/protobuf/rtapicommand.proto similarity index 89% rename from proto/rtapicommand.proto rename to src/machinetalk/protobuf/rtapicommand.proto index fff2add5d..228e97472 100644 --- a/proto/rtapicommand.proto +++ b/src/machinetalk/protobuf/rtapicommand.proto @@ -1,4 +1,4 @@ -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 900 @@ -25,5 +25,6 @@ message RTAPICommand { optional string comp = 10; optional string func = 11; optional string instname = 12; + optional int32 flags = 13; } diff --git a/src/machinetalk/protobuf/status.proto b/src/machinetalk/protobuf/status.proto new file mode 100644 index 000000000..c222bcd03 --- /dev/null +++ b/src/machinetalk/protobuf/status.proto @@ -0,0 +1,492 @@ +import "machinetalk/protobuf/nanopb.proto"; +import "machinetalk/protobuf/types.proto"; +import "machinetalk/protobuf/preview.proto"; +import "machinetalk/protobuf/emcclass.proto"; +import "machinetalk/protobuf/motcmds.proto"; + +// see README.msgid +// msgid base: 1100 + +package pb; + +/** + * Types for EMC task execution state. + */ +enum EmcTaskExecStateType { + EMC_TASK_EXEC_ERROR = 1; /// Error during task execution. + EMC_TASK_EXEC_DONE = 2; /// Task execution has bee completed. + EMC_TASK_EXEC_WAITING_FOR_MOTION = 3; /// Task execution is waiting for Motion. + EMC_TASK_EXEC_WAITING_FOR_MOTION_QUEUE = 4; /// Task execution is waiting for Motion queue. + EMC_TASK_EXEC_WAITING_FOR_IO = 5; /// Task execution is waiting for IO. + EMC_TASK_EXEC_WAITING_FOR_MOTION_AND_IO = 7; /// Task execution is waiting for Motion and IO. + EMC_TASK_EXEC_WAITING_FOR_DELAY = 8; /// Task execution is waiting for a delay. + EMC_TASK_EXEC_WAITING_FOR_SYSTEM_CMD = 9; /// Task execution is waiting for a system command. + EMC_TASK_EXEC_WAITING_FOR_SPINDLE_ORIENTED = 10; /// Task execution is waiting for spindle orientation to complete. +} + +/** + * Types for EMC task interpreter state. + */ +enum EmcInterpStateType { + EMC_TASK_INTERP_IDLE = 1; /// Task interpreter is idling. + EMC_TASK_INTERP_READING = 2; /// Task interpreter is reading. + EMC_TASK_INTERP_PAUSED = 3; /// Task interpreter is paused. + EMC_TASK_INTERP_WAITING = 4; /// Task interpreter is waiting. +} + +/** + * Types for EMC interpreter exit codes. + */ +enum EmcInterpExitCodeType { + EMC_INTERP_EXIT_OK = 0; /// Interpreter exited successfully. + EMC_INTERP_EXIT_EXIT = 1; /// Interpreter exited with no status information. + EMC_INTERP_EXIT_EXECUTE_FINISH = 2; /// Interpreter execution finished. + EMC_INTERP_EXIT_ENDFILE = 3; /// Interpreter has reached end of file. + EMC_INTERP_EXIT_FILE_NOT_OPEN = 4; /// Interpreter could not open the file. + EMC_INTERP_EXIT_ERROR = 5; /// Interpreter exited with an error. +} + +/** + * EMC kinematics type. + */ +enum EmcKinematicsType { + KINEMATICS_IDENTITY = 1; /// Identity kinematics. + KINEMATICS_FORWARD_ONLY = 2; /// Forward only kinematics. + KINEMATICS_INVERSE_ONLY = 3; /// Inverse only kinematics. + KINEMATICS_BOTH = 4; /// Forward and inverse kinematics. +} + + +/** + * Types for trajectory motion control. + */ +enum EmcTrajectoryModeType { + EMC_TRAJ_MODE_FREE = 1; /// Independent axis motion. + EMC_TRAJ_MODE_COORD = 2; /// Coordinated axis motion. + EMC_TRAJ_MODE_TELEOP = 3; /// Velocity based world coordinates motion. +} + +/** + * Types for EMC Canon units. + */ +enum EmcCanonUnitsType { + CANON_UNITS_INCHES = 1; /// Inches. + CANON_UNITS_MM = 2; /// Millimeters. + CANON_UNITS_CM = 3; /// Centimeters. +} + +/** + * Types for EMC linear units. + */ +enum EmcLinearUnitsType { + LINEAR_UNITS_INCHES = 1; /// Inches. + LINEAR_UNITS_MM = 2; /// Millimeters. + LINEAR_UNITS_CM = 3; /// Centimeters. +} + +/** + * Types for EMC angular units. + */ +enum EmcAngularUnitsType { + ANGULAR_UNITS_DEGREES = 1; /// Degrees. + ANGULAR_UNITS_RADIAN = 2; /// Radian. + ANGULAR_UNITS_GRAD = 3; /// Grad. +} + +/** + * Types for EMC time units. + */ +enum EmcTimeUnitsType { + TIME_UNITS_MINUTE = 1; /// Minutes. + TIME_UNITS_SECOND = 2; /// Seconds. +} + +/** + * Types for EMC task modes. + */ +enum EmcTaskModeType { + EMC_TASK_MODE_MANUAL = 1; /// Manual task mode. For example jogging. + EMC_TASK_MODE_AUTO = 2; /// Automatic task mode. For example program execution. + EMC_TASK_MODE_MDI = 3; /// MDI task mode. MDI commands only. +} + +/** + * Types for EMC task state. + */ +enum EmcTaskStateType { + EMC_TASK_STATE_ESTOP = 1; /// Task is in ESTOP. + EMC_TASK_STATE_ESTOP_RESET = 2; /// Task is trying to reset an ESTOP. + EMC_TASK_STATE_OFF = 3; /// Task is turned off (no ESTOP) + EMC_TASK_STATE_ON = 4; /// Task is turned on. +} + +/** + * Axis types. + */ +enum EmcAxisType { + EMC_AXIS_LINEAR = 1; /// Axis is using linear units. + EMC_AXIS_ANGULAR = 2; /// Axis is using angular units. +} + +/** + * Position offset types. + */ +enum EmcPositionOffsetType { + EMC_CONFIG_RELATIVE_OFFSET = 1; /// Offset in relative coordinates. + EMC_CONFIG_MACHINE_OFFSET = 2; /// Offset in machine coordinates. +} + +/** + * Position feedback types. + */ +enum EmcPositionFeedbackType { + EMC_CONFIG_ACTUAL_FEEDBACK = 1; /// Feed back current position. + EMC_CONFIG_COMMANDED_FEEDBACK = 2; /// Feed back commanded position. +} + +/** + * Tool table data. + */ +message EmcToolData { + + option (nanopb_msgopt).msgid = 1100; // see README.msgid + + + required int32 index = 1; /// Tool table index (not tool id). + optional int32 id = 2; /// ID/number of the tool. + //optional double xOffset = 3; offsets replaced by Position message + //optional double yOffset = 4; + //optional double zOffset = 5; + //optional double aOffset = 6; + //optional double bOffset = 7; + //optional double cOffset = 8; + //optional double uOffset = 9; + //optional double vOffset = 10; + //optional double wOffset = 11; + optional double diameter = 12; /// Diameter of the tool. + optional double frontangle = 13; /// Front angle of the tool (only on lathe). + optional double backangle = 14; /// Back angle of the tool (only on lathe). + optional int32 orientation = 15; /// Orientation of the tool (lathe only, 0-9). + optional Position offset = 16; /// Position offset of the tool. +} + +/** + * Stores per axis information from motion. + */ +message EmcStatusMotionAxis { + + option (nanopb_msgopt).msgid = 1101; + + required int32 index = 1; /// Axis index. + optional bool enabled = 2; /// Axis is enabled. + optional bool fault = 3; /// Axis amp fault. + optional double ferror_current = 4; /// Current following error. + optional double ferror_highmark = 5; /// Magnitude of maximum following error. + optional bool homed = 6; /// Axis has been homed. + optional bool homing = 7; /// Homing currently progress. + optional bool inpos = 8; /// Axis is in position. + optional double input = 9; /// Current input position. + optional bool max_hard_limit = 10; /// Maximum hard limit exceeded. + optional bool max_soft_limit = 11; /// Maximum position limit was exceeded. + optional bool min_hard_limit = 12; /// Minimum hard limit was exceeded. + optional bool min_soft_limit = 13; /// Minimum position limit was exceeded. + optional double output = 14; /// Commanded output position. + optional bool override_limits = 15; /// Limits are overridden. + optional double velocity = 16; /// Current velocity. +} + +/** + * Stores per axis information from configuration. + */ +message EmcStatusConfigAxis { + + option (nanopb_msgopt).msgid = 1102; + + required int32 index = 1; /// Axis index. + optional EmcAxisType axis_type = 2; /// Type of axis. Reflects [AXIS_N]TYPE + optional double backlash = 3; /// Axis backlash. Reflects [AXIS_N]BACKLASH + optional double max_ferror = 4; /// Maximum following error. Reflects [AXIS_N]FERROR + optional double max_position_limit = 5; /// Maximum position limit. Reflects [AXIS_N]MAX_LIMIT + optional double min_ferror = 6; /// Minimum following error. Reflects [AXIS_N]MIN_FERROR + optional double min_position_limit = 7; /// Minimum position limit. Reflects [AXIS_N]MIN_LIMIT + //optional double units = 8; // Units per mm. field removed + optional int32 home_sequence = 9; /// Homing sequence index. Reflects [AXIS_N]HOME_SEQUENCE + optional double max_acceleration = 10; /// Maximum acceleration. Reflects [AXIS_N]MAX_ACCELERATION + optional double max_velocity = 11; /// Maximum velocity. Reflects [AXIS_N]MAX_VELOCITY + optional string increments = 12; /// Axis increments space separated.Reflects [AXIS_N]INCREMENTS or [DISPLAY]INCREMENTS +} + +/** + * Program extension message. + */ +message EmcProgramExtension { + + option (nanopb_msgopt).msgid = 1103; + + required int32 index = 1; /// Index of the program extension. + optional string extension = 2; /// Supported program extension. E.g. .gcode GCode program +} + +/** + * Analog IO pin message. + */ +message EmcStatusAnalogIO { + + option (nanopb_msgopt).msgid = 1104; + + required int32 index = 1; /// Index of analog IO pin. + optional double value = 2; /// Current value of analog IO pin. +} + +/** + * Digital IO pin message. + */ +message EmcStatusDigitalIO { + + option (nanopb_msgopt).msgid = 1105; + + required int32 index = 1; /// Index of digital IO pin. + optional bool value = 2; /// Current value of digital IO pin. +} + +/** + * Limit mask message. + */ +message EmcStatusLimit { + + option (nanopb_msgopt).msgid = 1106; + + required int32 index = 1; /// Axis index. + optional int32 value = 2; /// Axis limit mask. minHardLimit=1, maxHardLimit=2, minSoftLimit=4, maxSoftLimit=8 +} + +/** + * Currently active GCodes message. + */ +message EmcStatusGCode { + + option (nanopb_msgopt).msgid = 1107; + + required int32 index = 1; /// Index of the GCode. + optional int32 value = 2; /// GCode value. E.g. 210 for G21 +} + +/** + * Currently active MCodes message. + */ +message EmcStatusMCode { + + option (nanopb_msgopt).msgid = 1108; + + required int32 index = 1; /// Index of MCode. + optional int32 value = 2; /// MCode value. E.g. 100 for M100 +} + +/** + * Interpreter setting message. + */ +message EmcStatusSetting { + + option (nanopb_msgopt).msgid = 1109; + + required int32 index = 1; /// Index of interpreter setting. + optional double value = 2; /// Interpreter settings value. +} + +/** + * EMC status configuration message. + */ +message EmcStatusConfig { + + option (nanopb_msgopt).msgid = 1110; + + optional double default_acceleration = 1; /// Default acceleration. Reflects parameter [TRAJ]DEFAULT_ACCELERATION. + //optional double angular_units = 2; // Angular units scale. Reflects [TRAJ]ANGULAR_UNITS field removed + optional int32 axes = 3; /// Number of axes. Reflects [TRAJ]AXES + repeated EmcStatusConfigAxis axis = 4; /// Per axis configuration values. + optional int32 axis_mask = 5; /// Mask of axes. Reflects [TRAJ]COORDINATES and returns the sum of the axes X=1, Y=2, Z=4, A=8, B=16, C=32, U=64, V=128, W=256. + optional double cycle_time = 6; /// Polling cycle time. Reflects [TRAJ]CYCLE_TIME + optional int32 debug = 7; /// Debug flag. + optional EmcKinematicsType kinematics_type = 8; /// Kinematics type. + //optional double linear_units = 9; // Linear units scale. Reflects [TRAJ]LINEAR_UNITS field removed + optional double max_acceleration = 10; /// Maximum acceleration. Reflects [TRAJ]MAX_ACCELERATION + optional double max_velocity = 11; /// Maximum velocity. Reflects [TRAJ]MAX_VELOCITY + optional EmcLinearUnitsType linear_units = 12; /// Linear machine units. Reflects [TRAJ]LINEAR_UNITS + optional double default_velocity = 13; /// Default velocity. Reflects [TRAJ]DEFAULT_VELOCITY + repeated EmcProgramExtension program_extension = 14; /// List if program supported program extensions. + optional EmcPositionOffsetType position_offset = 15; /// Position offset type. Reflects [DISPLAY]POSITION_OFFSET + optional EmcPositionFeedbackType position_feedback = 16; /// Position feedback type. Reflects [DISPLAY]POSITION_FEEDBACK + optional double max_feed_override = 17; /// Maximum feed override. Reflects [DISPLAY]MAX_FEED_OVERRIDE + optional double min_feed_override = 18; /// Minimum feed override. Reflects [DISPLAY]MIN_FEED_OVERRIDE + optional double max_spindle_override = 19; /// Maximum spindle speed override. Reflects [DISPLAY]MAX_SPINDLE_OVERRIDE + optional double min_spindle_override = 20; /// Minimum spindle override. Reflects [DISPLAY]MIN_SPINDLE_OVERRIDE + optional double default_spindle_speed = 21; /// Default spindle speed. Reflects [DISPLAY]DEFAULT_SPINDLE_SPEED + optional double default_linear_velocity = 22; /// Default linear velocity. Reflects [DISPLAY]DEFAULT_LINEAR_VELOCITY + optional double min_velocity = 23; /// Minimum velocity override. Reflects [DISPLAY]MIN_VELOCITY + optional double max_linear_velocity = 24; /// Maximum linear velocity. Reflects [DISPLAY]MAX_LINEAR_VELOCITY + optional double min_linear_velocity = 25; /// Minimum linear velocity. Reflects [DISPLAY]MIN_LINEAR_VELOCITY + optional double default_angular_velocity = 26; /// Default angular velocity. Reflects [DISPLAY]DEFAULT_ANGULAR_VELOCITY + optional double max_angular_velocity = 27; /// Maximum angular velocity. Reflects [DISPLAY]MAX_ANGULAR_VELOCITY + optional double min_angular_velocity = 28; /// Minimum angular velocity. Reflects [DISPLAY]MIN_ANGULAR_VELOCITY + optional string increments = 29; /// White space separated jog increments. Reflects [DISPLAY]INCREMENTS + optional string grids = 30; /// Grid intervals. Reflects [DISPLAY]GRIDS + optional bool lathe = 31; /// Is machine a lathe. Reflects [DISPLAY]LATHE + optional string geometry = 32; /// Geometry of machine. E.g. XYZ. Reflects [DISPLAY]GEOMETRY + optional uint32 arcdivision = 33; /// Display granularity for arcs. Reflects [DISPLAY]ARCDIVISION + optional bool no_force_homing = 34; /// Do not enforce homing. Reflects [DISPLAY]NO_FORCE_HOMING + optional string remote_path = 35; /// Remote file path. Reflects [DISPLAY]PROGRAM_PREFIX + optional EmcTimeUnitsType time_units = 36; /// Time units type. Reflects [DISPLAY]TIME_UNITS + optional string name = 37; /// Machine name. Reflects [EMC]MACHINE + repeated EmcStatusUserCommand user_command = 38; /// List of user commands. Reflects [DISPLAY]USER_COMMAND + optional EmcAngularUnitsType angular_units = 39; /// Angular machine units. Reflects [TRAJ]ANGULAR_UNITS +} + +/** + * EMC status motion message. + */ +message EmcStatusMotion { + + option (nanopb_msgopt).msgid = 1111; + + optional int32 active_queue = 1; /// Number of motions blending. + optional Position actual_position = 2; /// Current trajectory position. + optional bool adaptive_feed_enabled = 3; /// Status of adaptive feed override. + repeated EmcStatusAnalogIO ain = 4; /// Status of analog input pins. + repeated EmcStatusAnalogIO aout = 5; /// Status of analog output pins. + repeated EmcStatusMotionAxis axis = 6; /// Per axis motion values. + optional bool block_delete = 7; /// Block delete on or off. + optional int32 current_line = 8; /// Currently executing line. + optional double current_vel = 9; /// Current velocity in Cartesian space. + optional double delay_left = 10; /// Remaining time on dwell (G4) command. + repeated EmcStatusDigitalIO din = 11; /// Status of digital input pins. + optional double distance_to_go = 12; /// Remaining distance of current move reported by trajectory planner. + repeated EmcStatusDigitalIO dout = 13; /// Status of digital output pins. + optional Position dtg = 14; /// Remaining distance of current move reported by trajectory planner. + optional bool enabled = 15; /// Trajectory planner enabled flag. + optional bool feed_hold_enabled = 16; /// Enable flag for feed hold. + optional bool feed_override_enabled = 17; /// Enable flag for feed override. + optional double feedrate = 18; /// Current feedrate override. + optional OriginIndex g5x_index = 19; /// Currently active coordinate system. + optional Position g5x_offset = 20; /// Offset of the currently active coordinate system. + optional Position g92_offset = 21; /// Current G92 offset. + optional int32 id = 23; /// Currently executing motion id. + optional bool inpos = 24; /// Machine in position flag. + optional Position joint_actual_position = 25; /// Actual joint position. + optional Position joint_position = 26; /// Desired joint position. + repeated EmcStatusLimit limit = 27; /// Axis limit masks. + optional int32 motion_line = 28; /// Source line number motion is currently executing. Relation to id is unclear. + optional MotionType motion_type = 29; /// Trajectory planner mode. + optional EmcTrajectoryModeType motion_mode = 30; /// Trajectory mode. + optional bool paused = 31; /// Motion paused flag. + optional Position position = 32; /// Trajectory position. + optional bool probe_tripped = 33; /// True if probe has tripped. + optional int32 probe_val = 34; /// Reflects the value of the motion.probe-input pin + optional Position probed_position = 35; /// Position where probe has tripped + optional bool probing = 36; /// Probe operation in progress. + optional int32 queue = 37; /// Current size of trajectory planner queue. + optional bool queue_full = 38; /// Trajectory planner queue is full. + optional double rotation_xy = 39; /// Current XY rotation around Z axis. + optional bool spindle_brake = 40; /// Spindle braked. + optional int32 spindle_direction = 41; /// Rotational direction of the spindle. forward=1, reverse=-1. + optional bool spindle_enabled = 42; /// Spindle enabled. + optional int32 spindle_increasing = 43; /// Spindle speed is increasing. + optional bool spindle_override_enabled = 44; /// Spindle override is enabled. + optional double spindle_speed = 45; /// Spindle speed value in rpm. > 0 is clockwise, < 0 is counterclockwise + optional double spindlerate = 46; /// Spindle speed override. + optional RCS_STATUS state = 47; /// Current command execution status. + optional double max_velocity = 48; /// Maximum velocity override. + optional double max_acceleration = 49; /// TODO remove +} + +/** + * EMC IO message. + */ +message EmcStatusIo { + + option (nanopb_msgopt).msgid = 1112; + + optional bool estop = 1; /// Estop active. + optional bool flood = 2; /// Flood enabled. + optional bool lube = 3; /// Lube enabled. + optional bool lube_level = 4; /// Lube level. Reflects iocontrol.0.lube_level + optional bool mist = 5; /// Mist enabled. + optional bool pocket_prepped = 6; /// A Tx command completed and this pocket is prepared. TODO wrong type? + optional bool tool_in_spindle = 7; /// Current tool number. + optional Position tool_offset = 8; /// Offset values of the current tool. + repeated EmcToolData tool_table = 9; /// List of tool entries. +} + +/** + * EMC status task message. + */ +message EmcStatusTask { + + option (nanopb_msgopt).msgid = 1113; + + /** + * The serial number of the last executed command set by a UI to task. + * All commands carry a serial number. Once the command has been executed, + * its serial number is reflected in echo_serial_number. + */ + optional int32 echo_serial_number = 1; + optional EmcTaskExecStateType exec_state = 2; /// Task execution state. + optional string file = 3; /// Currently executing gcode file. + optional bool input_timeout = 4; /// Flag for M66 timer in progress. + optional bool optional_stop = 5; /// Optional stop enabled. + optional int32 read_line = 6; /// Line the RS274NGC interpreter is currently reading. TODO move to interp + optional EmcTaskModeType task_mode = 7; /// Current task mode. + optional int32 task_paused = 8; /// Task paused. + optional EmcTaskStateType task_state = 9; /// Current task state. + optional int32 total_lines = 10; /// Total number of lines of currently active program file. +} + +/** + * EMC status interpreter message. + */ +message EmcStatusInterp { + + option (nanopb_msgopt).msgid = 1114; + + optional string command = 1; /// Currently executing command. + repeated EmcStatusGCode gcodes = 2; /// Currently active GCodes. + optional EmcInterpStateType interp_state = 3; /// Current state of RS274NGC interpreter. + optional EmcInterpExitCodeType interpreter_errcode = 4; /// Current RS274NGC interpreter return code. + repeated EmcStatusMCode mcodes = 5; /// Currently active MCodes. + repeated EmcStatusSetting settings = 6; /// Current interpreter settings. [0] = sequence number, [1] = feed rate, [2] = velocity + optional EmcCanonUnitsType program_units = 7; /// Current interpreter program units. +} + +/** + * EMC command parameters. + */ +message EmcCommandParameters { + + option (nanopb_msgopt).msgid = 1115; + + optional uint32 index = 1; /// General purpose index. + optional uint32 debug_level = 2; /// Debug level. + optional int32 line_number = 3; /// General purpose line number. + optional double scale = 4; /// General purpose scale value. + optional double velocity = 5; /// General purpose velocity value. + optional double distance = 6; /// General purpose distance value. + optional double value = 7; /// General purpose value. + optional bool enable = 8; /// General purpose enable value. + optional string command = 9; /// General purpose command string. + optional string path = 10; /// General purpose path string. + optional EmcTaskModeType task_mode = 100; /// Task mode. + optional EmcTaskStateType task_state = 101; /// Task state. + optional EmcTrajectoryModeType traj_mode = 102; /// Trajectory mode. + optional EmcPose pose = 103; /// General purpose pose. + optional EmcToolData tool_data = 104; /// Tool data. +} + +/** + * User command message. + */ +message EmcStatusUserCommand { + + option (nanopb_msgopt).msgid = 1116; + + required int32 index = 1; /// User command index. + optional string command = 2; /// User command separated by semicolon. E.g. G1A20;G1A0 Remove Filament. +} diff --git a/proto/task.proto b/src/machinetalk/protobuf/task.proto similarity index 96% rename from proto/task.proto rename to src/machinetalk/protobuf/task.proto index 0b0676cf8..e0b968e6a 100644 --- a/proto/task.proto +++ b/src/machinetalk/protobuf/task.proto @@ -35,8 +35,8 @@ // interpreter reply to a command: // MT_EMC_TASK_PLAN_REPLY = 10530; -import "types.proto"; -import "nanopb.proto"; +import "machinetalk/protobuf/types.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 1200 diff --git a/proto/test.proto b/src/machinetalk/protobuf/test.proto similarity index 87% rename from proto/test.proto rename to src/machinetalk/protobuf/test.proto index 7f7612595..6f0dde16f 100644 --- a/proto/test.proto +++ b/src/machinetalk/protobuf/test.proto @@ -1,7 +1,7 @@ // use any of the below for testing and experimentation. -import "emcclass.proto"; -import "nanopb.proto"; +import "machinetalk/protobuf/emcclass.proto"; +import "machinetalk/protobuf/nanopb.proto"; package pb; diff --git a/proto/types.proto b/src/machinetalk/protobuf/types.proto similarity index 98% rename from proto/types.proto rename to src/machinetalk/protobuf/types.proto index 649999673..cfa696a1d 100644 --- a/proto/types.proto +++ b/src/machinetalk/protobuf/types.proto @@ -1,5 +1,5 @@ // fundamental types -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; // see README.msgid // msgid base: 1400 @@ -344,6 +344,10 @@ enum ContainerType { // generic error reply. note field contains explanation. MT_ERROR = 360; + // generic full update and incremental update + MT_FULL_UPDATE = 370; + MT_INCREMENTAL_UPDATE = 371; + // task/client comms MT_TASK_REPLY = 400; MT_TICKET_UPDATE = 401; @@ -636,6 +640,10 @@ enum ContainerType { MT_EMC_NML_TEXT = 12511; MT_EMC_NML_DISPLAY = 12512; + // EMC command + MT_EMCCMD_EXECUTED = 12520; + MT_EMCCMD_COMPLETED = 12521; + // launcher pub-sub MT_LAUNCHER_FULL_UPDATE = 12600; MT_LAUNCHER_INCREMENTAL_UPDATE = 12601; @@ -650,6 +658,7 @@ enum ContainerType { } enum OriginIndex { + ORIGIN_UNKNOWN = 0; ORIGIN_G54 = 1; ORIGIN_G55 = 2; ORIGIN_G56 = 3; @@ -693,7 +702,7 @@ enum InterpreterStateType { INTERP_RUNNING = 2; INTERP_SYNC_WAIT = 3; INTERP_PAUSED = 4; - INTERP_QEUEUE_WAIT = 5; + INTERP_QUEUE_WAIT = 5; INTERP_ABORT_WAIT = 6; INTERP_STATE_UNSET = 99; // to ease change tracking }; diff --git a/proto/value.proto b/src/machinetalk/protobuf/value.proto similarity index 87% rename from proto/value.proto rename to src/machinetalk/protobuf/value.proto index 3187dfc3c..c7fb1840d 100644 --- a/proto/value.proto +++ b/src/machinetalk/protobuf/value.proto @@ -1,7 +1,7 @@ -import "nanopb.proto"; +import "machinetalk/protobuf/nanopb.proto"; -import "emcclass.proto"; -import "types.proto"; +import "machinetalk/protobuf/emcclass.proto"; +import "machinetalk/protobuf/types.proto"; // see README.msgid // msgid base: 1500