Repository: ignite Updated Branches: refs/heads/ignite-4242 38df717f8 -> 6bc587dc4
IGNITE-4062: fix BinaryObject.equals: compare only bytes containing the fields' data (without header and footer). This closes #1182. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/44740465 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/44740465 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/44740465 Branch: refs/heads/ignite-4242 Commit: 44740465677c39068dc813dabd464e60f09e5f49 Parents: ec12a9d Author: tledkov-gridgain <[email protected]> Authored: Wed Oct 26 18:00:11 2016 +0500 Committer: tledkov-gridgain <[email protected]> Committed: Wed Oct 26 18:00:11 2016 +0500 ---------------------------------------------------------------------- .../ignite/internal/binary/BinaryContext.java | 2 +- .../internal/binary/BinaryObjectExImpl.java | 57 ++- .../internal/binary/BinaryObjectImpl.java | 23 ++ .../binary/BinaryObjectOffheapImpl.java | 24 +- .../util/offheap/unsafe/GridUnsafeMemory.java | 33 +- .../binary/BinaryMarshallerSelfTest.java | 343 ++++++++++++++++++- 6 files changed, 447 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 0d66970..2ac8b7f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -501,7 +501,7 @@ public class BinaryContext { } /** - * @return Intenal mpper used as default. + * @return Internal mapper used as default. */ public static BinaryInternalMapper defaultMapper() { return DFLT_MAPPER; http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java index 063bd83..e15e770 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java @@ -77,12 +77,26 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx { } /** + * Get offset of data begin. + * + * @return Field value. + */ + @Nullable protected abstract int dataStartOffset(); + + /** + * Get offset of the footer begin. + * + * @return Field value. + */ + @Nullable protected abstract int footerStartOffset(); + + /** * Get field by offset. * - * @param fieldOffset Field offset. + * @param order Field order. * @return Field value. */ - @Nullable protected abstract <F> F fieldByOrder(int fieldOffset); + @Nullable protected abstract <F> F fieldByOrder(int order); /** * @param ctx Reader context. @@ -126,20 +140,29 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx { if (!(other instanceof BinaryObjectExImpl)) return false; - BinaryObjectExImpl otherPo = (BinaryObjectExImpl)other; + BinaryObjectExImpl other0 = (BinaryObjectExImpl)other; + + if (typeId() != other0.typeId()) + return false; + + int start = dataStartOffset(); + int end = footerStartOffset(); + + int otherStart = other0.dataStartOffset(); + int otherEnd = other0.footerStartOffset(); + + int len = end - start; - if (length() != otherPo.length() || typeId() != otherPo.typeId()) + if (len != otherEnd - otherStart) return false; if (hasArray()) { - if (otherPo.hasArray()) { - int len = length(); - int end = start() + len; + byte[] arr = array(); - byte[] arr = array(); - byte[] otherArr = otherPo.array(); + if (other0.hasArray()) { + byte[] otherArr = other0.array(); - for (int i = start(), j = otherPo.start(); i < end; i++, j++) { + for (int i = start, j = otherStart; i < end; i++, j++) { if (arr[i] != otherArr[j]) return false; } @@ -147,22 +170,20 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx { return true; } else { - assert otherPo.offheapAddress() > 0; + assert other0.offheapAddress() > 0; - return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array()); + return GridUnsafeMemory.compare(other0.offheapAddress() + otherStart, arr, start, len); } } else { assert offheapAddress() > 0; - if (otherPo.hasArray()) - return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array()); + if (other0.hasArray()) + return GridUnsafeMemory.compare(offheapAddress() + start, other0.array(), otherStart, len); else { - assert otherPo.offheapAddress() > 0; + assert other0.offheapAddress() > 0; - return GridUnsafeMemory.compare(offheapAddress() + start(), - otherPo.offheapAddress() + otherPo.start(), - length()); + return GridUnsafeMemory.compare(offheapAddress() + start, other0.offheapAddress() + otherStart, len); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java index f37d7c2..54a7c08 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java @@ -296,6 +296,29 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern } /** {@inheritDoc} */ + @Nullable @Override protected int dataStartOffset() { + int typeId = BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.TYPE_ID_POS); + + if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { + int len = BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.DFLT_HDR_LEN + 1); + + return start + GridBinaryMarshaller.DFLT_HDR_LEN + len + 5; + } + else + return start + GridBinaryMarshaller.DFLT_HDR_LEN; + } + + /** {@inheritDoc} */ + @Nullable @Override protected int footerStartOffset() { + short flags = BinaryPrimitives.readShort(arr, start + GridBinaryMarshaller.FLAGS_POS); + + if (!BinaryUtils.hasSchema(flags)) + return start + length(); + + return start + BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS); + } + + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override protected <F> F fieldByOrder(int order) { Object val; http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java index 9cbbaa2..7550b19 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java @@ -96,7 +96,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { int off = start + GridBinaryMarshaller.DFLT_HDR_LEN; - String clsName = BinaryUtils.doReadClassName(new BinaryOffheapInputStream(off, size)); + String clsName = BinaryUtils.doReadClassName(new BinaryOffheapInputStream(ptr + off, size)); typeId = ctx.typeId(clsName); } @@ -174,6 +174,28 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter } /** {@inheritDoc} */ + @Nullable @Override protected int dataStartOffset() { + int typeId = BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.TYPE_ID_POS); + + if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { + int len = BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.DFLT_HDR_LEN + 1); + + return start + GridBinaryMarshaller.DFLT_HDR_LEN + len + 5; + } else + return start + GridBinaryMarshaller.DFLT_HDR_LEN; + } + + /** {@inheritDoc} */ + @Nullable @Override protected int footerStartOffset() { + short flags = BinaryPrimitives.readShort(ptr, start + GridBinaryMarshaller.FLAGS_POS); + + if (!BinaryUtils.hasSchema(flags)) + return start + length(); + + return start + BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS); + } + + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override protected <F> F fieldByOrder(int order) { Object val; http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java index 87ba2f2..718e1a6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java @@ -153,7 +153,8 @@ public class GridUnsafeMemory { * @param reserved If {@code false}, means that memory counter was reserved and size will not * be added to counter. * @param cnt Counter to account allocated memory. - * @throws GridOffHeapOutOfMemoryException + * @throws GridOffHeapOutOfMemoryException In case of out of the off-heap memory. + * @return Pointer to the allocated memory. */ @SuppressWarnings("ErrorNotRethrown") private long allocate0(long size, boolean init, boolean reserved, @@ -507,20 +508,32 @@ public class GridUnsafeMemory { * @return {@code True} if equals. */ public static boolean compare(long ptr, byte[] bytes) { + return compare(ptr, bytes, 0, bytes.length); + } + + /** + * Compares memory. + * + * @param ptr Pointer. + * @param bytes Bytes to compare. + * @param bytesOff Offset in the bytes array. + * @param len Count of compared bytes. + * @return {@code True} if equals. + */ + public static boolean compare(long ptr, byte[] bytes, int bytesOff, int len) { + assert bytesOff + len <= bytes.length : "Check compare bounds: [offset=" + bytesOff + ", len=" + len + + ", bytes.length=" + bytes.length + ']'; + final int addrSize = GridUnsafe.ADDR_SIZE; // Align reads to address size. int off = (int)(ptr % addrSize); int align = addrSize - off; - int len = bytes.length; - if (align != addrSize) { - for (int i = 0; i < align && i < len; i++) { - if (GridUnsafe.getByte(ptr) != bytes[i]) + for (int i = 0, tmpOff = bytesOff; i < align && i < len; i++, tmpOff++, ptr++) { + if (GridUnsafe.getByte(ptr) != bytes[tmpOff]) return false; - - ptr++; } } else @@ -542,7 +555,7 @@ public class GridUnsafeMemory { int word = GridUnsafe.getInt(ptr); - int comp = GridUnsafe.getInt(bytes, GridUnsafe.BYTE_ARR_OFF + step); + int comp = GridUnsafe.getInt(bytes, GridUnsafe.BYTE_ARR_OFF + step + bytesOff); if (word != comp) return false; @@ -558,7 +571,7 @@ public class GridUnsafeMemory { long word = GridUnsafe.getLong(ptr); - long comp = GridUnsafe.getLong(bytes, GridUnsafe.BYTE_ARR_OFF + step); + long comp = GridUnsafe.getLong(bytes, GridUnsafe.BYTE_ARR_OFF + step + bytesOff); if (word != comp) return false; @@ -572,7 +585,7 @@ public class GridUnsafeMemory { if (left != 0) { // Compare left overs byte by byte. for (int i = 0; i < left; i++) - if (GridUnsafe.getByte(ptr + i) != bytes[i + align + words * GridUnsafe.ADDR_SIZE]) + if (GridUnsafe.getByte(ptr + i) != bytes[bytesOff + i + align + words * GridUnsafe.ADDR_SIZE]) return false; } http://git-wip-us.apache.org/repos/asf/ignite/blob/44740465/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java index f415472..39a4d32 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java @@ -842,8 +842,6 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { assertEquals(clazz, marshalUnmarshal(clazz)); } - - /** * */ @@ -2922,6 +2920,209 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { } /** + * @throws Exception If failed. + */ + public void testBinaryEquals() throws Exception { + Collection<String> excludedClasses = Arrays.asList( + ObjectRaw.class.getName(), + ObjectWithRaw.class.getName(), + Value.class.getName()); + + BinaryMarshaller m0 = binaryMarshaller(null, excludedClasses); + BinaryMarshaller m1 = binaryMarshaller(); + + Value obj = new Value(27); + ObjectWithRaw objectWithRaw = new ObjectWithRaw(27, 13); + ObjectRaw objectRaw = new ObjectRaw(27, 13); + + Value objOther = new Value(26); + ObjectWithRaw objectWithRawOther = new ObjectWithRaw(26, 13); + ObjectRaw objectRawOther = new ObjectRaw(26, 13); + + BinaryObjectImpl binObj0 = marshal(obj, m0); + BinaryObjectImpl binObj1 = marshal(obj, m1); + BinaryObjectImpl binObjWithRaw0 = marshal(objectWithRaw, m0); + BinaryObjectImpl binObjWithRaw1 = marshal(objectWithRaw, m1); + BinaryObjectImpl binObjRaw0 = marshal(objectRaw, m0); + BinaryObjectImpl binObjRaw1 = marshal(objectRaw, m1); + + assertNotEquals(binObj0.array().length, binObj1.array().length); + assertNotEquals(binObjWithRaw0.array().length, binObjWithRaw1.array().length); + assertNotEquals(binObjRaw0.array().length, binObjRaw1.array().length); + + checkEquals(binObj0, binObj1); + + checkEquals(binObjWithRaw0, binObjWithRaw1); + + checkEquals(binObjRaw0, binObjRaw1); + + BinaryObjectOffheapImpl binObjOffheap0 = null; + BinaryObjectOffheapImpl binObjOffheap1 = null; + BinaryObjectOffheapImpl binObjWithRawOffheap0 = null; + BinaryObjectOffheapImpl binObjWithRawOffheap1 = null; + BinaryObjectOffheapImpl binObjRawOffheap0 = null; + BinaryObjectOffheapImpl binObjRawOffheap1 = null; + + BinaryObjectImpl binObjOther0 = marshal(objOther, m0); + BinaryObjectImpl binObjOther1 = marshal(objOther, m1); + BinaryObjectImpl binObjWithRawOther0 = marshal(objectWithRawOther, m0); + BinaryObjectImpl binObjWithRawOther1 = marshal(objectWithRawOther, m1); + BinaryObjectImpl binObjRawOther0 = marshal(objectRawOther, m0); + BinaryObjectImpl binObjRawOther1 = marshal(objectRawOther, m1); + + assertEquals(binObjOther0.length(), binObj0.length()); + assertEquals(binObjOther1.length(), binObj1.length()); + assertEquals(binObjWithRawOther0.length(), binObjWithRaw0.length()); + assertEquals(binObjWithRawOther1.length(), binObjWithRaw1.length()); + assertEquals(binObjRawOther0.length(), binObjRaw0.length()); + assertEquals(binObjRawOther1.length(), binObjRaw1.length()); + + assertNotEquals(binObjOther0, binObj0); + assertNotEquals(binObjOther1, binObj1); + assertNotEquals(binObjWithRawOther0, binObjWithRaw0); + assertNotEquals(binObjWithRawOther1, binObjWithRaw1); + assertNotEquals(binObjRawOther0, binObjRaw0); + assertNotEquals(binObjRawOther1, binObjRaw1); + + try { + binObjOffheap0 = marshalOffHeap(binObj0, m0); + binObjOffheap1 = marshalOffHeap(binObj1, m1); + binObjWithRawOffheap0 = marshalOffHeap(binObjWithRaw0, m0); + binObjWithRawOffheap1 = marshalOffHeap(binObjWithRaw1, m1); + binObjRawOffheap0 = marshalOffHeap(binObjRaw0, m0); + binObjRawOffheap1 = marshalOffHeap(binObjRaw1, m1); + + checkEquals(binObj0, binObjOffheap0); + checkEquals(binObj1, binObjOffheap0); + checkEquals(binObj0, binObjOffheap1); + checkEquals(binObj1, binObjOffheap1); + checkEquals(binObjOffheap0, binObjOffheap1); + + checkEquals(binObjWithRaw0, binObjWithRawOffheap0); + checkEquals(binObjWithRaw0, binObjWithRawOffheap1); + checkEquals(binObjWithRaw1, binObjWithRawOffheap0); + checkEquals(binObjWithRaw1, binObjWithRawOffheap1); + checkEquals(binObjWithRawOffheap0, binObjWithRawOffheap1); + + checkEquals(binObjRaw0, binObjRawOffheap0); + checkEquals(binObjRaw1, binObjRawOffheap0); + checkEquals(binObjRaw0, binObjRawOffheap1); + checkEquals(binObjRaw1, binObjRawOffheap1); + checkEquals(binObjRawOffheap0, binObjRawOffheap1); + } + finally { + if (binObjOffheap0 != null) { + GridUnsafe.freeMemory(binObjOffheap0.offheapAddress()); + binObjOffheap0 = null; + } + + if (binObjOffheap1 != null) { + GridUnsafe.freeMemory(binObjOffheap1.offheapAddress()); + binObjOffheap1 = null; + } + + if (binObjWithRawOffheap0 != null) { + GridUnsafe.freeMemory(binObjWithRawOffheap0.offheapAddress()); + binObjOffheap1 = null; + } + + if (binObjWithRawOffheap1 != null) { + GridUnsafe.freeMemory(binObjWithRawOffheap1.offheapAddress()); + binObjOffheap1 = null; + } + + if (binObjRawOffheap0 != null) { + GridUnsafe.freeMemory(binObjRawOffheap0.offheapAddress()); + binObjOffheap1 = null; + } + + if (binObjRawOffheap1 != null) { + GridUnsafe.freeMemory(binObjRawOffheap1.offheapAddress()); + binObjOffheap1 = null; + } + } + } + + /** + * @param binObj0 Object #0. + * @param binObj1 Object #1. + */ + private void checkEquals(Object binObj0, Object binObj1) { + assertEquals(binObj0, binObj1); + assertEquals(binObj1, binObj0); + assertEquals(binObj0, binObj0); + assertEquals(binObj1, binObj1); + } + + /** + * @throws Exception If failed. + */ + public void testBinaryEqualsComplexObject() throws Exception { + List<String> excludedClasses = Arrays.asList( + TestClass0.class.getName(), + TestClass1.class.getName(), + TestClass2.class.getName()); + + BinaryMarshaller m0 = binaryMarshaller(null, excludedClasses); + BinaryMarshaller m1 = binaryMarshaller(null); + + TestClass0 obj0 = new TestClass0(); + TestClass1 obj1 = new TestClass1(); + TestClass2 obj2 = new TestClass2(); + + BinaryObjectImpl binObj00 = marshal(obj0, m0); + BinaryObjectImpl binObj01 = marshal(obj1, m0); + BinaryObjectImpl binObj02 = marshal(obj2, m0); + + // The length of array must be equal. Object are different only by the class. + assertEquals(binObj00.array().length, binObj01.array().length); + assertEquals(binObj00.array().length, binObj02.array().length); + + BinaryObjectImpl binObj10 = marshal(obj0, m1); + BinaryObjectImpl binObj11 = marshal(obj1, m1); + BinaryObjectImpl binObj12 = marshal(obj2, m1); + + // The length of array must be equal. Object are different only by the class. + assertEquals(binObj10.array().length, binObj11.array().length); + assertEquals(binObj10.array().length, binObj12.array().length); + + assertNotEquals(binObj10.array().length, binObj00.array().length); + + assertEquals(binObj00, binObj10); + assertEquals(binObj01, binObj11); + assertEquals(binObj02, binObj12); + + assertNotEquals(binObj00, binObj01); + assertNotEquals(binObj00, binObj02); + assertNotEquals(binObj00, binObj11); + assertNotEquals(binObj00, binObj12); + + assertNotEquals(binObj01, binObj00); + assertNotEquals(binObj01, binObj02); + assertNotEquals(binObj01, binObj10); + assertNotEquals(binObj01, binObj12); + + assertNotEquals(binObj02, binObj00); + assertNotEquals(binObj02, binObj01); + assertNotEquals(binObj02, binObj00); + assertNotEquals(binObj02, binObj11); + } + + /** + * @param obj Instance of the BinaryObjectImpl to offheap marshalling. + * @param marsh Binary marshaller. + * @return Instance of BinaryObjectOffheapImpl. + */ + private BinaryObjectOffheapImpl marshalOffHeap(BinaryObjectImpl obj, BinaryMarshaller marsh) { + long ptr = copyOffheap(obj); + + return new BinaryObjectOffheapImpl(binaryContext(marsh), + ptr, + 0, + obj.array().length); + } + + /** * */ private static interface SomeItf { @@ -3331,7 +3532,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { /** * @return Simple object. */ - private SimpleObject simpleObject() { + private static SimpleObject simpleObject() { SimpleObject inner = new SimpleObject(); inner.b = 1; @@ -4903,7 +5104,8 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { /** */ - private static class SingleHandleB {} + private static class SingleHandleB { + } /** */ @@ -4918,4 +5120,135 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { this.cls = cls; } } -} + + /** + * + */ + private static class TestClass0 { + /** */ + private int intVal = 33; + + /** */ + private String strVal = "Test string value"; + + /** */ + private SimpleObject obj = constSimpleObject(); + + /** + * @return Constant value of the SimpleObject. + */ + public static SimpleObject constSimpleObject() { + SimpleObject obj = simpleObject(); + + obj.uuid = null; + obj.date = new Date(33); + obj.ts = new Timestamp(22); + obj.uuidArr = new UUID[] {null, null, null}; + obj.dateArr = new Date[] {new Date(11111), new Date(22222), new Date(33333)}; + obj.objArr = new Object[] {null, null, null}; + + obj.inner.uuid = null; + obj.inner.date = new Date(33); + obj.inner.ts = new Timestamp(22); + obj.inner.uuidArr = new UUID[] {null, null, null}; + obj.inner.dateArr = new Date[] {new Date(11111), new Date(22222), new Date(33333)}; + obj.inner.objArr = new Object[] {null, null, null}; + + return obj; + } + } + + /** + * + */ + private static class TestClass1 { + /** */ + private int intVal = 33; + + /** */ + private String strVal = "Test string value"; + + /** */ + private SimpleObject obj = TestClass0.constSimpleObject(); + } + + /** + * + */ + private static class TestClass2 extends TestClass0 { + } + + /** */ + private static class ObjectWithRaw implements Binarylizable { + /** */ + private int val; + + /** */ + private int rawVal; + + /** + * + */ + public ObjectWithRaw() { + } + + /** + * @param val Value. + * @param rawVal Raw value. + */ + public ObjectWithRaw(int val, int rawVal) { + this.val = val; + this.rawVal = rawVal; + } + + /** {@inheritDoc} */ + @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { + writer.writeInt("val", val); + + writer.rawWriter().writeInt(rawVal); + } + + /** {@inheritDoc} */ + @Override public void readBinary(BinaryReader reader) throws BinaryObjectException { + val = reader.readInt("val"); + + rawVal = reader.rawReader().readInt(); + } + } + + /** */ + private static class ObjectRaw implements Binarylizable { + /** */ + private int val0; + + /** */ + private int val1; + + /** + * + */ + public ObjectRaw() { + } + + /** + * @param val0 Value. + * @param val1 Raw value. + */ + public ObjectRaw(int val0, int val1) { + this.val0 = val0; + this.val1 = val1; + } + + /** {@inheritDoc} */ + @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { + writer.rawWriter().writeInt(val0); + writer.rawWriter().writeInt(val1); + } + + /** {@inheritDoc} */ + @Override public void readBinary(BinaryReader reader) throws BinaryObjectException { + val0 = reader.rawReader().readInt(); + val1 = reader.rawReader().readInt(); + } + } +} \ No newline at end of file
