예제 #1
0
  @Test
  public void testVeryCompactComplexNumberWithIds() throws Exception {
    // same test, but by calling the writeObject with an artificial outer reference, all types are
    // known
    Complex x = new Complex(42.0, 24.0);
    Complex yAndZ = new Complex(1, 0);

    Vector org = new Vector(x, yAndZ, yAndZ);

    CompactByteArrayComposer cbac = new CompactByteArrayComposer(1000, true);
    cbac.addField(Container.meta$$outer, org); // this line is different from the previous test case
    System.out.println(
        "Length with CompactByteArrayComposer (ID) is " + cbac.getBuilder().length());

    // dump the bytes
    byte[] data = cbac.getBuilder().getBytes();
    System.out.println(ByteUtil.dump(data, 100));
    assert (data.length
        == 12); // here we expect less than a third of the size of the initial test case!

    // parse the result
    CompactByteArrayParser cbap = new CompactByteArrayParser(data, 0, data.length);
    BonaPortable copy = cbap.readObject(Container.meta$$outer, Vector.class);
    assert (copy != null);
    assert (copy instanceof Vector);
    assert (org.equals(copy));
  }
예제 #2
0
  @Test
  public void testCompactComplexNumber() throws Exception {
    Complex x = new Complex(42.0, 24.0);
    Complex yAndZ = new Complex(1, 0);

    Vector org = new Vector(x, yAndZ, yAndZ);

    CompactByteArrayComposer cbac = new CompactByteArrayComposer(1000, false);
    cbac.writeRecord(org);
    System.out.println(
        "Length with CompactByteArrayComposer (ID) is " + cbac.getBuilder().length());

    // dump the bytes
    byte[] data = cbac.getBuilder().getBytes();
    System.out.println(ByteUtil.dump(data, 100));
    assert (data.length
        == 38); // outer object per PQON, first two complex components as base object, last as
    // repeated.

    // parse the result
    CompactByteArrayParser cbap = new CompactByteArrayParser(data, 0, data.length);
    BonaPortable copy = cbap.readRecord();
    assert (copy != null);
    assert (copy instanceof Vector);
    assert (org.equals(copy));
  }