dist/client/lance-gg.js
/**
       *  Class can be serialized using either:
       * - a class based netScheme
       * - an instance based netScheme
       * - completely dynamically (not implemented yet)
       *
       * @param {Object} serializer - Serializer instance
       * @param {Object} [options] - Options object
       * @param {Object} options.dataBuffer [optional] - Data buffer to write to. If null a new data buffer will be created
       * @param {Number} options.bufferOffset [optional] - The buffer data offset to start writing at. Default: 0
       * @param {String} options.dry [optional] - Does not actually write to the buffer (useful to gather serializeable size)
       * @return {Object} the serialized object.  Contains attributes: dataBuffer - buffer which contains the serialized data;  bufferOffset - offset where the serialized data starts.
       */
Class can be serialized using either:
- a class based netScheme
- an instance based netScheme
- completely dynamically (not implemented yet)

@param {Object} serializer - Serializer instance
@param {Object} [options] - Options object
@param {Object} options.dataBuffer [optional] - Data buffer to write to. If null a new data buffer will be created
@param {Number} options.bufferOffset [optional] - The buffer data offset to start writing at. Default: 0
@param {String} options.dry [optional] - Does not actually write to the buffer (useful to gather serializeable size)
@return {Object} the serialized object.  Contains attributes: dataBuffer - buffer which contains the serialized data;  bufferOffset - offset where the serialized data starts.
Class can be serialized using either : - a class based netScheme - an instance based netScheme - completely dynamically ( not implemented yet ) @param { Object } serializer - Serializer instance @param { Object } [ options ] - Options object @param { Object } options . dataBuffer [ optional ] - Data buffer to write to . If null a new data buffer will be created @param { Number } options . bufferOffset [ optional ] - The buffer data offset to start writing at . Default : 0 @param { String } options . dry [ optional ] - Does not actually write to the buffer ( useful to gather serializeable size ) @return { Object } the serialized object . Contains attributes : dataBuffer - buffer which contains the serialized data ; bufferOffset - offset where the serialized data starts .
function serialize(serializer, options) {
        options = Object.assign({
          bufferOffset: 0
        }, options);
        var netScheme;
        var dataBuffer;
        var dataView;
        var classId = 0;
        var bufferOffset = options.bufferOffset;
        var localBufferOffset = 0; 
        if (this.classId) {
          classId = this.classId;
        } else {
          classId = Utils.hashStr(this.constructor.name);
        } 
        if (this.netScheme) {
          netScheme = this.netScheme;
        } else if (this.constructor.netScheme) {
          netScheme = this.constructor.netScheme;
        } else {
          console.warn('no netScheme defined! This will result in awful performance');
        } 
        if (options.dataBuffer == null && options.dry != true) {
          var bufferSize = this.serialize(serializer, {
            dry: true
          }).bufferOffset;
          dataBuffer = new ArrayBuffer(bufferSize);
        } else {
          dataBuffer = options.dataBuffer;
        }
        if (options.dry != true) {
          dataView = new DataView(dataBuffer); 
          dataView.setUint8(bufferOffset + localBufferOffset, classId);
        } 
        localBufferOffset += Uint8Array.BYTES_PER_ELEMENT;
        if (netScheme) {
          var _iteratorNormalCompletion = true;
          var _didIteratorError = false;
          var _iteratorError = undefined;
          try {
            for (var _iterator = Object.keys(netScheme).sort()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
              var property = _step.value;
              if (options.dry != true) {
                serializer.writeDataView(dataView, this[property], bufferOffset + localBufferOffset, netScheme[property]);
              }
              if (netScheme[property].type === BaseTypes.TYPES.STRING) {
                localBufferOffset += Uint16Array.BYTES_PER_ELEMENT;
                if (this[property] !== null && this[property] !== undefined) localBufferOffset += this[property].length * Uint16Array.BYTES_PER_ELEMENT;
              } else if (netScheme[property].type === BaseTypes.TYPES.CLASSINSTANCE) {
                var objectInstanceBufferOffset = this[property].serialize(serializer, {
                  dry: true
                }).bufferOffset;
                localBufferOffset += objectInstanceBufferOffset;
              } else if (netScheme[property].type === BaseTypes.TYPES.LIST) {
                localBufferOffset += Uint16Array.BYTES_PER_ELEMENT;
                var _iteratorNormalCompletion2 = true;
                var _didIteratorError2 = false;
                var _iteratorError2 = undefined;
                try {
                  for (var _iterator2 = this[property][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
                    var item = _step2.value;
                    if (netScheme[property].itemType === BaseTypes.TYPES.CLASSINSTANCE) {
                      var listBufferOffset = item.serialize(serializer, {
                        dry: true
                      }).bufferOffset;
                      localBufferOffset += listBufferOffset;
                    } else if (netScheme[property].itemType === BaseTypes.TYPES.STRING) {
                      localBufferOffset += Uint16Array.BYTES_PER_ELEMENT * (1 + item.length);
                    } else {
                      localBufferOffset += serializer.getTypeByteSize(netScheme[property].itemType);
                    }
                  }
                } catch (err) {
                  _didIteratorError2 = true;
                  _iteratorError2 = err;
                } finally {
                  try {
                    if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
                      _iterator2.return();
                    }
                  } finally {
                    if (_didIteratorError2) {
                      throw _iteratorError2;
                    }
                  }
                }
              } else {
                localBufferOffset += serializer.getTypeByteSize(netScheme[property].type);
              }
            }
          } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
          } finally {
            try {
              if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
              }
            } finally {
              if (_didIteratorError) {
                throw _iteratorError;
              }
            }
          }
        }
        return {
          dataBuffer: dataBuffer,
          bufferOffset: localBufferOffset
        };
      } 
function serialize ( serializer , options ) { options = Object . assign ( { bufferOffset : 0 } , options ) ; var netScheme ; var dataBuffer ; var dataView ; var classId = 0 ; var bufferOffset = options . bufferOffset ; var localBufferOffset = 0 ; if ( this . classId ) { classId = this . classId ; } else { classId = Utils . hashStr ( this . constructor . name ) ; } if ( this . netScheme ) { netScheme = this . netScheme ; } else if ( this . constructor . netScheme ) { netScheme = this . constructor . netScheme ; } else { console . warn ( 'no netScheme defined! This will result in awful performance' ) ; } if ( options . dataBuffer == null && options . dry != true ) { var bufferSize = this . serialize ( serializer , { dry : true } ) . bufferOffset ; dataBuffer = new ArrayBuffer ( bufferSize ) ; } else { dataBuffer = options . dataBuffer ; } if ( options . dry != true ) { dataView = new DataView ( dataBuffer ) ; dataView . setUint8 ( bufferOffset + localBufferOffset , classId ) ; } localBufferOffset += Uint8Array . BYTES_PER_ELEMENT ; if ( netScheme ) { var _iteratorNormalCompletion = true ; var _didIteratorError = false ; var _iteratorError = undefined ; try { for ( var _iterator = Object . keys ( netScheme ) . sort ( ) [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) { var property = _step . value ; if ( options . dry != true ) { serializer . writeDataView ( dataView , this [ property ] , bufferOffset + localBufferOffset , netScheme [ property ] ) ; } if ( netScheme [ property ] . type === BaseTypes . TYPES . STRING ) { localBufferOffset += Uint16Array . BYTES_PER_ELEMENT ; if ( this [ property ] !== null && this [ property ] !== undefined ) localBufferOffset += this [ property ] . length * Uint16Array . BYTES_PER_ELEMENT ; } else if ( netScheme [ property ] . type === BaseTypes . TYPES . CLASSINSTANCE ) { var objectInstanceBufferOffset = this [ property ] . serialize ( serializer , { dry : true } ) . bufferOffset ; localBufferOffset += objectInstanceBufferOffset ; } else if ( netScheme [ property ] . type === BaseTypes . TYPES . LIST ) { localBufferOffset += Uint16Array . BYTES_PER_ELEMENT ; var _iteratorNormalCompletion2 = true ; var _didIteratorError2 = false ; var _iteratorError2 = undefined ; try { for ( var _iterator2 = this [ property ] [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) { var item = _step2 . value ; if ( netScheme [ property ] . itemType === BaseTypes . TYPES . CLASSINSTANCE ) { var listBufferOffset = item . serialize ( serializer , { dry : true } ) . bufferOffset ; localBufferOffset += listBufferOffset ; } else if ( netScheme [ property ] . itemType === BaseTypes . TYPES . STRING ) { localBufferOffset += Uint16Array . BYTES_PER_ELEMENT * ( 1 + item . length ) ; } else { localBufferOffset += serializer . getTypeByteSize ( netScheme [ property ] . itemType ) ; } } } catch ( err ) { _didIteratorError2 = true ; _iteratorError2 = err ; } finally { try { if ( ! _iteratorNormalCompletion2 && _iterator2 . return != null ) { _iterator2 . return ( ) ; } } finally { if ( _didIteratorError2 ) { throw _iteratorError2 ; } } } } else { localBufferOffset += serializer . getTypeByteSize ( netScheme [ property ] . type ) ; } } } catch ( err ) { _didIteratorError = true ; _iteratorError = err ; } finally { try { if ( ! _iteratorNormalCompletion && _iterator . return != null ) { _iterator . return ( ) ; } } finally { if ( _didIteratorError ) { throw _iteratorError ; } } } } return { dataBuffer : dataBuffer , bufferOffset : localBufferOffset } ; }
Class can be serialized using either:
 - a class based netScheme
 - an instance based netScheme
 - completely dynamically (not implemented yet)
Class can be serialized using either : - a class based netScheme - an instance based netScheme - completely dynamically ( not implemented yet )
// used for counting the bufferOffset // instance classId // instance netScheme // todo define behaviour when a netScheme is undefined // TODO: currently we serialize every node twice, once to calculate the size //       of the buffers and once to write them out.  This can be reduced to //       a single pass by starting with a large (and static) ArrayBuffer and //       recursively building it up. // buffer has one Uint8Array for class id, then payload // first set the id of the class, so that the deserializer can fetch information about it // advance the offset counter // write the property to buffer // derive the size of the string // derive the size of the included class // derive the size of the list // list starts with number of elements // todo inelegant, currently doesn't support list of lists // size includes string length plus double-byte characters // advance offset // build a clone of this object with pruned strings (if necessary)