Пример #1
0
  /**
   * 将请求转为字节流
   *
   * @return piggie 2009-3-14
   */
  public byte[] toBytes() throws RuntimeException {

    ByteBuffer bb = ByteBuffer.allocate(NSHEAD_LEN);
    bb.order(ByteOrder.LITTLE_ENDIAN);

    try {
      bb.putShort(UnsignedSwitch.IntToUshort(id));
      bb.putShort(UnsignedSwitch.IntToUshort(version));
      bb.putInt(UnsignedSwitch.LongToUint(logId));
      byte[] prvd = NetBytesSwitch.StringToBytes(provider, 16);
      bb.put(prvd);
      bb.putInt(UnsignedSwitch.LongToUint(magicNum));
      bb.putInt(UnsignedSwitch.LongToUint(reserved));
      bb.putInt(UnsignedSwitch.LongToUint(bodyLen));
    } catch (Exception e) {
      throw new RuntimeException("exception when putting bytes for nshead...", e);
    }

    return bb.array();
  }