diff --git a/fc/css/gbajs.css b/fc/css/gbajs.css
deleted file mode 100644
index 3e17b3a..0000000
--- a/fc/css/gbajs.css
+++ /dev/null
@@ -1,686 +0,0 @@
-@charset "utf-8";
- a,mark {
- color:inherit
-}
-html {
- color:#000;
- background:#fff;
- font-family:Arial,'Microsoft YaHei';
- font-size:34px;
- -webkit-user-select:none;
- user-select:none;
- -webkit-overflow-scrolling:touch
-}
-body,button,dd,div,dl,dt,form,h1,h2,h3,h4,h5,h6,input,li,ol,p,pre,strong,td,textarea,th,ul {
- padding:0;
- margin:0
-}
-table {
- border-collapse:collapse;
- border-spacing:0
-}
-img {
- display:block;
- border:0;
- max-width:100%
-}
-a {
- text-decoration:none;
- outline:0
-}
-em,i,strong {
- font-style:inherit;
- font-weight:inherit
-}
-li {
- list-style:none
-}
-h1,h2,h3,h4,h5,h6 {
- font-size:100%;
- font-weight:400
-}
-button,input,optgroup,option,select,textarea {
- font-family:inherit;
- font-size:inherit;
- font-style:inherit;
- font-weight:inherit
-}
-mark {
- background-color:rgba(0,0,0,0)
-}
-.clearfix:after {
- content:"\200B";
- display:block;
- height:0;
- clear:both
-}
-.none,[v-cloak] {
- display:none
-}
-.dire-wrap,.key-wrap {
- display:inline-block;
- overflow:hidden;
- will-change:auto;
- contain:style;
- backface-visibility:hidden
-}
-.mask {
- position:fixed;
- width:100%;
- height:100%;
- left:0;
- top:0;
- z-index:95;
- background:rgba(0,0,0,.7)
-}
-.tx_ov {
- overflow:hidden;
- white-space:nowrap;
- text-overflow:ellipsis
-}
-.tx_wrap {
- word-break:break-all;
- word-wrap:break-word
-}
-body {
- background:#000
-}
-.dc-centre,.dc-dire,.dire-ctrl,.key-btn {
- background-size:100% 100%
-}
-#screen {
- position:absolute;
- width:256px;
- height:240px;
- top:calc((100vh + 50px - 256px)/ 2);
- right: 240px;
- transform:scale(3.3333,3.3333) rotate(90deg);
- border:none;
- overflow:hidden
-}
-.ctrl-wrap {
- position:fixed;
- height:100vh;
- width:100%;
- top:0;
- left:0
-}
-.dc-centre,.dc-dire,.dire-ctrl,.dire-wrap,.key-btn,.key-wrap {
- position:absolute
-}
-.dire-wrap {
- width:390px;
- height:390px;
- top:-10px;
- left:-10px
-}
-.dire-ctrl {
- width:290px;
- height:290px;
- margin:50px;
- background-image:url(../resources/7.png);
- overflow:hidden
-}
-.dc-centre {
- width:124px;
- height:124px;
- background-image:url(../resources/8.png);
- will-change:auto;
- contain:style
-}
-.dc-dire {
- width:384px;
- height:384px;
- margin:3px;
- background-image:url(../resources/9.png);
- will-change:auto;
- contain:style
-}
-.key-wrap {
- width:100vw;
- height:390px;
- bottom:20px;
- left:20px
-}
-.key-btn {
- width:150px;
- height:150px;
- line-height:150px;
- text-align:center;
- font-size:56px;
- transform:rotate(90deg);
- font-weight:700;
- color:rgba(255,255,255,.5);
- opacity:.5;
- background-image:url(../resources/8.png)
-}
-.key-btn.kay-B {
- top:88px;
- left:90px;
- opacity:.7
-}
-.key-btn.kay-A {
- top:220px;
- left:0px;
- opacity:.7
-}
-.key-btn.kay-Y {
- top:88px;
- left:232px
-}
-.key-btn.kay-X {
- top:256px;
- left:162px
-}
-.key-btn.kay-AB {
- top:220px;
- left:222px
-}
-.key-btn.flat-btn {
- width:120px;
- height:80px;
- font-size:30px;
- line-height:80px
-}
-.key-btn.kay-SE {
- top:120px;
- right:60px
-}
-.key-btn.kay-ST {
- top:260px;
- right:60px
-}
-.btn-on {
- transform:scale(.9,.9) rotate(90deg)
-}
-.layui-m-layer {
- position:relative;
- z-index:19891014
-}
-.layui-m-layer * {
- -webkit-box-sizing:content-box;
- -moz-box-sizing:content-box;
- box-sizing:content-box
-}
-.layui-m-layermain,.layui-m-layershade {
- position:fixed;
- left:0;
- top:0;
- width:100%;
- height:100%
-}
-.layui-m-layershade {
- background-color:rgba(0,0,0,.7);
- pointer-events:auto
-}
-.layui-m-layermain {
- display:table;
- pointer-events:none
-}
-.layui-m-layermain .layui-m-layersection {
- display:table-cell;
- vertical-align:middle;
- text-align:center
-}
-.layui-m-layerchild {
- position:relative;
- display:inline-block;
- text-align:left;
- background-color:#fff;
- font-size:2.6vh;
- border-radius:20px;
- box-shadow:0 0 8px rgba(0,0,0,.1);
- pointer-events:auto;
- -webkit-overflow-scrolling:touch;
- -webkit-animation-fill-mode:both;
- animation-fill-mode:both;
- -webkit-animation-duration:.2s;
- animation-duration:.2s
-}
-@-webkit-keyframes layui-m-anim-scale {
- 0% {
- opacity:0;
- -webkit-transform:scale(.5);
- transform:scale(.5)
-}
-100% {
- opacity:1;
- -webkit-transform:scale(1);
- transform:scale(1)
-}
-}@keyframes layui-m-anim-scale {
- 0% {
- opacity:0;
- -webkit-transform:scale(.5);
- transform:scale(.5)
-}
-100% {
- opacity:1;
- -webkit-transform:scale(1);
- transform:scale(1)
-}
-}.layui-m-anim-scale {
- animation-name:layui-m-anim-scale;
- -webkit-animation-name:layui-m-anim-scale
-}
-@-webkit-keyframes layui-m-anim-up {
- 0% {
- opacity:0;
- -webkit-transform:translateY(1600px);
- transform:translateY(1600px)
-}
-100% {
- opacity:1;
- -webkit-transform:translateY(0);
- transform:translateY(0)
-}
-}@keyframes layui-m-anim-up {
- 0% {
- opacity:0;
- -webkit-transform:translateY(1600px);
- transform:translateY(1600px)
-}
-100% {
- opacity:1;
- -webkit-transform:translateY(0);
- transform:translateY(0)
-}
-}.layui-m-anim-up {
- -webkit-animation-name:layui-m-anim-up;
- animation-name:layui-m-anim-up
-}
-.layui-m-layer0 .layui-m-layerchild {
- width:70%
-}
-.layui-m-layer1 .layui-m-layerchild {
- border:none;
- border-radius:0
-}
-.layui-m-layer2 .layui-m-layerchild {
- width:15vh;
- border:none;
- padding:35px 0;
- box-shadow:none;
- color:#fff;
- background-color:rgba(0,0,0,.7)
-}
-.layui-m-layerchild h3 {
- padding:0 5%;
- height:7.5vh;
- line-height:7.5vh;
- font-size:2.8vh;
- font-weight:400;
- border-radius:20px 20px 0 0;
- text-align:center;
- border-bottom:1px solid #E0E0E0
-}
-.layui-m-layerbtn span,.layui-m-layerchild h3 {
- text-overflow:ellipsis;
- overflow:hidden;
- white-space:nowrap
-}
-.layui-m-layercont {
- padding:8% 10%;
- line-height:4vh;
- text-align:center
-}
-.layui-m-layer1 .layui-m-layercont {
- padding:0;
- text-align:left
-}
-.layui-m-layer2 .layui-m-layercont {
- text-align:center;
- padding:0;
- line-height:0
-}
-.layui-m-layer2 .layui-m-layercont i {
- width:3vh;
- height:3vh;
- margin-left:1vh;
- display:inline-block;
- background-color:#fff;
- border-radius:100%;
- -webkit-animation:layui-m-anim-loading 1.4s infinite ease-in-out;
- animation:layui-m-anim-loading 1.4s infinite ease-in-out;
- -webkit-animation-fill-mode:both;
- animation-fill-mode:both
-}
-.layui-m-layerbtn,.layui-m-layerbtn span {
- position:relative;
- text-align:center;
- border-radius:0 0 20px 20px
-}
-.layui-m-layer2 .layui-m-layercont p {
- margin-top:2vh;
- font-size:2.5vh
-}
-@-webkit-keyframes layui-m-anim-loading {
- 0%,100%,80% {
- transform:scale(0);
- -webkit-transform:scale(0)
-}
-40% {
- transform:scale(1);
- -webkit-transform:scale(1)
-}
-}@keyframes layui-m-anim-loading {
- 0%,100%,80% {
- transform:scale(0);
- -webkit-transform:scale(0)
-}
-40% {
- transform:scale(1);
- -webkit-transform:scale(1)
-}
-}.layui-m-layer2 .layui-m-layercont i:first-child {
- margin-left:0;
- -webkit-animation-delay:-.32s;
- animation-delay:-.32s
-}
-.layui-m-layer2 .layui-m-layercont i.layui-m-layerload {
- -webkit-animation-delay:-.16s;
- animation-delay:-.16s
-}
-.layui-m-layer2 .layui-m-layercont>div {
- line-height:3.3vh;
- padding-top:14px;
- margin-bottom:40px;
- font-size:3vh
-}
-.layui-m-layerbtn {
- display:block;
- display:-moz-box;
- display:-webkit-box;
- width:100%;
- height:7.5vh;
- line-height:7.5vh;
- font-size:0;
- border-top:1px solid #ddd;
- background-color:#FFF
-}
-.layui-m-layerbtn span {
- display:block;
- -moz-box-flex:1;
- box-flex:1;
- -webkit-box-flex:1;
- font-size:2.8vh;
- cursor:pointer;
- color:#0084ff
-}
-.layui-m-layerbtn span[yes] {
- border-radius:0 0 20px
-}
-.layui-m-layerbtn span[no] {
- border-right:1px solid #ddd;
- border-radius:0 0 0 20px
-}
-.layui-m-layerbtn span:active {
- background-color:#F6F6F6
-}
-.layui-m-layerend {
- position:absolute;
- right:14px;
- top:20px;
- width:60px;
- height:60px;
- border:0;
- font-weight:400;
- background:0 0;
- cursor:pointer;
- -webkit-appearance:none;
- font-size:6vh
-}
-.layui-m-layerend::after,.layui-m-layerend::before {
- position:absolute;
- left:10px;
- top:30px;
- content:'';
- width:18px;
- height:1px;
- background-color:#999;
- transform:rotate(45deg);
- -webkit-transform:rotate(45deg);
- border-radius:12px
-}
-.layui-m-layerend::after {
- transform:rotate(-45deg);
- -webkit-transform:rotate(-45deg)
-}
-body .layui-m-layer .layui-m-layer-footer {
- position:fixed;
- width:95%;
- max-width:100%;
- margin:0 auto;
- left:0;
- right:0;
- bottom:20px;
- background:0 0
-}
-.layui-m-layer-footer .layui-m-layercont {
- padding:20px;
- border-radius:20px 20px 0 0;
- background-color:rgba(255,255,255,.8)
-}
-.layui-m-layer-footer .layui-m-layerbtn {
- display:block;
- height:auto;
- background:0 0;
- border-top:none
-}
-.layui-m-layer-footer .layui-m-layerbtn span {
- background-color:rgba(255,255,255,.8)
-}
-.layui-m-layer-footer .layui-m-layerbtn span[no] {
- color:#FD482C;
- border-top:1px solid #c2c2c2;
- border-radius:0 0 20px 20px
-}
-.layui-m-layer-footer .layui-m-layerbtn span[yes] {
- margin-top:20px;
- border-radius:20px
-}
-body .layui-m-layer .layui-m-layer-msg {
- width:auto;
- max-width:90%;
- margin:0 auto;
- background-color:rgba(0,0,0,.7);
- color:#fff
-}
-.layui-m-layer-msg .layui-m-layercont {
- padding:20px 40px;
- font-size:2.8vh
-}
-/*html, body {
- padding: 0;
- margin: 0;
- width: 100%;
- height: 100%;
- cursor: none;
-}
-canvas {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
-}*/
-/*span {
- color: red;
- bottom: 0px;
- position: absolute;
- right: 0px;
- display: none;
- font-size: 40pt;
- font-weight: bold;
- text-align: right;
- vertical-align: bottom;
- font-family: monospace;
- display:none;
-}*/
-.background-div{
- position: fixed;
- background-color: #000;
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
-}
-.info-mask {
- position: absolute;
- top: 0;
- left: 0;
- width: 110vw;
- height: 250vw;
- background-color: #000;
- overflow-x: hidden;
- overflow-y: auto;
- background-image:url(../resources/invite-mask.jpg);
- background-repeat:no-repeat;
- background-size: 100%
-}
-#mask-img {
- width: 100%;
- height: 100%;
- opacity: 0;
-}
-.container::-webkit-scrollbar {
- display: none;
-}
-.real .dire-ctrl {
- background-image:url(../resources/rocker.png);
-}
-
-.real .dc-centre {
- display: none;
-}
-.real .dc-dire {
- background-image:url(../resources/direct-shadow.png);
-}
-
-.real .direct-wrap {
- display: grid;
-}
-.direct-btn {
-}
-.real .key-btn {
- opacity:1!important;
- background-image:url(../resources/button.png)!important;
-}
-
-.real .flat-btn {
- background-image:url(../resources/flat-button.png)!important;;
- opacity:.7!important;;
- width:150px!important;
-}
-.real .kay-SE {
- top:100px!important;
-}
-.real .kay-ST {
- right:60px!important;;
-}
-.hidden {
- display: none!important;
-}
-.menu-back {
- background-color: #000;
- opacity: 0.5;
- position: absolute;
- left: 0;
- top: 0;
- bottom: 0;
- right:0;
- display: none;
-}
-.menu-container {
- background-color: white;
- width: 100vw;
- height: 60vw;
- position: absolute;
- left: 50%;
- top: 50%;
- margin-left: -50vw;
- margin-top: -30vw;
- transform: rotate(90deg);
- display: flex;
- flex-direction: column;
- border-radius: 10px;
-}
-.menu-container .menu-title {
- height: 80px;
- padding: 10px 30px;
- display: flex;
- align-items: center;
- color: #777;
-}
-.menu-container .menu-body {
- flex: 1;
- padding: 10px;
-}
-.menu-body .row {
- margin-left: 5px;
- margin-right: 5px;
- padding: 15px;
- margin-bottom: 5px;
- display: flex;
-}
-.menu-body .row .row-title {
- width: 30%;
- color: #777;
-}
-.menu-body .row .row-body {
- flex: 1;
- display: flex;
-}
-.row-body .row-part{
- width: 50%;
-}
-.row-part input[type='radio']{
- width: 30px;
- height: 30px;
- margin-right: 10px;
-}
-.menu-container .menu-footer {
- height: 80px;
- display: flex;
-}
-.menu-container .menu-footer .left-part {
- flex:1;
-}
-.menu-container .menu-footer .right-part {
- display: flex;
- padding: 5px 20px;
-}
-.menu-container .menu-footer .menu-btn {
- width: 100px;
- height: 50px;
- text-align: center;
- border: 1px solid #ddd;
- margin-right: 10px;
- padding: 4px 10px;
- border-radius: 4px;
-}
-.menu-btn.btn-success{
- color: #fff;
- background-color: #449d44;
- border-color: #398439;
-}
-#menu_btn{
- top: 120px;
- right: 60px;
- width: 120px;
- height: 80px;
- font-size: 30px;
- line-height: 80px;
- text-align: center;
- transform: rotate(90deg);
- font-weight: 700;
- color: rgba(255,255,255,.5);
- opacity: .5;
- position: absolute;
- background-size: 100% 100%;
- background-image: url(../resources/8.png);
- z-index: 10;
-}
-#menu_btn.real{
- background-image: url(../resources/flat-button.png);
-}
diff --git a/fc/index.html b/fc/index.html
deleted file mode 100644
index 69d0a8a..0000000
--- a/fc/index.html
+++ /dev/null
@@ -1,97 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
A
-
B
-
-
-
AB
-
选择
-
开始
-
-
-
-
-
-
-
-
-
diff --git a/fc/js/NetWorkHandle.js b/fc/js/NetWorkHandle.js
deleted file mode 100644
index f0f15e9..0000000
--- a/fc/js/NetWorkHandle.js
+++ /dev/null
@@ -1,63 +0,0 @@
-NetEnum = {
- STARTGAME:1,
- ENTERGAME:2,
- CHANGECLOTH:3,
- JUMP:100,
- USEITEM:101,
- ENDITEM:102,
- STARTMATCH:103,
- SETROBOT:104,
-}
-
- nwh = function(){
- this.functionarr=[];
- var self = this;
- this.process=function(msg){
- var data = JSON.parse(msg.content);
- data.uid = msg.srcUserId;
- this.functionarr[data.m](data)
- };
- this.processFrame =function(msg){
- for(var i=0;i
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-/**
- * @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 = littleEndian;
-
- /**
- * 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;
-});
diff --git a/fc/js/jcfw/httpcli.js b/fc/js/jcfw/httpcli.js
deleted file mode 100644
index 616bcbb..0000000
--- a/fc/js/jcfw/httpcli.js
+++ /dev/null
@@ -1,206 +0,0 @@
-
-
-var httpcli = function(){
- // LIFE-CYCLE CALLBACKS:
-
- // onLoad () {},
-
- // start () {},
-
- // update (dt) {},
-
- this.init=function(){
- this.cachemsg = [];
- this._needretry = false;
- this._retrycount = 3;
- this._retryms = 3000;
- this._runningcount = 0;
- this._maxrunning = 10;
- // this._retry_tid = setInterval(this._retry.bind(this), this._retryms);
- };
-
- this.httpGet=function(url, cbRes, cbErr){
- // var realurl = url;
- // if(urldata){
- // if(realurl.indexOf("?") == -1){
- // realurl += "?";
- // }else{
- // realurl += "&";
- // }
- // realurl += encodeURIComponent(urldata);
- // }
- return this.httpsend(url, null, cbRes, cbErr, 'GET');
- };
-
- this.httpPost=function(url, postdata, cbRes, cbErr){
- return this.httpsend(url, postdata, cbRes, cbErr, 'POST');
- };
-
- this.httpsend=function(url, urldata, cbRes, cbErr, smethod, isretry){
- if(this._runningcount < this._maxrunning){
- return this._httpsend(url, urldata, cbRes, cbErr, smethod, isretry);
- }else if(!isretry){
- let obj = {
- u: url,
- v: urldata,
- successcb: cbRes,
- errcb: cbErr
- };
- this.cachemsg.push(obj);
- return null;
- }
- };
-
- this._httpsend=function(url, urldata, cbRes, cbErr, smethod, isretry){
- this._runningcount++;
- let self = this;
- if(typeof(XMLHttpRequest) != 'undefined'){
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4){
- self._runningcount--;
- if(xhr.status >= 200 && xhr.status < 400) {
- var response = xhr.responseText;
- cbRes && cbRes(response);
- }else{
- if(!isretry && self._needretry){
- let obj = {
- u: url,
- v: urldata,
- successcb: cbRes,
- errcb: cbErr
- };
- self.cachemsg.push(obj);
- }else{
- cbErr && cbErr(xhr.status, xhr.statusText);
- }
- }
- }
- };
- // xhr.onabort = function(){
- // self._runningcount--;
- // };
- xhr.onerror = function(){
- self._runningcount--;
- };
- xhr.open(smethod, url, true);
- xhr.send(urldata);
- return xhr;
- }else if(typeof(wx) != 'undefined'){
- var jsobj = urldata? JSON.parse(urldata): null;
- var xhr = wx.request({
- url: url,
- data: jsobj,
- method: smethod,
- success: function(res){
- console.log("[wx]request success!" + res.statusCode);
- if(res.statusCode >= 200 && res.statusCode < 400) {
- var restext = JSON.stringify(res.data);
- cbRes && cbRes(restext);
- }else{
- cbErr && cbErr(res.statusCode, res.msg);
- }
- },
- fail: function(res){
- console.log("[wx]request fail!"+ JSON.stringify(res));
- if(!isretry && self._needretry){
- let obj = {
- u: url,
- v: urldata,
- successcb: cbRes,
- errcb: cbErr
- };
- self.cachemsg.push(obj);
- }else{
- cbErr && cbErr(-1, res.msg);
- }
- // cbErr && cbErr(-1, res.msg);
- },
- complete: function(){
- self._runningcount--;
- console.log("[wx]request complete!");
- }
- });
- return xhr;
- }
- return null;
- };
-
- this._retry=function(){
- if(this.cachemsg.length > 0){
- this.cachemsg.forEach(element => {
- let obj = element;
- if(obj.retrying){
- return;
- }
- let bneedretry = false;
- if(!obj.retry_count){
- obj.retry_count = 1;
- obj.passtime = 0;
- }
- obj.passtime += this._retryms;
- bneedretry = (obj.passtime >= obj.retry_count * this._retryms);
-
- if(bneedretry && !obj.retrying){
- obj.retrying = true;
- let method = obj.v? 'POST': 'GET';
- this.httpsend(obj.u, obj.v, (restext) => {
- obj.successcb && obj.successcb(restext);
- let idx = this.cachemsg.findIndex((element) => {
- return element == obj;
- });
- if(idx != -1){
- this.cachemsg.splice(idx, 1);
- }
- }, (errcode, errmsg) => {
- obj.retrying = false;
- obj.passtime = 0;
- obj.retry_count++;
- if(obj.retry_count >= this._retrycount){
- obj.errcb && obj.errcb(errcode, errmsg);
- let idx = this.cachemsg.findIndex((element) => {
- return element == obj;
- });
- if(idx != -1){
- this.cachemsg.splice(idx, 1);
- }
- }
- }, method, true);
- }
-
- });
- }
- };
-
- this.setRetryCount=function(count){
- this.retrycount = count;
- };
-
- this.setRetryInterval=function(millsec){
- if(millsec != this._retryms){
- this._retryms = millsec;
- if(this._retry_tid){
- clearInterval(this._retry_tid);
- this._retry_tid = 0;
- }
- }
- if(!this._retry_tid){
- this._retry_tid = setInterval(this._retry.bind(this), this._retryms);
- }
- };
-
- this.setNeedRetry=function(needretry){
- this._needretry = needretry;
- // if(!this._needretry && this._retry_tid){
- // clearInterval(this._retry_tid);
- // this._retry_tid = 0;
- // }else if(this._needretry && !this._retry_tid){
- // this._retry_tid = setInterval(this._retry.bind(this), this._retryms);
- // }
- }
-};
-
-
-require.register('httpcli', function(module, exports, require) {
- module.exports = httpcli;
-});
diff --git a/fc/js/jcfw/httpclient.js b/fc/js/jcfw/httpclient.js
deleted file mode 100644
index c62cfe9..0000000
--- a/fc/js/jcfw/httpclient.js
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-var httpcli = require('httpcli');
-require.register('common/httpclient', function(module, exports, require) {
-module.exports = {
- // LIFE-CYCLE CALLBACKS:
-
- // onLoad () {},
-
- // start () {},
-
- // update (dt) {},
- getInstance(){
- if(!this._instance){
- this._instance = new httpcli();
- this._instance.init();
- this._instance.setRetryInterval(3000);
- this._instance.setNeedRetry(true);
- }
- return this._instance;
- },
-
- httpGet(url, cbRes, cbErr){
- // var realurl = url;
- // if(urldata){
- // if(realurl.indexOf("?") == -1){
- // realurl += "?";
- // }else{
- // realurl += "&";
- // }
- // realurl += encodeURIComponent(urldata);
- // }
- return this.httpsend(url, null, cbRes, cbErr, 'GET');
- },
-
- httpPost(url, postdata, cbRes, cbErr){
- return this.httpsend(url, postdata, cbRes, cbErr, 'POST');
- },
-
- httpsend(url, urldata, cbRes, cbErr, smethod){
- return this.getInstance().httpsend(url, urldata, cbRes, cbErr, smethod);
- },
-
- JSON_parse(text){
- try{
- return JSON.parse(text);
- }catch(err){
- console.log(err);
- return null;
- }
- }
-};
-});
diff --git a/fc/js/jcfw/jcgamelog.js b/fc/js/jcfw/jcgamelog.js
deleted file mode 100644
index fb33352..0000000
--- a/fc/js/jcfw/jcgamelog.js
+++ /dev/null
@@ -1,969 +0,0 @@
-
-
-var httpclient = require('common/httpclient');
-var urlbuilder = require('common/urlbuilder');
-
-const JC_LOG_T = {
- lauch:{
- key: 1,
- subkey: 1,
- },
-
- entermain:{
- key: 1,
- subkey: 2,
- },
-
- show:{
- key: 1,
- subkey: 3
- },
-
- hide:{
- key: 1,
- subkey: 3
- },
-
- jumpapp:{
- key: 1,
- subkey: 4
- },
-
- loginFailed:{
- key: 1,
- subkey: 5
- },
-
- launchsysteminfo:{
- key: 1,
- subkey: 6
- },
-
- logined:{
- key: 11,
- subkey: 1
- },
-
- authed:{
- key: 11,
- subkey: 2
- },
-
- authfail:{
- key: 11,
- subkey: 3
- },
-
- startgame:{
- key: 11,
- subkey: 4
- },
-
- restartgame:{
- key: 11,
- subkey: 4
- },
-
- gameover:{
- key: 11,
- subkey: 6
- },
-
- againgame:{
- key: 11,
- subkey: 4
- },
-
- productitem:{
- key: 11,
- subkey: 8
- },
-
- useitem:{
- key: 11,
- subkey: 9
- },
-
- share:{
- key: 11,
- subkey: 10
- },
-
- inviter:{
- key: 11,
- subkey: 11
- },
-
- systeminfo:{
- key: 11,
- subkey: 20
- },
-
- advinfo:{
- key: 11,
- subkey: 21
- },
-
- vslogin:{
- key: 11,
- subkey: 24
- },
-
- vsreconnect:{
- key: 11,
- subkey: 25
- },
-
- vsroomcreate:{
- key: 11,
- subkey: 26
- },
-
- vsroomjoin:{
- key: 11,
- subkey: 27
- },
-
- vsroomleave:{
- key: 11,
- subkey: 28
- },
-
- vsroomsetstate:{
- key: 11,
- subkey: 29
- },
-
- business:{
- key: 11,
- subkey: 30
- },
-
- buttonclick:{
- key: 11,
- subkey: 31
- },
-
- msgevent:{
- key: 11,
- subkey: 32
- }
-};
-
-const _SHOW_FLAG = 2;
-const _HIDE_FLAG = 1;
-
-const _ONLINE_KEY = 'jc_online_flags';
-
-// 说明:带下划线的函数是内部函数,无需关心
-
-const jcgamelog = {
- // LIFE-CYCLE CALLBACKS:
-
- // onLoad () {},
-
- // start () {},
-
- // update (dt) {},
- __uuid(len, radix) {
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
- var uuid = [], i;
- radix = radix || chars.length;
-
- if (len) {
- // Compact form
- for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
- } else {
- // rfc4122, version 4 form
- var r;
-
- // rfc4122 requires these characters
- uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
- uuid[14] = '4';
-
- // Fill in random data. At i==19 set the high bits of clock sequence as
- // per rfc4122, sec. 4.1.5
- for (i = 0; i < 36; i++) {
- if (!uuid[i]) {
- r = 0 | Math.random() * 16;
- uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
- }
- }
- }
-
- return uuid.join('');
- },
-
- _buildReportUrl(typeobj){
- this.urlbd.clear();
- this.urlbd.addKV('c', 'GameLog')
- .addKV('a', 'reportLog')
- .addKV('gameid', this.gameid)
- .addKV('channel', this.channelid)
- .addKV('account_id', this.accountid)
- .addKV('session_id', this.sessionid)
- .addKV('access_token', this.token)
- .addKV('wid', this.wid)
- .addKV('sid', this.sid)
- .addKV('ptid', this.ptid)
- .addKV('logclass1', typeobj.key)
- .addKV('logclass2', typeobj.subkey)
- .addKV('localuuid', this.localid)
- .addKV('from_appid', this.fromid)
- ;
- //console.log("[gamelog]");
- //console.log(JSON.stringify(typeobj));
- return this.urlbd.baseurl;
- },
-
- _buildReportUserUrl(){
- this.urlbd.clear();
- this.urlbd.addKV('c', 'GameLog')
- .addKV('a', 'reportUser')
- .addKV('gameid', this.gameid)
- .addKV('channel', this.channelid)
- .addKV('account_id', this.accountid)
- .addKV('session_id', this.sessionid)
- .addKV('access_token', this.token)
- ;
- return this.urlbd.baseurl;
- },
-
- _buildShowHideMsg(showflag){
- let data = {
- str1: this.localid,
- str2: this.fromid,
- str3: this.accountid,
- str4: this.nickName,
- num1: showflag,
- num2: -1
- };
-
- let msg = {
- u: this._buildReportUrl(showflag == _SHOW_FLAG? JC_LOG_T.show: JC_LOG_T.hide),
- v: JSON.stringify(data),
- ext: showflag
- };
-
- return msg;
- },
-
- _report(typeobj, valueobj, successcb, failcb){
- let url = this._buildReportUrl(typeobj);
- let value = JSON.stringify(valueobj);
- var self = this;
- httpclient.httpPost(url, value, function(restext){
- let obj = httpclient.JSON_parse(restext);
- if(obj.errcode == 0){
- //console.log('[_report]success!'+JSON.stringify(obj));
- successcb && successcb();
- }else{
- //console.log('[_report]'+url);
- //console.log('[_report]failed!'+obj.errcode+":"+obj.errmsg);
- failcb && failcb(0, obj.errcode, obj.errmsg);
- }
- }, function(errcode, errmsg){
- //console.log('[_report]'+url);
- //console.log('[_report]failed!'+errcode+":"+errmsg);
- failcb && failcb(errcode, 0, errmsg);
- let nflag = -1;
- if(typeobj.key == JC_LOG_T.show.key && typeobj.subkey == JC_LOG_T.show.subkey){
- nflag = valueobj.num1;
- }
- let msg = {
- u: url,
- v: value,
- ext: nflag
- }
- self.cachemsg.push(msg);
- });
- },
-
- _reportUser(valueobj, successcb, failcb){
- let url = this._buildReportUserUrl();
- let value = JSON.stringify(valueobj);
- var self = this;
- httpclient.httpPost(url, value, function(restext){
- let obj = httpclient.JSON_parse(restext);
- if(obj.errcode == 0){
- //console.log('[_reportUser]success!'+JSON.stringify(obj));
- successcb && successcb();
- }else{
- //console.log('[_reportUser]failed!'+obj.errcode+":"+obj.errmsg);
- failcb && failcb(0, obj.errcode, obj.errmsg);
- }
- }, function(errcode, errmsg){
- //console.log('[_reportUser]failed!'+errcode+":"+errmsg);
- failcb && failcb(errcode, 0, errmsg);
- let nflag = -1;
- let msg = {
- u: url,
- v: value,
- ext: nflag
- }
- self.cachemsg.push(msg);
- });
- },
-
- _retry(){
- if(this.cachemsg.length > 0){
- let obj = this.cachemsg[0];
- var self = this;
- httpclient.httpPost(obj.u, obj.v, function(restext){
- if(obj.ext >= 0){
- self.showflag = obj.ext;
- self._saveflag(self.showflag);
- }
- self.cachemsg.shift();
- }, function(errcode, errmsg){
- //console.log('[_retry_report]failed!'+errcode+":"+errmsg);
- });
- }
- },
-
- _saveflag(showflag){
- },
-
- _loadflag(){
- },
-
- _handlelaunch(res){
- if(res){
- if(res.query && res.query.weixinadinfo){
- let wxaddr = res.query.weixinadinfo.split('.');
- let ad = wxaddr[0];
- if(ad && ad != ''){
- this.fromadvid = ad;
- }
- }
- this.launchparam = res.query;
- if(res.referrerInfo && res.referrerInfo.appId){
- this.setFromAppID(res.referrerInfo.appId);
- this.launchparam = res.referrerInfo.extraData;
- }else if(res.query && res.query.scene){
- this.setFromAppID(res.query.scene);
- }
- this.scene = res.scene? res.scene: 0;
- }
- },
-
- _handleLoginInfo(res){
- if(res.account_id && res.session_id){
- this.setAccountID(res.account_id, res.session_id);
- }
- if(res && res.nickname && res.nickname != ''){
- this.setNickName(res.nickname);
- }
- },
-
- _handleAuthInfo(res){
- if(res && res.nickname && res.nickname != ''){
- this.setNickName(res.nickname);
- }
- },
-
- //【通用函数】生成本地匿名ID
- generateUUID(){
- return this.__uuid(32, 62);
- },
-
- // 初始化(上报前必须调用此函数)【使用jcfw.init的话此函数无需手动调用】
- init(channelid, gameid, isoffical, owner, url){
- this.gameid = gameid;
- this.channelid = channelid;
- this.accountid = this.accountid? this.accountid: '';
- this.sessionid = this.sessionid? this.sessionid: '';
- this.token = this.token? this.token: '';
- this.localid = this.localid? this.localid: '';
- this.nickname = this.nickname? this.nickname: '';
- this.fromid = this.fromid? this.fromid: '';
- this.fromadvid = this.fromadvid? this.fromadvid: '';
- this.scene = this.scene? this.scene: 0;
- this._tempuuid = '';
- this._starttime = 0;
- this._launchtime = 0;
- this.needsubmit = false;
- this.urlbd = new urlbuilder(url);
- this.showflag = this._loadflag();
- this.cachemsg = [];
- if(this.showflag == _SHOW_FLAG){
- this.cachemsg.push(this._buildShowHideMsg(this.showflag));
- }
- this.showflag = null;
- setInterval(this._retry.bind(this), 5000);
- //console.log("[jcgamelog]init:"+gameid + "|" + channelid + "|" + isoffical);
- },
-
- // 【暂未使用】
- setSubmitFlag(bsubmit){
- this.needsubmit = bsubmit;
- },
-
- // 登陆成功后调用,传入accountid和sessionid【使用jcfw.login的话此函数无需手动调用】
- setAccountID(accountid, sessionid, exobj){
- if(!this.accountid || this.accountid != accountid){
- this.accountid = accountid;
- }
- if(!this.sessionid || this.sessionid != sessionid){
- this.sessionid = sessionid;
- }
- if(exobj){
- this.wid = exobj.wid;
- this.sid = exobj.sid;
- this.ptid = exobj.ptid;
- }
- },
-
- // 设置昵称【无需手动调用】
- setNickName(nickname){
- if(!this.nickname || this.nickname != nickname){
- this.nickname = nickname;
- }
- },
-
- // 设置本app从哪个appid跳转过来的【使用jcfw.init的话此函数无需手动调用】
- setFromAppID(appid){
- if(!this.fromid || this.fromid != appid){
- this.fromid = appid;
- }
- },
-
- // 设置本地匿名ID(本地生成匿名id后调用)【使用jcfw.init的话此函数无需手动调用】
- setLocalUUID(uuid){
- if(!this.localid || this.localid != uuid){
- this.localid = uuid;
- }
- },
-
- setSystemInfo(info){
-
- },
-
- // 【暂未使用】
- setToken(token){
- this.token = token;
- },
-
- handlelaunch(res, cb){
- this._launchtime = new Date().getTime();
- var param = 0;
- var uid = '';
- var stype = 0;
- var invid = '';
- if(res){
- this._handlelaunch(res);
- param = res.query.activity_param? res.query.activity_param: 0;
- uid = res.query.localuuid? res.query.localuuid: '';
- stype = res.query.sharetype? res.query.sharetype: 0;
- invid = res.query.inviter_id? res.query.inviter_id: '';
- }
- this.logLauchDefault(res);
- cb && cb(stype, param, uid, invid, this.fromid, this.scene, this.launchparam);
- },
-
- //////////////////统计函数////////////////////
- // 启动游戏--------游戏启动后上报【使用jcfw.init的话此函数无需手动调用】
- logLaunch(launch_option){
- this._launchtime = new Date().getTime();
- this._handlelaunch(launch_option);
- this.logLauchDefault(launch_option);
- },
-
- //启动游戏(内部调用)
- logLauchDefault(launch_option){
- let data = {
- str1: this.localid,
- str2: this.fromid,
- ext: launch_option? JSON.stringify(launch_option): null,
- str3: this.fromadvid,
- num1: this.scene
- }
- this._report(JC_LOG_T.lauch, data);
- },
-
- // 登陆成功--------游戏登陆成功后上报【使用jcfw.login的话此函数无需手动调用】
- logLoginSuccess(res, costtime){
- let nowtime = new Date().getTime();
- let dttime = nowtime - this._launchtime;
- this._handleLoginInfo(res);
- let data = {
- str1: res.nickname,
- str2: res.unionid,
- str3: res.country,
- str4: res.province,
- str5: res.city,
- str6: this.localid,
- num1: costtime? costtime: 0,
- num2: dttime,
- str7: this.fromadvid
- }
- //console.log('[launchcost]'+dttime);
- this._report(JC_LOG_T.logined, data);
- },
-
- // 登陆失败---------游戏登陆失败后上报【使用jcfw.login的话此函数无需手动调用】
- logLoginFailed(neterr, logicerr, errmsg){
- let data = {
- error_code_net: neterr,
- error_code_logic: logicerr,
- error_msg: errmsg
- };
- this._report(JC_LOG_T.loginFailed, data);
- },
-
- // 授权成功--------微信获取userinfo后上报【使用jcfw.login的话此函数无需手动调用】
- logAuthSuccess(res){
- this._handleAuthInfo(res);
- let data = {
- str1: res.nickName,
- num1: res.gender,
- str3: res.country,
- str4: res.province,
- str5: res.city,
- str6: this.localid,
- str7: res.avatarUrl? res.avatarUrl: '',
- str8: res.language
- }
- this._report(JC_LOG_T.authed, data);
- },
-
- // 授权失败--------微信获取userinfo时,用户拒绝授权后上报【使用jcfw.login的话此函数无需手动调用】
- logAuthFail(){
- let data = {
- str1: this.nickName,
- str2: this.localid
- }
- this._report(JC_LOG_T.authfail, data);
- },
-
- // 分享---------------用户分享时上报【使用jcfw.shareNormal/shareCapture的话此函数无需手动调用】
- logShare(businessid, sharetokenid, param){
- let data = {
- str1: this.nickname,
- str2: sharetokenid? sharetokenid: '',
- num1: businessid,
- str3: param? param: ''
- }
- this._report(JC_LOG_T.share, data);
- },
-
- // 分享点击-------------当用户点击别人分享的卡片进入游戏时上报【使用jcfw.login的话此函数无需手动调用】
- logShareInvite(inviterid, businessid, sharetokenid, param){
- let data = {
- str1: this.nickName,
- str2: inviterid,
- num1: businessid,
- str3: sharetokenid? sharetokenid: sharetokenid,
- str4: param? param: ''
- }
- this._report(JC_LOG_T.inviter, data);
- },
-
- // 系统信息-------------获取用户系统信息后上报【使用jcfw.init的话此函数无需手动调用】
- logSysInfo(res, typeobj){
- let data = {
- str1: res.brand,
- str2: res.model,
- str3: res.language,
- str4: res.version,
- str5: res.platform,
- str6: res.SDKVersion,
- str7: res.system,
- num1: res.pixelRatio,
- num2: res.screenWidth,
- num3: res.screenHeight,
- num4: res.windowWidth,
- num5: res.windowHeight,
- num6: res.benchmarkLevel
- // ext: JSON.stringify(res)
- };
- this._report(typeobj, data);
- },
-
- logSystemInfo(res){
- if(!res){
- return;
- }
- this.logSysInfo(res, JC_LOG_T.systeminfo);
- },
-
- logLaunchSystemInfo(res){
- if(!res){
- return;
- }
- this.logSysInfo(res, JC_LOG_T.launchsysteminfo);
- },
-
- // 开始游戏---------开始一局游戏时上报【使用jcfw.gameStart的话此函数无需手动调用】
- logStartGame(param, startmode){
- this._tempuuid = this.generateUUID();
- this._starttime = new Date().getTime();
- let data = {
- str1: this.fromid,
- str2: this._tempuuid,
- str3: param? param: '',
- str4: this.nickname,
- str5: this.localid,
- num1: startmode? startmode: 0
- }
- this._report(JC_LOG_T.startgame, data);
- },
-
- // 重新开始游戏---------重新开始一局游戏时上报【使用jcfw.gameStart的话此函数无需手动调用】
- logRestartGame(param){
- this._tempuuid = this.generateUUID();
- this._starttime = new Date().getTime();
- let data = {
- str1: this.fromid,
- str2: this._tempuuid,
- str3: param? param: '',
- str4: this.nickname,
- str5: this.localid,
- num1: 1
- }
- this._report(JC_LOG_T.restartgame, data);
- },
-
- // 上报游戏还活着
- logGameAlive(param){
- //this._tempuuid = this.generateUUID();
- this._starttime = new Date().getTime();
- let data = {
- str1: this.fromid,
- str2: this._tempuuid,
- str3: param? param: '',
- str4: this.nickname,
- str5: this.localid,
- num1: 3
- }
- this._report(JC_LOG_T.restartgame, data);
- },
-
- // 游戏结束---------本局游戏结束时上报【使用jcfw.gameOver的话此函数无需手动调用】
- logGameover(param, score, endflag){
- let nowtime = new Date().getTime();
- let data = {
- str1: this.fromid,
- str2: this._tempuuid,
- str3: param? param: '',
- num1: score,
- str4: this.nickname,
- str5: this.localid,
- num2: nowtime - this._starttime,
- num3: endflag? endflag: 0
- }
- this._report(JC_LOG_T.gameover, data);
- },
-
- // 再来一次----------再来一次时上报【使用jcfw.gameStart的话此函数无需手动调用】
- logTryAgain(param){
- this._tempuuid = this.generateUUID();
- let data = {
- str1: this.fromid,
- str2: this._tempuuid,
- str3: param? param: '',
- str4: this.nickname,
- str5: this.localid,
- num1: 2
- }
- this._report(JC_LOG_T.againgame, data);
- },
-
- // 显示-----------------------app显示时上报(eg:wx.onShow)【使用jcfw.gameShow的话此函数无需手动调用】
- logShow(bIgnoreFlag){
- if(!bIgnoreFlag){
- let bok = !this.showflag || this.showflag == _HIDE_FLAG;
- if(!bok){
- return;
- }
- this.showflag = _SHOW_FLAG;
- }
-
- let nowtime = new Date().getTime();
- let data = {
- str1: this.localid,
- str2: this.fromid,
- str3: this.accountid,
- str4: this.nickName,
- num1: _SHOW_FLAG,
- num2: nowtime - this._launchtime
- };
- this._report(JC_LOG_T.show, data, ()=>{
- if(!bIgnoreFlag){
- this._saveflag(this.showflag);
- }
- }, () => {
- });
- },
-
- // 隐藏-----------------------app隐藏时上报(eg:wx.onHide)【使用jcfw.gameHide的话此函数无需手动调用】
- logHide(bIgnoreFlag){
- if(!bIgnoreFlag){
- let bok = this.showflag && this.showflag == _SHOW_FLAG;
- if(!bok){
- return;
- }
- this.showflag = _HIDE_FLAG;
- }
- let nowtime = new Date().getTime();
- let data = {
- str1: this.localid,
- str2: this.fromid,
- str3: this.accountid,
- str4: this.nickName,
- num1: _HIDE_FLAG,
- num2: nowtime - this._launchtime
- };
- this._report(JC_LOG_T.hide, data, ()=>{
- if(!bIgnoreFlag){
- this._saveflag(this.showflag);
- }
- }, () => {
- });
- },
-
- // 产出道具----------道具产出时上报【使用jcfw.gameGetItem的话此函数无需手动调用】
- logProductItem(itemid, itemcount, reson, resonparam){
- let data = {
- str1: this.nickname,
- num1: itemid,
- num2: itemcount,
- num3: reson,
- num4: resonparam
- }
- this._report(JC_LOG_T.productitem, data);
- },
-
- // 使用道具----------使用道具时上报【使用jcfw.gameUseItem的话此函数无需手动调用】
- logUseItem(itemid, itemcount, reson, resonparam){
- let data = {
- str1: this.nickname,
- num1: itemid,
- num2: itemcount,
- num3: reson,
- num4: resonparam
- }
- this._report(JC_LOG_T.useitem, data);
- },
-
- // 运营活动上报---------------开始运营活动时上报
- logBusiness(businessid, actionid){
- let data = {
- str1: this.nickName,
- str2: this.localid,
- num1: businessid,
- num2: actionid
- };
- this._report(JC_LOG_T.business, data);
- },
-
- // 进入游戏主界面-------------主界面显示时上报
- logEnterMainScene(dt){
- let data = {
- str1: this.localid,
- str2: this.fromid,
- num1: dt? dt: 0
- };
- this._report(JC_LOG_T.entermain, data);
- },
-
- // 跳转到其他app--------------跳转到其他app时上报(eg: wx.navigateMiniProgram)
- logJumpApp(appid, appparam, jumpres){
- let data = {
- str1: this.localid,
- str2: this.fromid,
- str3: this.accountid,
- str4: this.nickName,
- str5: appid,
- str6: appparam,
- num1: jumpres? jumpres: 0
- };
- this._report(JC_LOG_T.jumpapp, data);
- },
-
- // 广告相关-----------------处理广告时上报(eg: 激励广告出现时)
- logAdvInfo(advid, actiontype, actionparam){
- let data = {
- str1: this.nickname,
- str2: advid,
- num1: actiontype,
- str3: actionparam
- };
- this._report(JC_LOG_T.advinfo, data);
- },
-
- // 【对战开房间】登陆【无需主动调用】
- logVS_login(){
- let data = {
- str1: this.nickName
- };
- this._report(JC_LOG_T.vslogin, data);
- },
-
- // 【对战开房间】重连【无需主动调用】
- logVS_reconnect(roomid){
- let data = {
- str1: this.nickName,
- str2: roomid
- };
- this._report(JC_LOG_T.vsreconnect, data);
- },
-
- // 【对战开房间】创建房间【无需主动调用】
- logVS_createRoom(roomname, maxplayer){
- let data = {
- str1: this.nickname,
- str2: roomname,
- num1: maxplayer
- };
- this._report(JC_LOG_T.vsroomcreate, data);
- },
-
- // 【对战开房间】加入房间【无需主动调用】
- logVS_joinRoom(roomid, customdata, israndom){
- let data = {
- str1: this.nickname,
- str2: roomid? roomid: '',
- num1: israndom? 1: 0,
- str3: customdata
- };
- this._report(JC_LOG_T.vsroomjoin, data);
- },
-
- // 【对战开房间】离开房间【无需主动调用】
- logVS_leaveRoom(roomid, customdata){
- let data = {
- str1: this.nickname,
- str2: roomid,
- str3: customdata
- };
- this._report(JC_LOG_T.vsroomleave, data);
- },
-
- // 【对战开房间】游戏准备【无需主动调用】
- logVS_gameReady(roomid, customdata, isready){
- let data = {
- str1: this.nickname,
- str2: roomid,
- num1: isready? 1: 0,
- str3: customdata
- };
- this._report(JC_LOG_T.vsroomsetstate, data);
- },
-
- // 【对战开房间】游戏开始【无需主动调用】
- logVS_gameStart(roomid, customdata){
- let data = {
- str1: this.nickname,
- str2: roomid,
- num1: 2,
- str3: customdata
- };
- this._report(JC_LOG_T.vsroomsetstate, data);
- },
-
- // 按钮事件----------------点击按钮时上报
- logButtonClick(buttonname, param, buttonsubname){
- let data = {
- nickname: this.nickname,
- button_name: buttonname,
- button_param: param? param: ''
- };
- if(buttonsubname){
- data.button_subname = buttonsubname;
- }
- this._report(JC_LOG_T.buttonclick, data);
- },
-
- logMsg(msgid, msgname, errcode, reqcontent, rspcontent, passtime){
- let data = {
- msg_id: msgid,
- msg_name: msgname,
- msg_error: errcode,
- req_content: reqcontent,
- rsp_content: rspcontent,
- msg_cosumetime: passtime
- };
- this._report(JC_LOG_T.msgevent, data);
- },
-
- // 设置角色属性
- /* 调用示例:角色初始化时
- run(){
- let obj = {
- level: 1,
- money: 10000,
- ...
- };
- jcfw.gamelog.userSet(obj);
- }
- */
- userSet(kvobj){
- let data = {
- set: kvobj
- };
- this._reportUser(data);
- },
-
- // 设置角色属性(仅允许设置一次)
- /* 调用示例:改名时(如果有此功能)
- run(){
- let obj = {
- nickname: "abc"
- };
- jcfw.gamelog.userSet(obj);
- }
- */
- userSetOnce(kvobj){
- let data = {
- set_once: kvobj
- };
- this._reportUser(data);
- },
-
- // 增加/减少角色数值属性
- /* 调用示例:角色升级时
- run(){
- let obj = {
- level: 1
- };
- jcfw.gamelog.userAdd(obj);
- }
- */
- userAdd(kvobj){
- let data = {
- add: kvobj
- };
- this._reportUser(data);
- },
-
- /*可以一次调用set/setonce/add */
- userReport(setobj, setonceobj, addobj){
- let data = {
- set: setobj,
- set_once: setonceobj,
- add: addobj
- };
- this._reportUser(data);
- },
-
- /**
- *
- * @param {number} externalID 外部调用的ID
- * @param {object} logFunc 外部调用的方法
- * @param {string} p1 参数1
- * @param {string} p2 参数2
- * @param {string} p3 参数3
- * @param {string} p4 参数4
- */
- externalLog(externalID, logFunc, p1, p2, p3, p4){
- let tmpid = this.gameid;
- this.gameid = externalID;
- logFunc && logFunc.call(this,p1,p2,p3,p4);
- this.gameid = tmpid;
- }
-};
-
-require.register('jsgamelog', function(module, exports, require) {
- module.exports = jcgamelog;
-});
diff --git a/fc/js/jcfw/urlbuilder.js b/fc/js/jcfw/urlbuilder.js
deleted file mode 100644
index 0736b13..0000000
--- a/fc/js/jcfw/urlbuilder.js
+++ /dev/null
@@ -1,35 +0,0 @@
-require.register('common/urlbuilder', function(module, exports, require) {
- module.exports = function(url){
- this.orginurl = url;
- this.baseurl = url;
- this.checked = false;
- this.addKV=function(key, value){
- if(typeof(value) == 'undefined'){
- return this;
- }
- this._checkurl();
- var str = encodeURIComponent(key) + '=' + encodeURIComponent(value);
- this.baseurl += str;
- return this;
- };
-
- this.clear=function(){
- this.baseurl = this.orginurl;
- this.checked = false;
- };
-
- this._checkurl=function(){
- if(!this.checked){
- if(this.baseurl.indexOf("?") == -1){
- this.baseurl += "?";
- }else{
- this.baseurl += "&";
- }
- this.checked = true;
- }else{
- this.baseurl += "&";
- }
-
- };
-};
-});
diff --git a/fc/js/jcmatchvs.js b/fc/js/jcmatchvs.js
deleted file mode 100644
index 3cf499e..0000000
--- a/fc/js/jcmatchvs.js
+++ /dev/null
@@ -1,1550 +0,0 @@
-
-JCMsgHandler = function(){
-
-
- this.init=function(handler){
- this._handobj = handler;
- this.msglst = [];
- this.deltatime = 0;
- this.delaytime = 500;
- this.rate = 60;
- }
-
-
- this.run=function (dt){
- var self = this;
- this.msglst.forEach(element => {
- element.delaycount--;
- if(element.delaycount <= 0){
- self._handobj && self._handobj.handleData && self._handobj.handleData(element);
- element.handled = true;
- }
- });
-
- var i = this.msglst.length;
- while(i--){
- if(this.msglst[i].handled){
- this.msglst.splice(i,1);
- }
- }
- }
-
- this.pushMsg =function(obj){
- var msg = this.msgclone(obj);
- var subobj = JSON.parse(msg.content);
- var tm = subobj.timestamp + this.deltatime;
- var d = new Date();
- msg.delaycount = Math.ceil((d.getTime() - tm) / this.rate);
- msg.handled = false;
- this.msglst.push(msg);
- }
-
- this.msgclone=function(obj) {
- // Handle the 3 simple types, and null or undefined
- if (null == obj || "object" != typeof obj) return obj;
-
- // Handle Date
- if (obj instanceof Date) {
- var copy = new Date();
- copy.setTime(obj.getTime());
- return copy;
- }
-
- // Handle Array
- if (obj instanceof Array) {
- var copy = [];
- var len = obj.length;
- for (var i = 0; i < len; ++i) {
- copy[i] = this.msgclone(obj[i]);
- }
- return copy;
- }
-
- // Handle Object
- if (obj instanceof Object) {
- var copy = {};
- for (var attr in obj) {
- if (obj.hasOwnProperty(attr)) copy[attr] = this.msgclone(obj[attr]);
- }
- return copy;
- }
-
- throw new Error("Unable to copy obj! Its type isn't supported.");
- }
-
- this.setDeltaTime=function(dt){
- this.deltatime = dt;
- }
-
- this.setFramerate=function(rt){
- this.rate = rt;
- }
-};
-
-
-
-
-
-MsgEnum = function(){
-
- this.c2sMsg = function(){
- return this.msg.CMMessageId_e;
- }
-
- this.s2cMsg = function(){
- return this.msg.SMMessageId_e;
- }
- this.downloadFile=function(fileName, registrationHandler) {
- var ajax = new XMLHttpRequest();
- ajax.onload = registrationHandler;
- ajax.open("GET", "./" + fileName, true);
- ajax.responseType = "text";
- ajax.overrideMimeType("text/plain; charset=x-user-defined");
- ajax.send(null);
- }
-
- this.init=function(cb){
- this.msg = null;
- var protoFile = "./resources/messages.proto";
- this.downloadFile(protoFile, function ( res){
- if(res.target.status===200){
- var Builder = ProtoBuf.protoFromString(res.target.response);
- this.msg = Builder.build("kingsomevs");
- cb && cb();
- }
-
- }.bind(this));
- }
-};
-
-
-MsgObj =function(arrbuf, len){
-
- var handbuf = new Uint8Array(arrbuf);
- this._id = handbuf[2] | ((handbuf[3] << 8) & 0xFF);
- var msgbuf = handbuf.subarray(8, 8+len);
- this.u8buf = new Uint8Array(len);
- this.u8buf.set(msgbuf);
-
- this.id=function(){
- return this._id;
- }
-
- this.data=function(){
- return this.u8buf.buffer;
- }
-
-};
-
-
-const BUFF_SIZE = 1024;
-
-
-
-MsgBuffer =function(){
-
-
- this.init=function(){
- this.BUFF_SZ = BUFF_SIZE;
- this.buffer = new ArrayBuffer(BUFF_SIZE);
- this.handrecvbuf = new Uint8Array(this.buffer);
- this.usedlen = 0;
- }
-
- this.pushData=function(buf){
- if(!buf || !buf.byteLength || buf.byteLength <= 0){
- return;
- }
-
- var len = buf.byteLength;
- while (this.usedlen + len >= this.BUFF_SZ){
- console.log("msgbuffer enlarge *2!" + this.BUFF_SZ + "|" + this.usedlen);
- this.BUFF_SZ *= 2;
-
- var newBuffer = new ArrayBuffer(this.BUFF_SZ);
- if(this.usedlen>0){
- var oldbuf = new Uint8Array(this.buffer);
- var newbuf = new Uint8Array(newBuffer);
- var subold = oldbuf.subarray(this.usedlen);
- newbuf.set(subold);
- }
-
- this.buffer = newBuffer;
- this.handrecvbuf = new Uint8Array(this.buffer);
- }
-
- var subbuf = this.handrecvbuf.subarray(this.usedlen);
- var hbuf = new Uint8Array(buf);
- subbuf.set(hbuf);
-
- this.usedlen += len;
- }
-
- this.hasPackMsg=function(){
- if(this.usedlen < 8){//len(2byte) + id(2byte) + code(4byte)
- return false;
- }
- var handbuf = this.handrecvbuf;
-
- var num = handbuf[0] | ((handbuf[1] << 8));
- if(this.usedlen < num + 8){
- return false;
- }
- return true;
- }
-
- this.popPackMsg=function(){
- var handbuf = this.handrecvbuf;
-
- var num = handbuf[0] | ((handbuf[1] << 8));
- var id = handbuf[2] | ((handbuf[3] << 8));
- var msg = new MsgObj(handbuf.buffer, num);
- // console.log("[popPackMsg]:"+num+","+id);
- //start update param
- var n = num + 8;
- if(this.usedlen > n){
- this.buffer.copyWithin(0, n, this.usedlen);
- }
- this.usedlen -= n;
- return msg;
- }
-
- this.buildPackMsg=function(msgid, arrbuf){
- var len = arrbuf? arrbuf.byteLength: 0;
- var num = len + 8;
- var bytebuf = new Uint8Array(num);
- bytebuf[0] = len > 0? len & 0xFF: 0;
- bytebuf[1] = len > 0? (len >> 8) & 0xFF: 0;
- bytebuf[2] = msgid & 0xFF;
- bytebuf[3] = (msgid >> 8) & 0xFF;
-
- bytebuf[4] = 0xAA;
- bytebuf[5] = 0xCC;
- bytebuf[6] = 0xBB;
- bytebuf[7] = 0xAA;
-
- //var handbuf = new Uint16Array(bytebuf.buffer);
- //handbuf[0] = num;
- //handbuf[1] = msgid;
- //var dwordbuf = new Uint32Array(handbuf.buffer);
- //dwordbuf[1] = 0xFFCCAABB;
- if(arrbuf){
- var oldbuf = new Uint8Array(arrbuf);
- bytebuf.set(oldbuf, 8);
- }
-
- return bytebuf.buffer;
- }
-}
-MessageVo = function(){
- this.update= function (mId, proto, cb) {
- this.msgId = mId;
- this.protoData = proto;
- this.callBack = cb;
- return this;
- }
-};
-
-
-
-Socket = function(callback, hosturl){
- //this._super();
- this._sock = null;
- this._cb = callback;
- this._host = hosturl;
- this._sendqueue = [];
- this._isclosed = false;
- var self = this;
- if(typeof(WebSocket) != 'undefined'){
- //cocos creator websocket
- this._sock = new WebSocket(hosturl);
- this._sock.binaryType = 'arraybuffer';
- this._sock.onmessage = function (event) {
- //console.log("socket on message");
- self._cb.onMessage && self._cb.onMessage(event.data);
- };
- this._sock.onopen = function (event) {
- console.log("Create the socket is success :"+self._host );
- while (self._sendqueue.length > 0) {
- self._sock.send(self._sendqueue.pop());
- }
- self._cb.onOpen && self._cb.onOpen(self._host);
- };
- this._sock.onclose = function (e) {
- self._isclosed = true;
- self._cb.onClose && self._cb.onClose(self._host,e);
- console.log("socket on closed ,code:"+e.code+"(1000:NORMAL,1005:CLOSE_NO_STATUS,1006:RESET,1009:CLOSE_TOO_LARGE) msg:"+e.reason);
- };
- this._sock.onerror = function (event) {
- console.log("socket on error ,event:"+JSON.stringify(event));
- self._cb.onError && self._cb.onError(self._host,event);
- if(!self._isclosed){
- self.close();
- }
- };
-
- }
- this.send=function(msg){
- var n = this._sock.readyState;
- //console.log("sock readyState:" + n);
- if(n == WebSocket.CONNECTING){
- this._sendqueue.push(msg);
- }else if(n == WebSocket.OPEN){
- this._sock.send(msg);
- }else{
- this._sock.onclose({code:-n});
- }
- }
-
- this.close=function(){
- //todo:
- this._sock && this._sock.close();
- }
-}
-
-
-
-
-WS = function(){
- this.url =""
- this.sock = null;
-
-
-
- this.setCallback=function(cb){
- this.cb = cb;
- }
- // LIFE-CYCLE CALLBACKS:
-
- // onLoad () {},
-
- this.start=function () {
-
- }
-
- // update (dt) {},
-
- this.setHost=function(url){
- this.url = url;
- }
-
- this.connect=function(){
- if(this.sock){
- this.sock = null;
- }
- this.sock = new Socket(this, this.url);
- }
-
- this.send=function(msg){
- this.sock && this.sock.send(msg);
- }
-
- this.disconnect=function(){
- this.sock && this.sock.close();
- }
-
- this.onOpen=function(url){
- this.cb && this.cb.onConnect();
- }
-
- this.onClose=function(url, errevent){
- this.cb && this.cb.onClose(errevent);
- }
-
- this.onError=function(url, errevent){
- this.cb && this.cb.onError(errevent);
- }
-
- this.onMessage=function(msg){
- this.cb && this.cb.onRecv(msg);
- }
-}
-
-// var MessageBuffer = require('msgbuffer');
-// var MessageVo = require('messageVo');
-// var WS = require('webclient');
-//var Base64 = require('base64');
-
-MsgManager = function(){
-
- this.init=function() {
- this._sendMsgQueue = {};
- this._recvMsgQueue = {};
- this._ws = new WS();
- this._ws.setCallback(this);
- this._buf = new MsgBuffer();
- this._buf.init();
- this._isconnected = false;
- this._netcb = null;
- }
- this.initSendMsg=function(msgId, proto) {
- var vo = new MessageVo();
- vo.update(msgId, proto, null);
- this._sendMsgQueue[msgId] = vo;
- }
- this.initRecvMsg=function(msgId, proto, callBack) {
- var vo = new MessageVo();
- vo.update(msgId, proto, callBack);
- this._recvMsgQueue[msgId] = vo;
- }
- this.sendMsg=function(msgId, msg) {
-
- var msgVo = this._sendMsgQueue[msgId];
- //console.log(JSON.stringify(msgVo));
- var data = msg? msgVo.protoData.encode(msg).toArrayBuffer():null;
-
- var pkgdata = this._buf.buildPackMsg(msgId, data);
- if(pkgdata && this._ws){
- //console.log(Base64.arrayBufferToBase64(pkgdata));
- //console.log("[sendmsg]:"+msgId + ":" + msg);
- this._ws.send(pkgdata);
- }
-
- }
- this.parseMsg=function(msgId, msgByte) {
- // console.log("信息回调id:" + msgId+ ":"+msgByte);
- var msgVo = this._recvMsgQueue[msgId];
- if(msgVo == undefined){
- console.log("[undefined msg]"+msgId);
- return;
- }
- var msg = msgVo.protoData.decode(msgByte);
- if(msgVo.callBack) {
-
- //统一处理errorcode
- if(msg && msg.errorcode){
- //TODO 统一处理errorcode
- //1:根据errorcode获取对应的文本信息
- //2:提示给用户
-
- }
-
- msgVo.callBack(msg);
- }
- }
-
- this.isConnected=function(){
- return this._isconnected;
- }
-
- this.connectNet= function(host, cb){
- console.log("[connectNet]");
- this._netcb = cb;
- //this._ws.setHost(host);
- this._ws.url = host;
- this._ws.connect();
- }
-
- this.closeNet= function(){
- this._ws.disconnect();
- }
-
- this.onConnect=function(){
- this._isconnected = true;
- if(this._netcb){
- this._netcb("connect", 0);
- }
- }
-
- this.onClose=function(err){
- this._isconnected = false;
- if(this._netcb){
- var n = err.code? err.code: 0;
- this._netcb("close", n);
- }
- }
-
- this.onError=function(err){
- this._isconnected = false;
- if(this._netcb){
- var n = err.code? err.code: 0;
- this._netcb("error", n);
- }
- }
-
- this.onRecv=function(msg){
- // console.log("onrecv");
- this._buf.pushData(msg);
- while(this._buf.hasPackMsg()){
- var msg = this._buf.popPackMsg();
- this.parseMsg(msg.id(), msg.data());
- }
- }
-}
-
-
-
-
-// var MsgMan = require('./net/msgmanager');
-// var MsgIDEnum = require('./net/msgenum');
-// var ProtoBuf = require("./net/proto/protobuf");
-
-// var MsgHandler = require("./jcmsghandler");
-
-const state_enum ={
- none: 0,
- initing: 1,
- inited: 2,
- logining: 3,
- logined: 4,
- loginouting: 5,
- loginouted: 6,
- joining: 7,
- joined: 8,
- leaving: 9,
- leaved: 10,
-};
-
-UserInfo = function(){
-
- this.channelID=""
- this.platForm=""
- this.gameID=""
- this.deviceID=""
- this.userID=""
- this.token=""
- this.roomID=""
- this.init_state=state_enum.none
- this.login_state= state_enum.none
- this.room_state= state_enum.none
-
-};
-
-const url_offical = "wss://matchvs-al.kingsome.cn/websocket";
-
-const url_test = "wss://matchvs-al.kingsome.cn/websocket";//"ws://118.31.73.76:81/websocket";
-
-JCMatchVS = function(){
-
-
- // LIFE-CYCLE CALLBACKS:
-
- this.onLoad =function() {
- this.userinfo = {};
- this.rsp = null;
- this.userinfo = new UserInfo();
- this.reconnectcount = 0;
- this.reconnectmax = 5;
- this.msgctrl = new JCMsgHandler();
- }
-
-
-
- this.run=function(dt){
- this.msgctrl.run(dt);
- }
-
- // update (dt) {},
-
- this.__classCreate=function(){
- this.onLoad();
- if(!this.msgManager){
- this.msgManager = new MsgManager();
- this.msgManager.init();
- }
- if(!this.msgIDs){
- this.msgIDs = new MsgEnum();
- }
- }
-
- this.init=function(response, channel, platform, gameid, deviceid) {
- this.rsp = response;
- this.userinfo.channelID = channel;
- this.userinfo.platForm = platform;
- this.userinfo.gameID = gameid;
- this.userinfo.deviceID = deviceid;
- this.userinfo.init_state = state_enum.initing;
- this.msgIDs.init(function(err){
- this.initMsgHandler(this.msgIDs.c2sMsg(), this.msgIDs.s2cMsg());
- }.bind(this));
- this.msgctrl.init(response);
- }
- this.downloadFile=function(fileName, registrationHandler) {
- var ajax = new XMLHttpRequest();
- ajax.onload = registrationHandler;
- ajax.open("GET", "./" + fileName, true);
- ajax.responseType = "text";
- ajax.overrideMimeType("text/plain; charset=x-user-defined");
- ajax.send(null);
- }
- this.initMsgHandler=function(c2sMsg, s2cMsg){
- var protoFile = "./resources/kingsomevs.proto";
- this.downloadFile(protoFile, function ( res){
-
-
- var Builder = ProtoBuf.protoFromString(res.target.response);
-
- var msg = Builder.build("kingsomevs");
-
- this.msgManager.initSendMsg(c2sMsg._CMLogin, msg.CMLogin);
- this.msgManager.initRecvMsg(s2cMsg._SMLogin, msg.SMLogin, this.onLoginRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMCreateRoom, msg.CMCreateRoom);
- this.msgManager.initRecvMsg(s2cMsg._SMCreateRoom, msg.SMCreateRoom, this.onCreateRoomRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMJoinRandomRoom, msg.CMJoinRandomRoom);
- this.msgManager.initRecvMsg(s2cMsg._SMJoinRandomRoom, msg.SMJoinRandomRoom, this.onJoinRoomRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMJoinRoom, msg.CMJoinRoom);
- this.msgManager.initRecvMsg(s2cMsg._SMJoinRoom, msg.SMJoinRoom, this.onJoinRoomRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMKickPlayer, msg.CMKickPlayer);
- this.msgManager.initRecvMsg(s2cMsg._SMKickPlayer, msg.SMKickPlayer, this.onKickPlayerRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMJoinOver, msg.CMJoinOver);
- this.msgManager.initRecvMsg(s2cMsg._SMJoinOver, msg.SMJoinOver, this.onJoinOverRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMJoinOpen, msg.CMJoinOpen);
- this.msgManager.initRecvMsg(s2cMsg._SMJoinOpen, msg.SMJoinOpen, this.onJoinOpenRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMGameStart, msg.CMGameStart);
- this.msgManager.initRecvMsg(s2cMsg._SMGameStart, msg.SMGameStart, this.onGameStartRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMSendRoomEvent, msg.CMSendRoomEvent);
- this.msgManager.initRecvMsg(s2cMsg._SMSendRoomEvent, msg.SMSendRoomEvent, this.onSendRoomEvtRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMLeaveRoom, msg.CMLeaveRoom);
- this.msgManager.initRecvMsg(s2cMsg._SMLeaveRoom, msg.SMLeaveRoom, this.onLeaveRoomRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMSetFrameSync, msg.CMSetFrameSync);
- this.msgManager.initRecvMsg(s2cMsg.SMSetFrameSync, msg.SMSetFrameSync, this.onSetFrameSyncRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMPing, msg.CMPing);
- this.msgManager.initRecvMsg(s2cMsg._SMPing, msg.SMPing, this.onPing.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMSendFrameEvent, msg.CMSendFrameEvent);
- this.msgManager.initRecvMsg(s2cMsg._SMSendFrameEvent, msg.SMSendFrameEvent, this.onSendFrameEvtRsp.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMReConnect, msg.CMReConnect);
- this.msgManager.initRecvMsg(s2cMsg._SMReConnect, msg.SMReConnect, this.onReConnectRsp.bind(this));
-
- this.msgManager.initRecvMsg(s2cMsg._SMRoomPeerJoinNotify, msg.SMRoomPeerJoinNotify, this.onJoinRoomNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMRoomKickPlayerNotify, msg.SMRoomKickPlayerNotify, this.onKickNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMRoomEventNotify, msg.SMRoomEventNotify, this.onRoomEvtNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMRoomPeerLeaveNotify, msg.SMRoomPeerLeaveNotify, this.onLeaveRoomNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMFrameEventUpdateNotify, msg.SMFrameEventUpdateNotify, this.onFrameUpdateNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMRoomDisbandNotify, msg.SMRoomDisbandNotify, this.onRoomDestoryNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMJoinOverNotify, msg.SMJoinOverNotify, this.onJoinOverNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMJoinOpenNotify, msg.SMJoinOpenNotify, this.onJoinOpenNotify.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMNetWorkStateNotify, msg.SMNetWorkStateNotify, this.onNetWorkStateNotify.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMSetRoomParam, msg.CMSetRoomParam);
- this.msgManager.initRecvMsg(s2cMsg._SMSetRoomParam, msg.SMSetRoomParam, this.onSMSetRoomParam.bind(this));
- this.msgManager.initRecvMsg(s2cMsg._SMRoomMergeNotify, msg.SMRoomMergeNotify, this.onSMRoomMergeNotify.bind(this));
-
- this.msgManager.initSendMsg(c2sMsg._CMResetRoom, msg.CMResetRoom);
- this.msgManager.initRecvMsg(s2cMsg._SMResetRoom, msg.SMResetRoom, this.onSMResetRoom.bind(this));
-
-
- this.userinfo.init_state = state_enum.inited;
-
- this.rsp && this.rsp.initResponse({
- status: 0
- });
- }.bind(this));
- }
-
- this.setUserId=function(userid){
- this.userinfo.userID = userid;
- }
-
- this.setToken=function(token){
- this.userinfo.token = token;
- }
-
- this. _checkInitState=function(){
- if(this.userinfo.init_state != state_enum.inited){
- if(this.userinfo.init_state == state_enum.none)
- return -2;
- if(this.userinfo.init_state == state_enum.initing)
- return -3;
- }
- return 0;
- }
-
- this._checkLoginState=function(currstate){
- if(this.userinfo.login_state == state_enum.none && currstate != state_enum.logining){
- return -4;
- }
- if(this.userinfo.login_state == state_enum.logined && currstate == state_enum.logining){
- return -5;
- }
- if(this.userinfo.login_state == state_enum.logining && this.userinfo.login_state != currstate){
- return -6;
- }
- if(this.userinfo.login_state == state_enum.loginouting && this.userinfo.login_state != currstate){
- return -6;
- }
- return 0;
- }
-
- this._checkRoomState=function(currstate){
- if(this.userinfo.room_state == state_enum.none && currstate != state_enum.joining){
- return -9;
- }
- if(this.userinfo.room_state == state_enum.joined && currstate == state_enum.joining){
- return -8;
- }
- if(this.userinfo.room_state == state_enum.joining && this.userinfo.room_state != currstate){
- return -7;
- }
- if(this.userinfo.room_state != state_enum.joined && currstate == state_enum.leaving){
- return -6;
- }
- return 0;
- }
-
- this._netCallback=function(msg, err){
- if(msg == "connect"){
- this.reconnectcount = 0;
- var res = {
- status: 0,
- eventtype: msg
- };
- this.rsp && this.rsp.netResponse(res);
- if(this.userinfo.roomID != ""){
- this.reconnect();
- }else{
- this.login();
- }
- //this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMLogin, param);
- }else{
- if(msg == "close"){
- if(this.reconnectcount > this.reconnectmax){
- var res = {
- status: err,
- eventtype: msg
- };
- this.rsp && this.rsp.netResponse(res);
- this._cleanState();
- }else{
- var self = this;
- this.scheduleOnce(function(dt){
- self.reconnectcount++;
- self.reconnectNet();
- var res = {
- status: -1,
- eventtype: "reconnect"
- };
- this.rsp && this.rsp.netResponse(res);
- }, 2);
- }
-
- }
- }
- }
-
- this._cleanState=function(){
- this.userinfo.login_state = state_enum.none;
- this.userinfo.room_state = state_enum.none;
- this.userinfo.roomID = "";
- }
-
- this._handleDeltaTime=function(createtime, passtime){
- var ts = createtime * 1000 + passtime;
- var d = new Date();
- var ct = d.getTime() - ts;
- this.msgctrl.setDeltaTime(ct);
- }
-
- this.isInited=function() {
- return this.userinfo.init_state == state_enum.inited;
- },
-
- this.isLogined=function() {
- return this.userinfo.login_state == state_enum.logined;
- }
-
- this.isInRoom=function (){
- return this.userinfo.room_state == state_enum.joined;
- }
-
- this.isConnected=function (){
- return this.msgManager.isConnected();
- }
-
- this.reconnectNet=function(){
- //this._cleanState();
- var url = this.userinfo.platForm == "alpha"? url_test: url_offical;
- this.msgManager.connectNet(url, this._netCallback.bind(this));
- }
-
- this.disconnect=function(){
- // if(this.msgManager.isConnected()){
- // this.msgManager.closeNet();
- // }
- this.msgManager.closeNet();
- }
-
- this.login=function(){
- var st = state_enum.logining;
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(st);
- if(rs != 0){
- return rs;
- }
- this.userinfo.login_state = st;
-
- var param = {
- account_id: this.userinfo.userID,
- session_id: this.userinfo.token,
- game_id: this.userinfo.gameID,
- device_id: this.userinfo.deviceID
- };
-
- if(!this.isConnected()){
- this.reconnectNet();
- }else{
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMLogin, param);
- }
- this._log && this._log.logVS_login();
- return 0;
- }
-
- this.loginOut=function(){
- this.userinfo.login_state = state_enum.none;
- var param = {
- status: 0
- };
- this.rsp && this.rsp.logoutResponse(param);
- }
-
- this.createRoom=function(roomname, maxplayer, userdesc){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.joining;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- this.userinfo.room_state = st;
- var param = {
- create_room_info:{
- room_name: roomname,
- max_player: maxplayer,
- allow_merge: 0,
- auto_exit_room : 1,
- },
- user_profile: userdesc
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMCreateRoom, param);
- return 0;
- }
-
- this.joinRoom=function(roomid, userdesc){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.joining;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- this.userinfo.room_state = st;
- var param = {
- room_id: roomid,
- user_profile: userdesc
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMJoinRoom, param);
- window.log && window.log.logVS_joinRoom(roomid, userdesc, false);
- return 0;
- }
-
- this.joinRandomRoom=function(maxplayer, userdesc){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.joining;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- this.userinfo.room_state = st;
- var param = {
- max_player: maxplayer,
- user_profile: userdesc
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMJoinRandomRoom, param);
- window.log && window.log.logVS_joinRoom('', userdesc, true);
- return 0;
- }
-
- this.leaveRoom=function(content){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.leaving;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- this.userinfo.room_state = st;
- var param = {
- custom_data: content
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMLeaveRoom, param);
- window.log && window.log.logVS_leaveRoom(this.userinfo.roomID, content);
- return 0;
- }
-
- this.joinOver=function(content){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- custom_data: content
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMJoinOver, param);
- window.log && window.log.logVS_gameReady(this.userinfo.roomID, content, true);
- return 0;
- }
-
- this.joinOpen=function(content){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- custom_data: content
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMJoinOpen, param);
- window.log && window.log.logVS_gameReady(this.userinfo.roomID, content, false);
- return 0;
- }
-
- this.gameStart=function(content){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- custom_data: content
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMGameStart, param);
- window.log && window.log.logVS_gameStart(this.userinfo.roomID, content);
- return 0;
- }
-
- this.kickPlayer=function(userid, content){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- account_id: userid,
- custom_data: content
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMKickPlayer, param);
- return 0;
- }
-
- this.sendRoomMsg=function(msg){
- var d = new Date();
- msg.timestamp = d.getTime() - this.msgctrl.deltatime + this.msgctrl.delaytime;
- this.sendRoomEvent(JSON.stringify(msg));
- }
-
- this.sendRoomEvent=function(msg){
- console.log("[sendRoomEvent]"+msg);
- var rs = this._checkInitState();
- console.log("rs"+rs);
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- custom_data: msg
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMSendRoomEvent, param);
- return 0;
- }
-
- this.sendFrameEvent=function(msg){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- custom_data: msg
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMSendFrameEvent, param);
- return 0;
- }
-
- this.setFrameSync=function(framerate){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- frame_rate: framerate
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMSetFrameSync, param);
- return 0;
- }
-
- this.heart=function(){
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMPing, null);
- return 0;
- }
-
- this.reconnect=function(){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
-
- var param = {
- room_id: this.userinfo.roomID,
- account_id: this.userinfo.userID,
- session_id: this.userinfo.token
- };
-
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMReConnect, param);
- return 0;
- }
-
- this.onLoginRsp=function(msg){
- console.log("[onLoginRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result == null || msg.result.error_code == 0){
- this.userinfo.login_state = state_enum.logined;
- this.userinfo.roomID = msg.room_id? msg.room_id: "";
- }else{
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this.userinfo.login_state = state_enum.none;
- this.userinfo.roomID = "";
- }
- var param = {
- status: err,
- statusmsg: errstr,
- roomID: this.userinfo.roomID
- };
- this.rsp && this.rsp.loginResponse(param);
- }
-
- this.onLoginOutRsp=function(msg){
- console.log("[onLoginOutRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result == null || msg.result.error_code == 0){
- this.userinfo.login_state = state_enum.none;
- }else{
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this.userinfo.login_state = state_enum.logined;
- }
- var param = {
- status: err,
- statusmsg: errstr,
- };
- this.rsp && this.rsp.logoutResponse(param);
- }
-
- this.onCreateRoomRsp=function(msg){
- console.log("[onCreateRoomRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result == null || msg.result.error_code == 0){
- this.userinfo.room_state = state_enum.joined;
- this.userinfo.roomID = msg.room_id? msg.room_id: "";
- }else{
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this.userinfo.room_state = state_enum.none;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onCreateRoomRsp');
- }
- var param = {
- status: err,
- statusmsg: errstr,
- roomID: msg.room_id? msg.room_id: "",
- owner: "",
- create_time: msg.create_time,
- room_info:msg.room_info,
- };
-
- if(param.status == 0){
- this._handleDeltaTime(param.create_time, 0);
- }
-
- this.rsp && this.rsp.createRoomResponse(param);
- }
-
- this.onJoinRoomRsp=function(msg){
- console.log("[onJoinRoomRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result == null ||msg.result.error_code == 0||msg.result.error_code == -3){
- this.userinfo.room_state = state_enum.joined;
- this.userinfo.roomID = msg.room_info? msg.room_info.room_id: "";
-
- }else{
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this.userinfo.room_state = state_enum.none;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onJoinRoomRsp');
- }
-
- var lst = [];
- if(msg.room_user_info_list){
- msg.room_user_info_list.forEach(element => {
- var obj = {
- userId: element.account_id,
- userProfile: element.user_profile
- };
- lst.push(obj);
- });
- }
- var param = {
- status: err,
- statusmsg: errstr,
- roomInfo:{
- roomID: msg.room_info? msg.room_info.room_id: "",
- roomProperty: msg.room_info? msg.room_info.room_property: "",
- ownerId: msg.room_info? msg.room_info.owner_id: "",
- create_time: msg.room_info? msg.room_info.create_time: 0,
- _timestamp: msg.room_info? msg.room_info._timestamp: 0,
- robot_list:msg.room_info? msg.room_info.robot_list: 0
- },
- roomUserInfoList: lst
- };
-
- if(param.status == 0||param.status == -3){
- this._handleDeltaTime(param.roomInfo.create_time, param.roomInfo._timestamp);
- }
-
- this.rsp && this.rsp.joinRoomResponse(param);
- }
-
- this.onJoinOverRsp=function(msg){
- console.log("[onJoinOverRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onJoinOverRsp');
- }
- var param = {
- status: err,
- statusmsg: errstr,
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.joinOverResponse(param);
- }
-
- this.onJoinOpenRsp=function(msg){
- console.log("[onJoinOpenRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onJoinOpenRsp');
- }
- var param = {
- status: err,
- statusmsg: errstr,
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.joinOpenResponse(param);
- }
-
- this.onGameStartRsp=function(msg){
- console.log("[onGameStartRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onGameStartRsp');
- }
- var param = {
- status: err,
- statusmsg: errstr,
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.gameStartResponse(param);
- }
-
- this.onLeaveRoomRsp=function(msg){
- console.log("[onLeaveRoomRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result == null || msg.result.error_code == 0 || msg.result.error_code == -1){
- this.userinfo.room_state = state_enum.none;
- this.userinfo.roomID = "";
- }else{
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this.userinfo.room_state = state_enum.joined;
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onLeaveRoomRsp');
- }
- var param = {
- status: err,
- statusmsg: errstr,
- roomID: msg.room_id? msg.room_id: "",
- userId: msg.account_id? msg.account_id: "",
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.leaveRoomResponse(param);
- }
-
- this.onKickPlayerRsp=function(msg){
- console.log("[onKickPlayerRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- }
- var param = {
- status: err,
- statusmsg: errstr,
- owner: "",
- userId: msg.account_id? msg.account_id: "",
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.kickPlayerResponse(param);
- }
-
- this.onSendRoomEvtRsp=function(msg){
- console.log("[onSendRoomEvtRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- }
- var param = {
- status: err,
- statusmsg: errstr,
- eventid: msg.event_id? msg.event_id: "",
- content: msg.custom_data? msg.custom_data: "",
- _timestamp: msg._timestamp? msg._timestamp: 0
- };
- this.rsp && this.rsp.sendEventResponse(param);
- }
-
- this.onSetFrameSyncRsp=function(msg){
- console.log("[onSetFrameSyncRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- }
- var param = {
- status: err,
- statusmsg: errstr,
- framerate: msg.frame_rate? msg.frame_rate: 0
- };
- this.rsp && this.rsp.setFrameSyncResponse(param);
- }
-
- this.onSendFrameEvtRsp=function(msg){
- // console.log("[onSendFrameEvtRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null && msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- }
- var param = {
- status: err,
- statusmsg: errstr,
- eventid: msg.event_id? msg.event_id: ""
- };
- this.rsp && this.rsp.sendFrameEventResponse(param);
- }
-
- this.onReConnectRsp=function(msg){
- console.log("[onReConnectRsp]"+JSON.stringify(msg));
- var err = 0;
- var errstr = "";
- if(msg.result != null){
- if(msg.result.error_code != 0){
- err = msg.result.error_code;
- errstr = msg.result.error_msg;
- this._cleanState();
- window.log && window.log.logButtonClick('matchvs', msg.result, 'onReConnectRsp');
- }else{
- this.userinfo.roomID = msg.room_info? msg.room_info.room_id: "";
- }
- }
-
- var lst = [];
- if(msg.room_user_info_list){
- msg.room_user_info_list.forEach(element => {
- var obj = {
- userId: element.account_id,
- userProfile: element.user_profile
- };
- lst.push(obj);
- });
- }
- var param = {
- status: err,
- statusmsg: errstr,
- roomInfo:{
- roomID: msg.room_info? msg.room_info.room_id: "",
- roomProperty: msg.room_info? msg.room_info.room_property: "",
- ownerId: msg.room_info? msg.room_info.owner_id: "",
- create_time: msg.room_info? msg.room_info.create_time: 0,
- _timestamp: msg.room_info? msg.room_info._timestamp: 0
- },
- roomUserInfoList: lst
- };
-
- if(param.status == 0){
- this._handleDeltaTime(param.roomInfo.create_time, param.roomInfo._timestamp);
- }
-
- this.rsp && this.rsp.reconnectResponse(param);
- }
-
- this.onRoomEvtNotify=function(msg){
- console.log("[onRoomEvtNotify]"+JSON.stringify(msg));
- var param = {
- srcUserId: msg.src_account_id? msg.src_account_id: "",
- eventid: msg.event_id? msg.event_id: "",
- content: msg.custom_data? msg.custom_data: ""
- };
- this.msgctrl.pushMsg(param);
- this.rsp && this.rsp.sendRoomEvtNotify(param);
- }
-
- this.onKickNotify=function(msg){
- console.log("[onKickNotify]"+JSON.stringify(msg));
- var param = {
- srcUserId: "",
- userId: msg.account_id? msg.account_id: "",
- owner: "",
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.kickPlayerNotify(param);
- }
-
- this.onJoinRoomNotify=function(msg){
- console.log("[onJoinRoomNotify]"+JSON.stringify(msg));
- var param = {
- userId: msg.room_user_info? msg.room_user_info.account_id: "",
- userProfile: msg.room_user_info? msg.room_user_info.user_profile: ""
- };
- this.rsp && this.rsp.joinRoomNotify(param);
- }
-
- this.onLeaveRoomNotify=function(msg){
- console.log("[onLeaveRoomNotify]"+JSON.stringify(msg));
- var param = {
- userId: msg.room_user_info? msg.room_user_info.account_id: "",
- userProfile: msg.room_user_info? msg.room_user_info.user_profile: "",
- roomID: msg.room_id? msg.room_id: "",
- owner: "",
- content: ""
- };
- this.rsp && this.rsp.leaveRoomNotify(param);
- }
-
- this.onFrameUpdateNotify=function(msg){
-// console.log("[onFrameUpdateNotify]"+JSON.stringify(msg));
- var lst = [];
- if(msg.frame_info && msg.frame_info.frame_items){
- msg.frame_info.frame_items.forEach(element =>{
- var obj = {
- srcUserID: element.src_account_id,
- content: element.custom_data,
- timestamp: element.timestamp
- };
- lst.push(obj);
- });
- }
-
- var param = {
- frameIndex: msg.frame_info? msg.frame_info.frame_index: 0,
- frameItems: lst,
- frameWaitCount: msg.frame_info? msg.frame_info.frame_wait_count: 0
- };
- this.rsp && this.rsp.frameUpdate(param);
- }
-
- this.onRoomDestoryNotify=function(msg){
- console.log("[onFrameUpdateNotify]"+JSON.stringify(msg));
- var param = {
- roomID: msg.room_id? msg.room_id: ""
- };
- this.userinfo.room_state = state_enum.none;
- this.userinfo.roomID = "";
- this.rsp && this.rsp.destroyRoomNotify(param);
- }
-
- this.onJoinOverNotify=function(msg){
- console.log("[onJoinOverNotify]"+JSON.stringify(msg));
- var param = {
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.joinOverRoomNotify(param);
- }
-
- this.onJoinOpenNotify=function(msg){
- console.log("[onJoinOpenNotify]"+JSON.stringify(msg));
- var param = {
- content: msg.custom_data? msg.custom_data: ""
- };
- this.rsp && this.rsp.joinOpenRoomNotify(param);
- }
-
- this.onNetWorkStateNotify=function(msg){
- console.log("[onNetWorkStateNotify]"+JSON.stringify(msg));
- var param = {
- roomID: msg.room_id? msg.room_id: "",
- userID: msg.account_id? msg.account_id: "",
- state: msg.state? msg.state: -100,
- owner: msg.owner? msg.owner: ""
- };
- this.rsp && this.rsp.netWorkStateNotify(param);
- }
- this.resetRoom=function(msg){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- join_over: msg,
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMResetRoom, param);
- }
- this.setRoomParam=function(msg){
- var rs = this._checkInitState();
- if(rs != 0){
- return rs;
- }
- rs = this._checkLoginState(this.userinfo.login_state);
- if(rs != 0){
- return rs;
- }
- var st = state_enum.none;
- rs = this._checkRoomState(st);
- if(rs != 0){
- return rs;
- }
- var param = {
- allow_merge: msg,
- };
- this.msgManager.sendMsg(this.msgIDs.c2sMsg()._CMSetRoomParam, param);
- }
- this.onSMSetRoomParam=function(msg){
- console.log("[onSMSetRoomParam]");
- this.rsp && this.rsp.onSMSetRoomParam(msg);
- }
- this.onSMResetRoom=function(msg){
- console.log("[onSMResetRoom]");
- this.rsp && this.rsp.onSMResetRoom(msg);
- }
- this.onSMRoomMergeNotify=function(msg){
- console.log("[onSMRoomMergeNotify]");
- this.rsp && this.rsp.onSMRoomMergeNotify(msg);
- }
- this.onPing=function(msg){
-
- }
-}
-
diff --git a/fc/js/jquery.js b/fc/js/jquery.js
deleted file mode 100644
index 49d1fcf..0000000
--- a/fc/js/jquery.js
+++ /dev/null
@@ -1,2 +0,0 @@
-/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */
-!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n+~]|"+M+")"+M+"*"),z=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),X=new RegExp(W),U=new RegExp("^"+R+"$"),V={ID:new RegExp("^#("+R+")"),CLASS:new RegExp("^\\.("+R+")"),TAG:new RegExp("^("+R+"|[*])"),ATTR:new RegExp("^"+I),PSEUDO:new RegExp("^"+W),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+P+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},G=/^(?:input|select|textarea|button)$/i,Y=/^h\d$/i,Q=/^[^{]+\{\s*\[native \w/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,K=/[+~]/,Z=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ee=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},te=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ne=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},re=function(){p()},ie=me(function(e){return!0===e.disabled&&("form"in e||"label"in e)},{dir:"parentNode",next:"legend"});try{L.apply(A=H.call(w.childNodes),w.childNodes),A[w.childNodes.length].nodeType}catch(e){L={apply:A.length?function(e,t){q.apply(e,H.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function oe(e,t,r,i){var o,s,l,c,f,h,v,m=t&&t.ownerDocument,T=t?t.nodeType:9;if(r=r||[],"string"!=typeof e||!e||1!==T&&9!==T&&11!==T)return r;if(!i&&((t?t.ownerDocument||t:w)!==d&&p(t),t=t||d,g)){if(11!==T&&(f=J.exec(e)))if(o=f[1]){if(9===T){if(!(l=t.getElementById(o)))return r;if(l.id===o)return r.push(l),r}else if(m&&(l=m.getElementById(o))&&x(t,l)&&l.id===o)return r.push(l),r}else{if(f[2])return L.apply(r,t.getElementsByTagName(e)),r;if((o=f[3])&&n.getElementsByClassName&&t.getElementsByClassName)return L.apply(r,t.getElementsByClassName(o)),r}if(n.qsa&&!S[e+" "]&&(!y||!y.test(e))){if(1!==T)m=t,v=e;else if("object"!==t.nodeName.toLowerCase()){(c=t.getAttribute("id"))?c=c.replace(te,ne):t.setAttribute("id",c=b),s=(h=a(e)).length;while(s--)h[s]="#"+c+" "+ve(h[s]);v=h.join(","),m=K.test(e)&&ge(t.parentNode)||t}if(v)try{return L.apply(r,m.querySelectorAll(v)),r}catch(e){}finally{c===b&&t.removeAttribute("id")}}}return u(e.replace(B,"$1"),t,r,i)}function ae(){var e=[];function t(n,i){return e.push(n+" ")>r.cacheLength&&delete t[e.shift()],t[n+" "]=i}return t}function se(e){return e[b]=!0,e}function ue(e){var t=d.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function le(e,t){var n=e.split("|"),i=n.length;while(i--)r.attrHandle[n[i]]=t}function ce(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function fe(e){return function(t){return"input"===t.nodeName.toLowerCase()&&t.type===e}}function pe(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function de(e){return function(t){return"form"in t?t.parentNode&&!1===t.disabled?"label"in t?"label"in t.parentNode?t.parentNode.disabled===e:t.disabled===e:t.isDisabled===e||t.isDisabled!==!e&&ie(t)===e:t.disabled===e:"label"in t&&t.disabled===e}}function he(e){return se(function(t){return t=+t,se(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}function ge(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}n=oe.support={},o=oe.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return!!t&&"HTML"!==t.nodeName},p=oe.setDocument=function(e){var t,i,a=e?e.ownerDocument||e:w;return a!==d&&9===a.nodeType&&a.documentElement?(d=a,h=d.documentElement,g=!o(d),w!==d&&(i=d.defaultView)&&i.top!==i&&(i.addEventListener?i.addEventListener("unload",re,!1):i.attachEvent&&i.attachEvent("onunload",re)),n.attributes=ue(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ue(function(e){return e.appendChild(d.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=Q.test(d.getElementsByClassName),n.getById=ue(function(e){return h.appendChild(e).id=b,!d.getElementsByName||!d.getElementsByName(b).length}),n.getById?(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){return e.getAttribute("id")===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n=t.getElementById(e);return n?[n]:[]}}):(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){var n="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return n&&n.value===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),r.find.TAG=n.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):n.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},r.find.CLASS=n.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&g)return t.getElementsByClassName(e)},v=[],y=[],(n.qsa=Q.test(d.querySelectorAll))&&(ue(function(e){h.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&y.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||y.push("\\["+M+"*(?:value|"+P+")"),e.querySelectorAll("[id~="+b+"-]").length||y.push("~="),e.querySelectorAll(":checked").length||y.push(":checked"),e.querySelectorAll("a#"+b+"+*").length||y.push(".#.+[+~]")}),ue(function(e){e.innerHTML="";var t=d.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&y.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&y.push(":enabled",":disabled"),h.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&y.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),y.push(",.*:")})),(n.matchesSelector=Q.test(m=h.matches||h.webkitMatchesSelector||h.mozMatchesSelector||h.oMatchesSelector||h.msMatchesSelector))&&ue(function(e){n.disconnectedMatch=m.call(e,"*"),m.call(e,"[s!='']:x"),v.push("!=",W)}),y=y.length&&new RegExp(y.join("|")),v=v.length&&new RegExp(v.join("|")),t=Q.test(h.compareDocumentPosition),x=t||Q.test(h.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return f=!0,0;var r=!e.compareDocumentPosition-!t.compareDocumentPosition;return r||(1&(r=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!n.sortDetached&&t.compareDocumentPosition(e)===r?e===d||e.ownerDocument===w&&x(w,e)?-1:t===d||t.ownerDocument===w&&x(w,t)?1:c?O(c,e)-O(c,t):0:4&r?-1:1)}:function(e,t){if(e===t)return f=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===d?-1:t===d?1:i?-1:o?1:c?O(c,e)-O(c,t):0;if(i===o)return ce(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?ce(a[r],s[r]):a[r]===w?-1:s[r]===w?1:0},d):d},oe.matches=function(e,t){return oe(e,null,null,t)},oe.matchesSelector=function(e,t){if((e.ownerDocument||e)!==d&&p(e),t=t.replace(z,"='$1']"),n.matchesSelector&&g&&!S[t+" "]&&(!v||!v.test(t))&&(!y||!y.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(e){}return oe(t,d,null,[e]).length>0},oe.contains=function(e,t){return(e.ownerDocument||e)!==d&&p(e),x(e,t)},oe.attr=function(e,t){(e.ownerDocument||e)!==d&&p(e);var i=r.attrHandle[t.toLowerCase()],o=i&&N.call(r.attrHandle,t.toLowerCase())?i(e,t,!g):void 0;return void 0!==o?o:n.attributes||!g?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null},oe.escape=function(e){return(e+"").replace(te,ne)},oe.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},oe.uniqueSort=function(e){var t,r=[],i=0,o=0;if(f=!n.detectDuplicates,c=!n.sortStable&&e.slice(0),e.sort(D),f){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return c=null,e},i=oe.getText=function(e){var t,n="",r=0,o=e.nodeType;if(o){if(1===o||9===o||11===o){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=i(e)}else if(3===o||4===o)return e.nodeValue}else while(t=e[r++])n+=i(t);return n},(r=oe.selectors={cacheLength:50,createPseudo:se,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(Z,ee),e[3]=(e[3]||e[4]||e[5]||"").replace(Z,ee),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||oe.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&oe.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return V.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=a(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(Z,ee).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=E[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&E(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=oe.attr(r,e);return null==i?"!="===t:!t||(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i.replace($," ")+" ").indexOf(n)>-1:"|="===t&&(i===n||i.slice(0,n.length+1)===n+"-"))}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,f,p,d,h,g=o!==a?"nextSibling":"previousSibling",y=t.parentNode,v=s&&t.nodeName.toLowerCase(),m=!u&&!s,x=!1;if(y){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===v:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?y.firstChild:y.lastChild],a&&m){x=(d=(l=(c=(f=(p=y)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1])&&l[2],p=d&&y.childNodes[d];while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if(1===p.nodeType&&++x&&p===t){c[e]=[T,d,x];break}}else if(m&&(x=d=(l=(c=(f=(p=t)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1]),!1===x)while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===v:1===p.nodeType)&&++x&&(m&&((c=(f=p[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]=[T,x]),p===t))break;return(x-=i)===r||x%r==0&&x/r>=0}}},PSEUDO:function(e,t){var n,i=r.pseudos[e]||r.setFilters[e.toLowerCase()]||oe.error("unsupported pseudo: "+e);return i[b]?i(t):i.length>1?(n=[e,e,"",t],r.setFilters.hasOwnProperty(e.toLowerCase())?se(function(e,n){var r,o=i(e,t),a=o.length;while(a--)e[r=O(e,o[a])]=!(n[r]=o[a])}):function(e){return i(e,0,n)}):i}},pseudos:{not:se(function(e){var t=[],n=[],r=s(e.replace(B,"$1"));return r[b]?se(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),t[0]=null,!n.pop()}}),has:se(function(e){return function(t){return oe(e,t).length>0}}),contains:se(function(e){return e=e.replace(Z,ee),function(t){return(t.textContent||t.innerText||i(t)).indexOf(e)>-1}}),lang:se(function(e){return U.test(e||"")||oe.error("unsupported lang: "+e),e=e.replace(Z,ee).toLowerCase(),function(t){var n;do{if(n=g?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return(n=n.toLowerCase())===e||0===n.indexOf(e+"-")}while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===h},focus:function(e){return e===d.activeElement&&(!d.hasFocus||d.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:de(!1),disabled:de(!0),checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!r.pseudos.empty(e)},header:function(e){return Y.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:he(function(){return[0]}),last:he(function(e,t){return[t-1]}),eq:he(function(e,t,n){return[n<0?n+t:n]}),even:he(function(e,t){for(var n=0;n=0;)e.push(r);return e}),gt:he(function(e,t,n){for(var r=n<0?n+t:n;++r1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function be(e,t,n){for(var r=0,i=t.length;r-1&&(o[l]=!(a[l]=f))}}else v=we(v===a?v.splice(h,v.length):v),i?i(null,a,v,u):L.apply(a,v)})}function Ce(e){for(var t,n,i,o=e.length,a=r.relative[e[0].type],s=a||r.relative[" "],u=a?1:0,c=me(function(e){return e===t},s,!0),f=me(function(e){return O(t,e)>-1},s,!0),p=[function(e,n,r){var i=!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):f(e,n,r));return t=null,i}];u1&&xe(p),u>1&&ve(e.slice(0,u-1).concat({value:" "===e[u-2].type?"*":""})).replace(B,"$1"),n,u0,i=e.length>0,o=function(o,a,s,u,c){var f,h,y,v=0,m="0",x=o&&[],b=[],w=l,C=o||i&&r.find.TAG("*",c),E=T+=null==w?1:Math.random()||.1,k=C.length;for(c&&(l=a===d||a||c);m!==k&&null!=(f=C[m]);m++){if(i&&f){h=0,a||f.ownerDocument===d||(p(f),s=!g);while(y=e[h++])if(y(f,a||d,s)){u.push(f);break}c&&(T=E)}n&&((f=!y&&f)&&v--,o&&x.push(f))}if(v+=m,n&&m!==v){h=0;while(y=t[h++])y(x,b,a,s);if(o){if(v>0)while(m--)x[m]||b[m]||(b[m]=j.call(u));b=we(b)}L.apply(u,b),c&&!o&&b.length>0&&v+t.length>1&&oe.uniqueSort(u)}return c&&(T=E,l=w),x};return n?se(o):o}return s=oe.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=a(e)),n=t.length;while(n--)(o=Ce(t[n]))[b]?r.push(o):i.push(o);(o=S(e,Ee(i,r))).selector=e}return o},u=oe.select=function(e,t,n,i){var o,u,l,c,f,p="function"==typeof e&&e,d=!i&&a(e=p.selector||e);if(n=n||[],1===d.length){if((u=d[0]=d[0].slice(0)).length>2&&"ID"===(l=u[0]).type&&9===t.nodeType&&g&&r.relative[u[1].type]){if(!(t=(r.find.ID(l.matches[0].replace(Z,ee),t)||[])[0]))return n;p&&(t=t.parentNode),e=e.slice(u.shift().value.length)}o=V.needsContext.test(e)?0:u.length;while(o--){if(l=u[o],r.relative[c=l.type])break;if((f=r.find[c])&&(i=f(l.matches[0].replace(Z,ee),K.test(u[0].type)&&ge(t.parentNode)||t))){if(u.splice(o,1),!(e=i.length&&ve(u)))return L.apply(n,i),n;break}}}return(p||s(e,d))(i,t,!g,n,!t||K.test(e)&&ge(t.parentNode)||t),n},n.sortStable=b.split("").sort(D).join("")===b,n.detectDuplicates=!!f,p(),n.sortDetached=ue(function(e){return 1&e.compareDocumentPosition(d.createElement("fieldset"))}),ue(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||le("type|href|height|width",function(e,t,n){if(!n)return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ue(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||le("value",function(e,t,n){if(!n&&"input"===e.nodeName.toLowerCase())return e.defaultValue}),ue(function(e){return null==e.getAttribute("disabled")})||le(P,function(e,t,n){var r;if(!n)return!0===e[t]?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),oe}(e);w.find=E,w.expr=E.selectors,w.expr[":"]=w.expr.pseudos,w.uniqueSort=w.unique=E.uniqueSort,w.text=E.getText,w.isXMLDoc=E.isXML,w.contains=E.contains,w.escapeSelector=E.escape;var k=function(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&w(e).is(n))break;r.push(e)}return r},S=function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n},D=w.expr.match.needsContext;function N(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}var A=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,t,n){return g(t)?w.grep(e,function(e,r){return!!t.call(e,r,e)!==n}):t.nodeType?w.grep(e,function(e){return e===t!==n}):"string"!=typeof t?w.grep(e,function(e){return u.call(t,e)>-1!==n}):w.filter(t,e,n)}w.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?w.find.matchesSelector(r,e)?[r]:[]:w.find.matches(e,w.grep(t,function(e){return 1===e.nodeType}))},w.fn.extend({find:function(e){var t,n,r=this.length,i=this;if("string"!=typeof e)return this.pushStack(w(e).filter(function(){for(t=0;t1?w.uniqueSort(n):n},filter:function(e){return this.pushStack(j(this,e||[],!1))},not:function(e){return this.pushStack(j(this,e||[],!0))},is:function(e){return!!j(this,"string"==typeof e&&D.test(e)?w(e):e||[],!1).length}});var q,L=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(w.fn.init=function(e,t,n){var i,o;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(i="<"===e[0]&&">"===e[e.length-1]&&e.length>=3?[null,e,null]:L.exec(e))||!i[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(i[1]){if(t=t instanceof w?t[0]:t,w.merge(this,w.parseHTML(i[1],t&&t.nodeType?t.ownerDocument||t:r,!0)),A.test(i[1])&&w.isPlainObject(t))for(i in t)g(this[i])?this[i](t[i]):this.attr(i,t[i]);return this}return(o=r.getElementById(i[2]))&&(this[0]=o,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):g(e)?void 0!==n.ready?n.ready(e):e(w):w.makeArray(e,this)}).prototype=w.fn,q=w(r);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};w.fn.extend({has:function(e){var t=w(e,this),n=t.length;return this.filter(function(){for(var e=0;e-1:1===n.nodeType&&w.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(o.length>1?w.uniqueSort(o):o)},index:function(e){return e?"string"==typeof e?u.call(w(e),this[0]):u.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(w.uniqueSort(w.merge(this.get(),w(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}w.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return k(e,"parentNode")},parentsUntil:function(e,t,n){return k(e,"parentNode",n)},next:function(e){return P(e,"nextSibling")},prev:function(e){return P(e,"previousSibling")},nextAll:function(e){return k(e,"nextSibling")},prevAll:function(e){return k(e,"previousSibling")},nextUntil:function(e,t,n){return k(e,"nextSibling",n)},prevUntil:function(e,t,n){return k(e,"previousSibling",n)},siblings:function(e){return S((e.parentNode||{}).firstChild,e)},children:function(e){return S(e.firstChild)},contents:function(e){return N(e,"iframe")?e.contentDocument:(N(e,"template")&&(e=e.content||e),w.merge([],e.childNodes))}},function(e,t){w.fn[e]=function(n,r){var i=w.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=w.filter(r,i)),this.length>1&&(O[e]||w.uniqueSort(i),H.test(e)&&i.reverse()),this.pushStack(i)}});var M=/[^\x20\t\r\n\f]+/g;function R(e){var t={};return w.each(e.match(M)||[],function(e,n){t[n]=!0}),t}w.Callbacks=function(e){e="string"==typeof e?R(e):w.extend({},e);var t,n,r,i,o=[],a=[],s=-1,u=function(){for(i=i||e.once,r=t=!0;a.length;s=-1){n=a.shift();while(++s-1)o.splice(n,1),n<=s&&s--}),this},has:function(e){return e?w.inArray(e,o)>-1:o.length>0},empty:function(){return o&&(o=[]),this},disable:function(){return i=a=[],o=n="",this},disabled:function(){return!o},lock:function(){return i=a=[],n||t||(o=n=""),this},locked:function(){return!!i},fireWith:function(e,n){return i||(n=[e,(n=n||[]).slice?n.slice():n],a.push(n),t||u()),this},fire:function(){return l.fireWith(this,arguments),this},fired:function(){return!!r}};return l};function I(e){return e}function W(e){throw e}function $(e,t,n,r){var i;try{e&&g(i=e.promise)?i.call(e).done(t).fail(n):e&&g(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n.apply(void 0,[e])}}w.extend({Deferred:function(t){var n=[["notify","progress",w.Callbacks("memory"),w.Callbacks("memory"),2],["resolve","done",w.Callbacks("once memory"),w.Callbacks("once memory"),0,"resolved"],["reject","fail",w.Callbacks("once memory"),w.Callbacks("once memory"),1,"rejected"]],r="pending",i={state:function(){return r},always:function(){return o.done(arguments).fail(arguments),this},"catch":function(e){return i.then(null,e)},pipe:function(){var e=arguments;return w.Deferred(function(t){w.each(n,function(n,r){var i=g(e[r[4]])&&e[r[4]];o[r[1]](function(){var e=i&&i.apply(this,arguments);e&&g(e.promise)?e.promise().progress(t.notify).done(t.resolve).fail(t.reject):t[r[0]+"With"](this,i?[e]:arguments)})}),e=null}).promise()},then:function(t,r,i){var o=0;function a(t,n,r,i){return function(){var s=this,u=arguments,l=function(){var e,l;if(!(t=o&&(r!==W&&(s=void 0,u=[e]),n.rejectWith(s,u))}};t?c():(w.Deferred.getStackHook&&(c.stackTrace=w.Deferred.getStackHook()),e.setTimeout(c))}}return w.Deferred(function(e){n[0][3].add(a(0,e,g(i)?i:I,e.notifyWith)),n[1][3].add(a(0,e,g(t)?t:I)),n[2][3].add(a(0,e,g(r)?r:W))}).promise()},promise:function(e){return null!=e?w.extend(e,i):i}},o={};return w.each(n,function(e,t){var a=t[2],s=t[5];i[t[1]]=a.add,s&&a.add(function(){r=s},n[3-e][2].disable,n[3-e][3].disable,n[0][2].lock,n[0][3].lock),a.add(t[3].fire),o[t[0]]=function(){return o[t[0]+"With"](this===o?void 0:this,arguments),this},o[t[0]+"With"]=a.fireWith}),i.promise(o),t&&t.call(o,o),o},when:function(e){var t=arguments.length,n=t,r=Array(n),i=o.call(arguments),a=w.Deferred(),s=function(e){return function(n){r[e]=this,i[e]=arguments.length>1?o.call(arguments):n,--t||a.resolveWith(r,i)}};if(t<=1&&($(e,a.done(s(n)).resolve,a.reject,!t),"pending"===a.state()||g(i[n]&&i[n].then)))return a.then();while(n--)$(i[n],s(n),a.reject);return a.promise()}});var B=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;w.Deferred.exceptionHook=function(t,n){e.console&&e.console.warn&&t&&B.test(t.name)&&e.console.warn("jQuery.Deferred exception: "+t.message,t.stack,n)},w.readyException=function(t){e.setTimeout(function(){throw t})};var F=w.Deferred();w.fn.ready=function(e){return F.then(e)["catch"](function(e){w.readyException(e)}),this},w.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--w.readyWait:w.isReady)||(w.isReady=!0,!0!==e&&--w.readyWait>0||F.resolveWith(r,[w]))}}),w.ready.then=F.then;function _(){r.removeEventListener("DOMContentLoaded",_),e.removeEventListener("load",_),w.ready()}"complete"===r.readyState||"loading"!==r.readyState&&!r.documentElement.doScroll?e.setTimeout(w.ready):(r.addEventListener("DOMContentLoaded",_),e.addEventListener("load",_));var z=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===x(n)){i=!0;for(s in n)z(e,t,s,n[s],!0,o,a)}else if(void 0!==r&&(i=!0,g(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(w(e),n)})),t))for(;s1,null,!0)},removeData:function(e){return this.each(function(){K.remove(this,e)})}}),w.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=J.get(e,t),n&&(!r||Array.isArray(n)?r=J.access(e,t,w.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=w.queue(e,t),r=n.length,i=n.shift(),o=w._queueHooks(e,t),a=function(){w.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return J.get(e,n)||J.access(e,n,{empty:w.Callbacks("once memory").add(function(){J.remove(e,[t+"queue",n])})})}}),w.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),arguments.length\x20\t\r\n\f]+)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,""],thead:[1,""],col:[2,""],tr:[2,""],td:[3,""],_default:[0,"",""]};ge.optgroup=ge.option,ge.tbody=ge.tfoot=ge.colgroup=ge.caption=ge.thead,ge.th=ge.td;function ye(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&N(e,t)?w.merge([e],n):n}function ve(e,t){for(var n=0,r=e.length;n-1)i&&i.push(o);else if(l=w.contains(o.ownerDocument,o),a=ye(f.appendChild(o),"script"),l&&ve(a),n){c=0;while(o=a[c++])he.test(o.type||"")&&n.push(o)}return f}!function(){var e=r.createDocumentFragment().appendChild(r.createElement("div")),t=r.createElement("input");t.setAttribute("type","radio"),t.setAttribute("checked","checked"),t.setAttribute("name","t"),e.appendChild(t),h.checkClone=e.cloneNode(!0).cloneNode(!0).lastChild.checked,e.innerHTML="",h.noCloneChecked=!!e.cloneNode(!0).lastChild.defaultValue}();var be=r.documentElement,we=/^key/,Te=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ce=/^([^.]*)(?:\.(.+)|)/;function Ee(){return!0}function ke(){return!1}function Se(){try{return r.activeElement}catch(e){}}function De(e,t,n,r,i,o){var a,s;if("object"==typeof t){"string"!=typeof n&&(r=r||n,n=void 0);for(s in t)De(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=ke;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return w().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=w.guid++)),e.each(function(){w.event.add(this,t,i,r,n)})}w.event={global:{},add:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.get(e);if(y){n.handler&&(n=(o=n).handler,i=o.selector),i&&w.find.matchesSelector(be,i),n.guid||(n.guid=w.guid++),(u=y.events)||(u=y.events={}),(a=y.handle)||(a=y.handle=function(t){return"undefined"!=typeof w&&w.event.triggered!==t.type?w.event.dispatch.apply(e,arguments):void 0}),l=(t=(t||"").match(M)||[""]).length;while(l--)d=g=(s=Ce.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=w.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=w.event.special[d]||{},c=w.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&w.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(e,r,h,a)||e.addEventListener&&e.addEventListener(d,a)),f.add&&(f.add.call(e,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),w.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.hasData(e)&&J.get(e);if(y&&(u=y.events)){l=(t=(t||"").match(M)||[""]).length;while(l--)if(s=Ce.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){f=w.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,y.handle)||w.removeEvent(e,d,y.handle),delete u[d])}else for(d in u)w.event.remove(e,d+t[l],n,r,!0);w.isEmptyObject(u)&&J.remove(e,"handle events")}},dispatch:function(e){var t=w.event.fix(e),n,r,i,o,a,s,u=new Array(arguments.length),l=(J.get(this,"events")||{})[t.type]||[],c=w.event.special[t.type]||{};for(u[0]=t,n=1;n=1))for(;l!==this;l=l.parentNode||this)if(1===l.nodeType&&("click"!==e.type||!0!==l.disabled)){for(o=[],a={},n=0;n-1:w.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}return l=this,u\x20\t\r\n\f]*)[^>]*)\/>/gi,Ae=/