Beispiel #1
0
  public byte[] encode(EncContext ctx) {
    short enc = ((Short) ctx.getEncObject()).shortValue();
    int byteLength = ctx.getByteSize();
    NumberCodec numberCodec = ctx.getNumberCodec();

    return numberCodec.short2Bytes(enc, byteLength);
  }
Beispiel #2
0
  public DecResult decode(DecContext ctx) {
    byte[] bytes = ctx.getDecBytes();
    int byteLength = ctx.getByteSize();
    NumberCodec numberCodec = ctx.getNumberCodec();

    if (byteLength > bytes.length) {
      String errmsg =
          "ShortCodec: not enough bytes for decode, need ["
              + byteLength
              + "], actually ["
              + bytes.length
              + "].";
      if (null != ctx.getField()) {
        errmsg += "/ cause field is [" + ctx.getField() + "]";
      }
      logger.error(errmsg);
      throw new RuntimeException(errmsg);
      // return makeDecResult( retShort, bytes );
    }
    return new DecResult(
        numberCodec.bytes2Short(bytes, byteLength),
        ArrayUtils.subarray(bytes, byteLength, bytes.length));
  }