将webSocket消息转换为bytebuf类型,以适配后面的解码器
429440
@Override
	protected void decode(ChannelHandlerContext paramChannelHandlerContext,
			WebSocketFrame paramINBOUND_IN, List<Object> paramList)
			throws Exception {
		if(paramINBOUND_IN instanceof BinaryWebSocketFrame)
		{
			BinaryWebSocketFrame msg=(BinaryWebSocketFrame)paramINBOUND_IN;
			ByteBuf data = msg.content();
			paramList.add(data);
			data.retain();
		}
	}
26523
public static ByteBuffer toByteBuffer(String s) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(s.length());
        buffer.put(s.getBytes(UTF_8));
        buffer.flip();
        return buffer;
    }
67167
function decodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toUint8Array(buf);

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_decodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _decode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
1271049
@Override
	protected void decode(ChannelHandlerContext paramChannelHandlerContext,
			WebSocketFrame paramINBOUND_IN, List<Object> paramList)
			throws Exception {
		if(paramINBOUND_IN instanceof TextWebSocketFrame)
		{
			TextWebSocketFrame msg=(TextWebSocketFrame)paramINBOUND_IN;
			String text=msg.text();
			paramList.add(msg.text());
			log.debug("TextWebSocketFrame to text:"+text);
		}
	}
70771
function innerDecode(byteBuffer, readBody, deCompressBody) {
  const msgExt = new Message();
  // 消息ID
  byteBufferMsgId.reset();
  // 1 TOTALSIZE
  msgExt.storeSize = byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  msgExt.bodyCRC = byteBuffer.getInt();
  // 4 QUEUEID
  msgExt.queueId = byteBuffer.getInt();
  // 5 FLAG
  msgExt.flag = byteBuffer.getInt();
  // 6 QUEUEOFFSET
  msgExt.queueOffset = byteBuffer.getLong().toNumber();
  // 7 PHYSICALOFFSET
  msgExt.commitLogOffset = byteBuffer.getLong().toNumber();
  // 8 SYSFLAG
  const sysFlag = byteBuffer.getInt();
  msgExt.sysFlag = sysFlag;
  // 9 BORNTIMESTAMP
  msgExt.bornTimestamp = byteBuffer.getLong().toNumber();
  // 10 BORNHOST
  const host = Buffer.alloc(4);
  byteBuffer.get(host);
  let port = byteBuffer.getInt();
  msgExt.bornHost = host[0] + '.' + host[1] + '.' + host[2] + '.' + host[3] + ':' + port;
  // 11 STORETIMESTAMP
  msgExt.storeTimestamp = byteBuffer.getLong().toNumber();
  // 12 STOREHOST
  host.fill(0);
  byteBuffer.get(host);
  port = byteBuffer.getInt();
  msgExt.storeHost = host[0] + '.' + host[1] + '.' + host[2] + '.' + host[3] + ':' + port;
  byteBufferMsgId.put(host);
  byteBufferMsgId.putInt(port);
  byteBufferMsgId.putLong(msgExt.commitLogOffset);
  // 13 RECONSUMETIMES
  msgExt.reconsumeTimes = byteBuffer.getInt();
  // 14 Prepared Transaction Offset
  msgExt.preparedTransactionOffset = byteBuffer.getLong().toNumber();
  // 15 BODY
  const bodyLen = byteBuffer.getInt();
  if (bodyLen > 0) {
    if (readBody) {
      let body = Buffer.alloc(bodyLen);
      byteBuffer.get(body);

      // uncompress body
      if (deCompressBody && (sysFlag & MessageSysFlag.CompressedFlag) === MessageSysFlag.CompressedFlag) {
        body = utils.uncompress(body);
      }
      msgExt.body = body;
    } else {
      byteBuffer.position(byteBuffer.position() + bodyLen);
    }
  }

  // 16 TOPIC
  const topicLen = byteBuffer.get();
  const topic = Buffer.alloc(topicLen);
  byteBuffer.get(topic);
  msgExt.topic = topic.toString();

  // 17 properties
  const propertiesLength = byteBuffer.getShort();
  if (propertiesLength > 0) {
    const properties = Buffer.alloc(propertiesLength);
    byteBuffer.get(properties);
    const propertiesString = properties.toString();
    msgExt.properties = string2messageProperties(propertiesString);
  }

  msgExt.msgId = bytes2string(byteBufferMsgId.copy());
  return msgExt;
}
656727
function bytebufOverflowProtect(bytebuf, maxSize) {
    if (bytebuf.offset + maxSize > bytebuf.buf.length) {
      var length = bytebuf.buf.length * 2;
      while (length < bytebuf.offset + maxSize)
        length = length * 2;

      var tmp = new Buffer(length);
      bytebuf.buf.copy(tmp, 0, 0, bytebuf.buf.length);
      bytebuf.buf = tmp;
      return bytebuf;
    }
    return bytebuf;
  }
909157
function encode(buf) {
	if (buf.length != 8) {
		throw new TypeError("Buffer must be length 8");
	}

	var num = new UInt64(buf.readUInt32BE(4), buf.readUInt32BE(0));
	var str = "";
	do {
		num.div(SIXTY_TWO);
		str = CHARS[num.remainder] + str;
	} while (num.greaterThan(ZERO));

	return str;
}
1174352
function encodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toArrayLike(buf);

    if (!options.hasOwnProperty('width') || !options.hasOwnProperty('height')) {
      return cb(new Error('Provide width & height of the buffer'));
    }

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_encodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _encode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
796534
private static ByteBuf createSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload) {
        ByteBuf frame = ctx.alloc().buffer(FRAME_HEADER_LENGTH + payload.readableBytes());
        writeFrameHeader(frame, payload.readableBytes(), SETTINGS, new Http2Flags(), 0);
        frame.writeBytes(payload);
        payload.release();
        return frame;
    }
235091
@Override
  public void streamReply(WebSocket session,
                          HeadersAmp headers,
                          String to,
                          long qid,
                          int sequence,
                          List<Object> values,
                          Throwable exn,
                          boolean isComplete)
    throws IOException
  {
    /*
    if (values != null && values.size() > 0) {
      try (Writer out = session.getBasicRemote().getSendWriter()) {
        init(out);
        streamResult(headers, to, qid, values);
      }
    }
    
    if (exn != null) {
      try (Writer out = session.getBasicRemote().getSendWriter()) {
        init(out);
        streamError(headers, to, qid, exn);
      }
    }
    else if (isComplete) {
      try (Writer out = session.getBasicRemote().getSendWriter()) {
        init(out);
        streamComplete(headers, to, qid);
      }
    }
    */
  }
367620
function bufferToString(buffer) {
	        // base64-arraybuffer
	        var bytes = new Uint8Array(buffer);
	        var base64String = '';
	        var i;

	        for (i = 0; i < bytes.length; i += 3) {
	            /*jslint bitwise: true */
	            base64String += BASE_CHARS[bytes[i] >> 2];
	            base64String += BASE_CHARS[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4];
	            base64String += BASE_CHARS[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6];
	            base64String += BASE_CHARS[bytes[i + 2] & 63];
	        }

	        if (bytes.length % 3 === 2) {
	            base64String = base64String.substring(0, base64String.length - 1) + '=';
	        } else if (bytes.length % 3 === 1) {
	            base64String = base64String.substring(0, base64String.length - 2) + '==';
	        }

	        return base64String;
	    }
1077441
function strbuf(str) {
  var b = new ByteBuffer(str.length + 4);

  b.setUint16 (0, str.length, true);

  for (var i = 0; i < str.length; i += 2) {
    b.setUint16 (i + 2, str.getUint16 (i), true);
  }

  b.setUint16 (b.length - 2, 0, true);

  return b;
}
914550
private IoBuffer encodeClientBW(ClientBW clientBW) {
        final IoBuffer out = IoBuffer.allocate(5);
        out.putInt(clientBW.getBandwidth());
        out.put(clientBW.getLimitType());
        return out;
    }
660969
static ByteBuffer unescapeBytes(final CharSequence input)
    {
        int pos = 0, len = input.length();
        final byte[] result = new byte[len];
        ByteBuffer buffer = ByteBuffer.wrap(result);
        for (int i = 0; i < len; i++)
        {
            char c = input.charAt(i);
            if (c == '\\')
            {
                if (i + 1 < len)
                {
                    ++i;
                    c = input.charAt(i);
                    if (isOctal(c))
                    {
                        // Octal escape.
                        int code = digitValue(c);
                        if (i + 1 < len && isOctal(input.charAt(i + 1)))
                        {
                            ++i;
                            code = code * 8 + digitValue(input.charAt(i));
                        }
                        if (i + 1 < len && isOctal(input.charAt(i + 1)))
                        {
                            ++i;
                            code = code * 8 + digitValue(input.charAt(i));
                        }
                        result[pos++] = (byte) code;
                    }
                    else
                    {
                        switch (c)
                        {
                            case 'a':
                                result[pos++] = 0x07;
                                break;
                            case 'b':
                                result[pos++] = '\b';
                                break;
                            case 'f':
                                result[pos++] = '\f';
                                break;
                            case 'n':
                                result[pos++] = '\n';
                                break;
                            case 'r':
                                result[pos++] = '\r';
                                break;
                            case 't':
                                result[pos++] = '\t';
                                break;
                            case 'v':
                                result[pos++] = 0x0b;
                                break;
                            case '\\':
                                result[pos++] = '\\';
                                break;
                            case '\'':
                                result[pos++] = '\'';
                                break;
                            case '"':
                                result[pos++] = '\"';
                                break;

                            case 'x':
                                // hex escape
                                int code = 0;
                                if (i + 1 < len && isHex(input.charAt(i + 1)))
                                {
                                    ++i;
                                    code = digitValue(input.charAt(i));
                                }
                                else
                                {
                                    throw new InvalidEscapeSequenceException(
                                            "Invalid escape sequence: '\\x' with no digits");
                                }
                                if (i + 1 < len && isHex(input.charAt(i + 1)))
                                {
                                    ++i;
                                    code = code * 16 + digitValue(input.charAt(i));
                                }
                                result[pos++] = (byte) code;
                                break;

                            default:
                                throw new InvalidEscapeSequenceException(
                                        "Invalid escape sequence: '\\" + c + '\'');
                        }
                    }
                }
                else
                {
                    throw new InvalidEscapeSequenceException(
                            "Invalid escape sequence: '\\' at end of string.");
                }
            }
            else
            {
                result[pos++] = (byte) c;
            }
        }
        buffer.limit(pos);
        return buffer;
    }
998787
@Override
    public ByteBuffer getBinary() throws IOException {
        if (_messageType == null) {
            return null;
        }

        if (_messageType == WebSocketMessageType.EOS){
            String s = "End of stream has reached as the connection has been closed";
            throw new WebSocketException(s);
        }

        if (_messageType != WebSocketMessageType.BINARY) {
            String s = "Invalid WebSocketMessageType: Cannot decode the payload " +
                       "as a binary message";
            throw new WebSocketException(s);            
        }
    
        return ByteBuffer.wrap(((ByteBuffer)_payload).array());
    }
1083094
function (msg, knownComputations) {
    if (msg.data && msg.data.byteLength) {
      // The presence of byteLength indicates data is an ArrayBuffer from a WebSocket data frame.
      return parseBinaryMessage(msg.data, knownComputations);
    } else if (msg.type) {
      // Otherwise it's JSON in a WebSocket text frame.
      return JSON.parse(msg.data);
    } else {
      console.warn('Unrecognized websocket message.');
      return null;
    }
  }
396228
public void onMessage(String sessionId, ByteBuffer buffer) {
        WebSocketSession session = WsonrpcRemotes.getSession(sessionId);
        byte[] bytes = buffer.array();
        WsonrpcSessions.begin(session);
        try {
            fireMessage(sessionId, bytes);
            wsonrpcControl.handle(session, bytes);
        } catch (Exception ex) {
            onError(session.getId(), ex);
        } finally {
            WsonrpcSessions.end();
        }
    }