IGNITE-1282: Better raw handling in a single commit.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/354ea251 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/354ea251 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/354ea251 Branch: refs/heads/ignite-1816 Commit: 354ea2514fa06af0d24e3dd0b5265c09a800d071 Parents: 049b75d Author: vozerov-gridgain <[email protected]> Authored: Thu Nov 12 12:16:33 2015 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Nov 12 12:16:33 2015 +0300 ---------------------------------------------------------------------- .../internal/portable/BinaryReaderExImpl.java | 4 +-- .../internal/portable/BinaryWriterExImpl.java | 32 +++++++++++--------- .../portable/PortableClassDescriptor.java | 1 - .../builder/BinaryObjectBuilderImpl.java | 13 +++----- 4 files changed, 24 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/354ea251/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java index 669ba01..8bcdab9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java @@ -229,14 +229,14 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Obje typeId = in.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS); - IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start, offsetSize); + IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start); footerStart = footer.get1(); footerLen = footer.get2() - footerStart; schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS); - rawOff = PortableUtils.rawOffsetAbsolute(in, start, offsetSize); + rawOff = PortableUtils.rawOffsetAbsolute(in, start); if (typeId == UNREGISTERED_TYPE_ID) { // Skip to the class name position. http://git-wip-us.apache.org/repos/asf/ignite/blob/354ea251/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java index cedf1c8..2bb541a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java @@ -339,7 +339,11 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje * @param userType User type flag. */ public void postWrite(boolean userType) { + short flags = userType ? PortableUtils.FLAG_USR_TYP : 0; + if (schema != null) { + flags |= PortableUtils.FLAG_HAS_SCHEMA; + // Write schema ID. out.writeInt(start + SCHEMA_ID_POS, schemaId); @@ -350,31 +354,29 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje int offsetByteCnt = schema.write(this, fieldCnt); // Write raw offset if needed. - if (rawOffPos != 0) - out.writeInt(rawOffPos - start); - - if (offsetByteCnt == PortableUtils.OFFSET_1) { - int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_ONE_BYTE; + if (rawOffPos != 0) { + flags |= PortableUtils.FLAG_HAS_RAW; - out.writeShort(start + FLAGS_POS, (short)flags); + out.writeInt(rawOffPos - start); } - else if (offsetByteCnt == PortableUtils.OFFSET_2) { - int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_TWO_BYTES; - out.writeShort(start + FLAGS_POS, (short)flags); - } + if (offsetByteCnt == PortableUtils.OFFSET_1) + flags |= PortableUtils.FLAG_OFFSET_ONE_BYTE; + else if (offsetByteCnt == PortableUtils.OFFSET_2) + flags |= PortableUtils.FLAG_OFFSET_TWO_BYTES; } else { - // Write raw-only flag is needed. - int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_RAW_ONLY; - - out.writeShort(start + FLAGS_POS, (short)flags); + if (rawOffPos != 0) + flags |= PortableUtils.FLAG_HAS_RAW; // If there are no schema, we are free to write raw offset to schema offset. out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, (rawOffPos == 0 ? out.position() : rawOffPos) - start); } - // 5. Write length. + // Write flags. + out.writeShort(start + FLAGS_POS, (short)flags); + + // Write length. out.writeInt(start + TOTAL_LEN_POS, out.position() - start); } http://git-wip-us.apache.org/repos/asf/ignite/blob/354ea251/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java index c9870b4..3997b84 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java @@ -682,7 +682,6 @@ public class PortableClassDescriptor { PortableUtils.writeHeader( writer, - userType, registered ? typeId : GridPortableMarshaller.UNREGISTERED_TYPE_ID, obj instanceof CacheObjectImpl ? 0 : obj.hashCode(), registered ? null : cls.getName() http://git-wip-us.apache.org/repos/asf/ignite/blob/354ea251/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java index 777d30b..5e023f5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java @@ -196,7 +196,6 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) { try { PortableUtils.writeHeader(writer, - true, registeredType ? typeId : UNREGISTERED_TYPE_ID, hashCode, registeredType ? null : clsNameToWrite); @@ -222,13 +221,13 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { // Get footer details. int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags); - IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize); + IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start); int footerPos = footer.get1(); int footerEnd = footer.get2(); // Get raw position. - int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize); + int rawPos = PortableUtils.rawOffsetAbsolute(reader, start); // Position reader on data. reader.position(start + hdrLen); @@ -354,9 +353,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { if (reader != null) { // Write raw data if any. - int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags); - - int rawOff = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize); + int rawOff = PortableUtils.rawOffsetAbsolute(reader, start); int footerStart = PortableUtils.footerStartAbsolute(reader, start); if (rawOff < footerStart) { @@ -424,12 +421,12 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { Map<Integer, Object> readCache = new HashMap<>(); - IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize); + IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start); int footerPos = footer.get1(); int footerEnd = footer.get2(); - int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize); + int rawPos = PortableUtils.rawOffsetAbsolute(reader, start); while (footerPos + 4 < footerEnd) { int fieldId = reader.readIntPositioned(footerPos);
