⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hessian2input.as

📁 RESIN 3.2 最新源码
💻 AS
📖 第 1 页 / 共 4 页
字号:
      return read();    }    /**     * Returns true if the data has ended.     *     * @return Whether the data has ended.     */    public override function isEnd():Boolean    {      var code:int;      if (_offset < _length)        code = (_buffer[_offset] & 0xff);      else {        code = read();        if (code >= 0)          _offset--;      }      return (code < 0 || code == 'z'.charCodeAt());    }    /**     * Read the end byte.     */    public override function readEnd():void    {      var code:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();      if (code != 'z'.charCodeAt())        throw error("unknown code:" + String.fromCharCode(code));    }    /**     * Read the end byte.     */    public override function readMapEnd():void    {      var code:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();      if (code != 'z'.charCodeAt())        throw error("unknown code:" + String.fromCharCode(code));    }    /**     * Read the end byte.     */    public override function readListEnd():void    {      var code:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();      if (code != 'z'.charCodeAt())        throw error("unknown code:" + String.fromCharCode(code));    }    /**     * Adds an object reference.     *     * @param obj The object to which to add the reference.     *     * @return The reference number.     *     */    public override function addRef(obj:Object):int    {      if (_refs == null)        _refs = new Array();      _refs.push(obj);      return _refs.length - 1;    }    /**     * Sets an object reference.     *     * @param i The reference number.     * @param obj The object to which to add the reference.     */    public override function setRef(i:int, obj:Object):void    {      _refs[i] = obj;    }    /**     * Resets the references for streaming.     */    public override function resetReferences():void    {      if (_refs != null)        _refs = new Array();    }    /**     * Reads an object type.     *     * @return The type value read as a String.     */    public override function readType():String    {      var code:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();      switch (code) {        case 't'.charCodeAt():          {            var len:int = 256 * read() + read();            var type:String = readLenString(len);            if (_types == null)              _types = new Array();            _types.push(type);            return type;          }        case 'T'.charCodeAt():          return _types[readInt()] as String;        case Hessian2Constants.TYPE_REF:          return _types[readInt()] as String;                  default:          {            if (code >= 0)              _offset--;                      return "";          }      }    }    /**     * Parses the length for an array.     *     * <p>     *   <pre>     *   l b32 b24 b16 b8     *   </pre>     * </p>     *     * @return The length value read as an int.     */    public override function readLength():int    {      var code:int = read();      if (code == Hessian2Constants.LENGTH_BYTE)        return read();      else if (code == 'l'.charCodeAt())        return parseInteger();      else {        if (code >= 0)          _offset--;        return -1;      }    }    /**     * Parses a 32-bit integer value from the stream.     *     * <pre>     * b32 b24 b16 b8     * </pre>     */    private function parseInteger():int    {      var offset:int = _offset;      var b32:int;      var b24:int;      var b16:int;      var b8:int;            if (offset + 3 < _length) {        var buffer:ByteArray = _buffer;                b32 = buffer[offset + 0] & 0xff;        b24 = buffer[offset + 1] & 0xff;        b16 = buffer[offset + 2] & 0xff;        b8 = buffer[offset + 3] & 0xff;        _offset = offset + 4;        return (b32 << 24) + (b24 << 16) + (b16 << 8) + b8;      }      else {        b32 = read();        b24 = read();        b16 = read();        b8 = read();        return (b32 << 24) + (b24 << 16) + (b16 << 8) + b8;      }    }    /**     * Parses a 64-bit long value from the stream.     *     * <pre>     * b64 b56 b48 b40 b32 b24 b16 b8     * </pre>     */    private function parseLong():Number    {      var b64:Number = read();      var b56:Number = read();      var b48:Number = read();      var b40:Number = read();      var b32:Number = read();      var b24:Number = read();      var b16:Number = read();      var b8:Number = read();      // The << operator in actionscript returns a 32-bit int so we can only      // use it for the lowest 32 bits of any computation.  Note that we also       // have to be careful about the sign bit of the lower 32 bits: if the       // MSB of byte b32 is 1, then it can make the bottom 32 bits actually       // represent a negative number, so we really can only use << for the      // lowest 24 bits.      // Notice that we've also split the long into the most and least       // significant 32-bits.  This is because the arithmetic to deal with      // 64-bit negative numbers doesn't always work because AS Numbers are      // 64-bit floats underneath.  Thus we split and do 32-bit arithmetic      // to avoid overflows.      var msi:Number = (b64 * 0x1000000) +                       (b56 << 16) +                       (b48 << 8) +                        b40;      var lsi:Number = (b32 * 0x1000000) +                       (b24 << 16) +                       (b16 << 8) +                        b8;      var sign:Number = 1;      if ((b64 & 0x80) != 0) {        msi = 0xFFFFFFFF - msi;        lsi = 0x100000000 - lsi;        sign = -1;      }      return sign * (msi * 0x100000000 + lsi);    }      /**     * Parses a 64-bit double value from the stream.     *     * <pre>     * b64 b56 b48 b40 b32 b24 b16 b8     * </pre>     */    private function parseDouble():Number    {      var buffer:ByteArray = new ByteArray();      for (var i:int = 0; i < 8; i++)        buffer.writeByte(read());      buffer.position = 0;          return buffer.readDouble();    }    /**     * Reads a character from the underlying stream.     */    private function parseChar():int    {      while (_chunkLength <= 0) {        if (_isLastChunk)          return -1;        var code:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();        switch (code) {          case 's'.charCodeAt():          case 'x'.charCodeAt():            _isLastChunk = false;            _chunkLength = (read() << 8) + read();            break;                      case 'S'.charCodeAt():          case 'X'.charCodeAt():            _isLastChunk = true;            _chunkLength = (read() << 8) + read();            break;                case 0x00: case 0x01: case 0x02: case 0x03:          case 0x04: case 0x05: case 0x06: case 0x07:          case 0x08: case 0x09: case 0x0a: case 0x0b:          case 0x0c: case 0x0d: case 0x0e: case 0x0f:          case 0x10: case 0x11: case 0x12: case 0x13:          case 0x14: case 0x15: case 0x16: case 0x17:          case 0x18: case 0x19: case 0x1a: case 0x1b:          case 0x1c: case 0x1d: case 0x1e: case 0x1f:            _isLastChunk = true;            _chunkLength = code - 0x00;            break;          default:            throw expect("string", code);        }      }      _chunkLength--;      return parseUTF8Char();    }    /**     * Parses a single UTF8 character.     */    private function parseUTF8Char():int    {      var ch:int = _offset < _length ? (_buffer[_offset++] & 0xff) : read();      var ch1:int;      if (ch < 0x80)        return ch;      else if ((ch & 0xe0) == 0xc0) {        ch1 = read();        return ((ch & 0x1f) << 6) + (ch1 & 0x3f);      }      else if ((ch & 0xf0) == 0xe0) {        ch1 = read();        var ch2:int = read();        return ((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f);      }      else        throw error("bad utf-8 encoding");    }      /**     * Reads a byte from the underlying stream.     */    private function parseByte():int    {      while (_chunkLength <= 0) {        if (_isLastChunk)          return -1;        var code:int = read();        switch (code) {          case 'b'.charCodeAt():            _isLastChunk = false;            _chunkLength = (read() << 8) + read();            break;                      case 'B'.charCodeAt():            _isLastChunk = true;            _chunkLength = (read() << 8) + read();            break;          case 0x20: case 0x21: case 0x22: case 0x23:          case 0x24: case 0x25: case 0x26: case 0x27:          case 0x28: case 0x29: case 0x2a: case 0x2b:          case 0x2c: case 0x2d: case 0x2e: case 0x2f:            _isLastChunk = true;            _chunkLength = code - 0x20;            break;          default:            throw expect("byte[]", code);        }      }      _chunkLength--;      return read();    }    /**     * Reads a byte from the stream.     *     * @return The byte read as a uint.     */    public final function read():uint    {      if (_length <= _offset && ! readBuffer())        throw new EOFError();      return _buffer[_offset++] & 0xff;    }    private function readBuffer():Boolean    {      var buffer:ByteArray = new ByteArray();      var offset:int = _offset;      var length:int = _length;      var eof:Boolean = false;          if (offset < length) {        _buffer.readBytes(buffer, offset, length - offset);        offset = length - offset;      }      else        offset = 0;      _buffer = buffer;      var len:int = buffer.length;      // XXX is this the right way to do it?        // Reading from a ByteArray requires this kind of nonsense, but       // will it work for a Socket or something else that actually streams?      var readAmount:int = Math.min(_di.bytesAvailable, SIZE - offset);            _di.readBytes(buffer, offset, readAmount);      // calculate how many bytes were actually read in      len = buffer.length - len;      if (len <= 0) {        _length = offset;        _offset = 0;        return offset > 0;      }      _length = offset + len;      _offset = 0;      return true;    }    /** @private */    protected function expect(expect:String, ch:int):IOError    {      if (ch < 0)        return error("expected " + expect + " at end of file");      else        return error("expected " + expect + " at " + ch);    }      /** @private */    protected function error(msg:String):IOError    {      if (_method != null)        return new HessianProtocolError(_method + ": " + msg);      else        return new HessianProtocolError(msg);    }    // The following functions duplicate the functionality of the     // SerializerFactory infrastructure in the Java implementation    private function readMap(expectedClass:Class = null):Object    {      var type:String = readType();      var cl:Class = null;            try {        cl = getDefinitionByName(type) as Class;      }      catch (e:Error) {}      var obj:Object = null;      if (cl != null)        obj = new cl();      else if (expectedClass != null)        obj = new expectedClass();      else {        obj = new Object();        if (type != null)          obj.hessianTypeName = type;      }      addRef(obj);      while (! isEnd()) {        var key:String = String(readObject());        obj[key] = readObject();      }      readMapEnd();      return obj;    }    private function readList(length:int,                               type:String = null,                               expectedClass:Class = null):Object    {      var array:Array = new Array();      var cl:Class = null;      try {        cl = getDefinitionByName(type) as Class;      }      catch (e:Error) {}      if (cl == null)        cl = expectedClass;      if (cl == null)        cl = Object;      addRef(array);      if (length >= 0) {        for (var i:int = 0; i < length; i++)          array.push(readObject(cl));        readListEnd();      }      else {        while (! isEnd())          array.push(readObject(cl));        readListEnd();      }      return array;    }    private function readLengthList(length:int,                                     type:String = null,                                     expectedClass:Class = null):Object    {      var array:Array = new Array();      var cl:Class = null;      try {        cl = getDefinitionByName(type) as Class;      }      catch (e:Error) {}      if (cl == null)        cl = expectedClass;      if (cl == null)        cl = Object;      addRef(array);      for (var i:int = 0; i < length; i++)        array.push(readObject(cl));      return array;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -