示例#1
0
    public void encode(Encoder encoder) {
      super.encode(encoder);

      encoder.encodeInt(int2);
      encoder.encodeString(string2);
      encoder.encodeInt(buffer2.remaining());
      encoder.encodeKnownLengthBuffer(buffer2);
    }
示例#2
0
    public void decode(Decoder decoder) {
      super.decode(decoder);

      int2 = decoder.decodeInt();
      string2 = decoder.decodeString();

      int length = decoder.decodeInt();
      buffer2 = decoder.decodeKnownLengthBuffer(length, true);
    }
示例#3
0
  public void testByteBufferCoder() {
    Persistent3 three =
        new Persistent3(
            10,
            (float) 4.444,
            555555555555L,
            true,
            "this is the fourth persistent string",
            new Date(),
            new byte[] {10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
            null);

    Persistent2 two =
        new Persistent2(
            1,
            (float) 2.222,
            333333333333L,
            false,
            "this is the first persistent string",
            new Date(),
            new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
            three,
            4,
            "this is the second persistent string",
            (ByteBuffer) ByteBuffer.allocateDirect(17).putInt(1234).rewind());

    Persistent1 one =
        new Persistent1(
            2,
            (float) 3.333,
            4444444444444L,
            true,
            "this is the third persistent string",
            new Date(),
            new byte[] {10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
            two);

    ByteBuffer buffer = ByteBuffer.allocateDirect(8 * 1024);
    ByteBufferCoder encoder = new ByteBufferCoder(buffer, true);

    encoder.encodeCodable(one);
    buffer.rewind();

    ByteBufferCoder decoder = new ByteBufferCoder(buffer, true, new Delegate());
    Persistent1 anotherOne = (Persistent1) decoder.decodeCodable();

    if (!one.equals(anotherOne)) {
      fail("unarchived object with type checking does not equal archived one");
    }

    buffer.clear();
    encoder = new ByteBufferCoder(buffer, false);

    encoder.encodeCodable(one);
    buffer.rewind();

    decoder = new ByteBufferCoder(buffer, false, new Delegate());
    anotherOne = (Persistent1) decoder.decodeCodable();

    if (!one.equals(anotherOne)) {
      fail("unarchived object without type checking does not equal archived one");
    }
  }