Merge branch 'ignite-1282-raw' into ignite-1816

Conflicts:
        
modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
        
modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
        
modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
        
modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/67e6401e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/67e6401e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/67e6401e

Branch: refs/heads/ignite-1816
Commit: 67e6401e08ae36c1e1bd6353db9a7b740aefc89a
Parents: 8056432 9f9f4cc
Author: vozerov-gridgain <[email protected]>
Authored: Thu Nov 12 12:29:46 2015 +0300
Committer: vozerov-gridgain <[email protected]>
Committed: Thu Nov 12 12:29:46 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryReaderExImpl.java   |   4 +-
 .../internal/portable/BinaryWriterExImpl.java   |  28 +--
 .../ignite/internal/portable/PortableUtils.java | 178 +++++++++++--------
 .../builder/BinaryObjectBuilderImpl.java        |  12 +-
 4 files changed, 128 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/67e6401e/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/67e6401e/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index d23bc69,316e700..8149355
--- 
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
@@@ -336,10 -341,9 +336,12 @@@ public class BinaryWriterExImpl impleme
      public void postWrite(boolean userType) {
          short flags = userType ? PortableUtils.FLAG_USR_TYP : 0;
  
 +        if (ctx.isCompactFooter())
 +            flags |= PortableUtils.FLAG_COMPACT_FOOTER;
- 
++        
          if (schema != null) {
+             flags |= PortableUtils.FLAG_HAS_SCHEMA;
+ 
              // Write schema ID.
              out.writeInt(start + SCHEMA_ID_POS, schemaId);
  
@@@ -347,27 -351,33 +349,33 @@@
              out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, out.position() - 
start);
  
              // Write the schema.
 -            int offsetByteCnt = schema.write(this, fieldCnt);
 +            int offsetByteCnt = schema.write(this, fieldCnt, 
ctx.isCompactFooter());
  
-             // Write raw offset if needed.
-             if (rawOffPos != 0)
-                 out.writeInt(rawOffPos - start);
- 
 +            if (offsetByteCnt == PortableUtils.OFFSET_1)
 +                flags |= PortableUtils.FLAG_OFFSET_ONE_BYTE;
 +            else if (offsetByteCnt == PortableUtils.OFFSET_2)
 +                flags |= PortableUtils.FLAG_OFFSET_TWO_BYTES;
++            
+             // Write raw offset if needed.
+             if (rawOffPos != 0) {
+                 flags |= PortableUtils.FLAG_HAS_RAW;
+ 
+                 out.writeInt(rawOffPos - start);
+             }
 -
 -            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.
-             flags |= PortableUtils.FLAG_RAW_ONLY;
+             if (rawOffPos != 0) {
+                 // If there are no schema, we are free to write raw offset to 
schema offset.
+                 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);
+                 out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, rawOffPos - 
start);
+             }
+             else
+                 out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, 0);
          }
  
-         // Write flags as we know them at this point.
+         // Write flags.
 -        out.writeShort(start + FLAGS_POS, (short)flags);
 +        out.writeShort(start + FLAGS_POS, flags);
  
          // Write length.
          out.writeInt(start + TOTAL_LEN_POS, out.position() - start);

http://git-wip-us.apache.org/repos/asf/ignite/blob/67e6401e/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index b49cc5b,39d0ffe..95ef9591
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@@ -101,17 -99,17 +101,20 @@@ public class PortableUtils 
      public static final short FLAG_USR_TYP = 0x0001;
  
      /** Flag: only raw data exists. */
-     public static final short FLAG_RAW_ONLY = 0x0002;
+     public static final short FLAG_HAS_SCHEMA = 0x0002;
+ 
+     /** Flag indicating that object has raw data. */
+     public static final short FLAG_HAS_RAW = 0x0004;
  
      /** Flag: offsets take 1 byte. */
-     public static final short FLAG_OFFSET_ONE_BYTE = 0x0004;
+     public static final short FLAG_OFFSET_ONE_BYTE = 0x0008;
  
      /** Flag: offsets take 2 bytes. */
-     public static final short FLAG_OFFSET_TWO_BYTES = 0x0008;
+     public static final short FLAG_OFFSET_TWO_BYTES = 0x0010;
  
 +    /** Flag: compact footer, no field IDs. */
-     public static final short FLAG_COMPACT_FOOTER = 0x0010;
++    public static final short FLAG_COMPACT_FOOTER = 0x0020;
 +
      /** Offset which fits into 1 byte. */
      public static final int OFFSET_1 = 1;
  
@@@ -186,130 -234,6 +189,181 @@@
  
              PLAIN_TYPE_FLAG[b] = true;
          }
 +
 +        PORTABLE_CLS.add(Byte.class);
 +        PORTABLE_CLS.add(Short.class);
 +        PORTABLE_CLS.add(Integer.class);
 +        PORTABLE_CLS.add(Long.class);
 +        PORTABLE_CLS.add(Float.class);
 +        PORTABLE_CLS.add(Double.class);
 +        PORTABLE_CLS.add(Character.class);
 +        PORTABLE_CLS.add(Boolean.class);
 +        PORTABLE_CLS.add(String.class);
 +        PORTABLE_CLS.add(UUID.class);
 +        PORTABLE_CLS.add(Date.class);
 +        PORTABLE_CLS.add(Timestamp.class);
 +        PORTABLE_CLS.add(BigDecimal.class);
 +        PORTABLE_CLS.add(byte[].class);
 +        PORTABLE_CLS.add(short[].class);
 +        PORTABLE_CLS.add(int[].class);
 +        PORTABLE_CLS.add(long[].class);
 +        PORTABLE_CLS.add(float[].class);
 +        PORTABLE_CLS.add(double[].class);
 +        PORTABLE_CLS.add(char[].class);
 +        PORTABLE_CLS.add(boolean[].class);
 +        PORTABLE_CLS.add(String[].class);
 +        PORTABLE_CLS.add(UUID[].class);
 +        PORTABLE_CLS.add(Date[].class);
 +        PORTABLE_CLS.add(Timestamp[].class);
 +        PORTABLE_CLS.add(BigDecimal[].class);
 +
 +        FIELD_TYPE_NAMES = new String[104];
 +
 +        FIELD_TYPE_NAMES[BYTE] = "byte";
 +        FIELD_TYPE_NAMES[SHORT] = "short";
 +        FIELD_TYPE_NAMES[INT] = "int";
 +        FIELD_TYPE_NAMES[LONG] = "long";
 +        FIELD_TYPE_NAMES[BOOLEAN] = "boolean";
 +        FIELD_TYPE_NAMES[FLOAT] = "float";
 +        FIELD_TYPE_NAMES[DOUBLE] = "double";
 +        FIELD_TYPE_NAMES[CHAR] = "char";
 +        FIELD_TYPE_NAMES[UUID] = "UUID";
 +        FIELD_TYPE_NAMES[DECIMAL] = "decimal";
 +        FIELD_TYPE_NAMES[STRING] = "String";
 +        FIELD_TYPE_NAMES[DATE] = "Date";
 +        FIELD_TYPE_NAMES[TIMESTAMP] = "Timestamp";
 +        FIELD_TYPE_NAMES[ENUM] = "Enum";
 +        FIELD_TYPE_NAMES[OBJ] = "Object";
 +        FIELD_TYPE_NAMES[PORTABLE_OBJ] = "Object";
 +        FIELD_TYPE_NAMES[COL] = "Collection";
 +        FIELD_TYPE_NAMES[MAP] = "Map";
 +        FIELD_TYPE_NAMES[MAP_ENTRY] = "Entry";
 +        FIELD_TYPE_NAMES[CLASS] = "Class";
 +        FIELD_TYPE_NAMES[BYTE_ARR] = "byte[]";
 +        FIELD_TYPE_NAMES[SHORT_ARR] = "short[]";
 +        FIELD_TYPE_NAMES[INT_ARR] = "int[]";
 +        FIELD_TYPE_NAMES[LONG_ARR] = "long[]";
 +        FIELD_TYPE_NAMES[BOOLEAN_ARR] = "boolean[]";
 +        FIELD_TYPE_NAMES[FLOAT_ARR] = "float[]";
 +        FIELD_TYPE_NAMES[DOUBLE_ARR] = "double[]";
 +        FIELD_TYPE_NAMES[CHAR_ARR] = "char[]";
 +        FIELD_TYPE_NAMES[UUID_ARR] = "UUID[]";
 +        FIELD_TYPE_NAMES[DECIMAL_ARR] = "decimal[]";
 +        FIELD_TYPE_NAMES[STRING_ARR] = "String[]";
 +        FIELD_TYPE_NAMES[DATE_ARR] = "Date[]";
 +        FIELD_TYPE_NAMES[TIMESTAMP_ARR] = "Timestamp[]";
 +        FIELD_TYPE_NAMES[OBJ_ARR] = "Object[]";
 +        FIELD_TYPE_NAMES[ENUM_ARR] = "Enum[]";
 +    }
 +
 +    /**
++     * Check if user type flag is set.
++     *
++     * @param flags Flags.
++     * @return {@code True} if set.
++     */
++    public static boolean isUserType(short flags) {
++        return isFlagSet(flags, FLAG_USR_TYP);
++    }
++
++    /**
++     * Check if raw-only flag is set.
++     *
++     * @param flags Flags.
++     * @return {@code True} if set.
++     */
++    public static boolean hasSchema(short flags) {
++        return isFlagSet(flags, FLAG_HAS_SCHEMA);
++    }
++
++    /**
++     * Check if raw-only flag is set.
++     *
++     * @param flags Flags.
++     * @return {@code True} if set.
++     */
++    public static boolean hasRaw(short flags) {
++        return isFlagSet(flags, FLAG_HAS_RAW);
++    }
++
++    /**
++     * Check if "no-field-ids" flag is set.
++     *
++     * @param flags Flags.
++     * @return {@code True} if set.
++     */
++    public static boolean isCompactFooter(short flags) {
++        return isFlagSet(flags, FLAG_COMPACT_FOOTER);
++    }
++
++    /**
++     * Check whether particular flag is set.
++     *
++     * @param flags Flags.
++     * @param flag Flag.
++     * @return {@code True} if flag is set in flags.
++     */
++    private static boolean isFlagSet(short flags, short flag) {
++        return (flags & flag) == flag;
++    }
++    
++    /**
 +     * Schema initial ID.
 +     *
 +     * @return ID.
 +     */
 +    public static int schemaInitialId() {
 +        return FNV1_OFFSET_BASIS;
 +    }
 +
 +    /**
 +     * Update schema ID when new field is added.
 +     *
 +     * @param schemaId Current schema ID.
 +     * @param fieldId Field ID.
 +     * @return New schema ID.
 +     */
 +    public static int updateSchemaId(int schemaId, int fieldId) {
 +        schemaId = schemaId ^ (fieldId & 0xFF);
 +        schemaId = schemaId * FNV1_PRIME;
 +        schemaId = schemaId ^ ((fieldId >> 8) & 0xFF);
 +        schemaId = schemaId * FNV1_PRIME;
 +        schemaId = schemaId ^ ((fieldId >> 16) & 0xFF);
 +        schemaId = schemaId * FNV1_PRIME;
 +        schemaId = schemaId ^ ((fieldId >> 24) & 0xFF);
 +        schemaId = schemaId * FNV1_PRIME;
 +
 +        return schemaId;
 +    }
 +
 +    /**
 +     * @param typeName Field type name.
 +     * @return Field type ID;
 +     */
 +    @SuppressWarnings("StringEquality")
 +    public static int fieldTypeId(String typeName) {
 +        for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
 +            String typeName0 = FIELD_TYPE_NAMES[i];
 +
 +            if (typeName.equals(typeName0))
 +                return i;
 +        }
 +
 +        throw new IllegalArgumentException("Invalid metadata type name: " + 
typeName);
 +    }
 +
 +    /**
 +     * @param typeId Field type ID.
 +     * @return Field type name.
 +     */
 +    public static String fieldTypeName(int typeId) {
 +        assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
 +
 +        String typeName = FIELD_TYPE_NAMES[typeId];
 +
 +        assert typeName != null : typeId;
 +
 +        return typeName;
      }
  
      /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/67e6401e/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
index 268df1a,5e023f5..048044b
--- 
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
@@@ -220,10 -219,9 +220,10 @@@ public class BinaryObjectBuilderImpl im
                      assignedFldsById = Collections.emptyMap();
  
                  // Get footer details.
 -                int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
 +                int fieldIdLen = PortableUtils.fieldIdLength(flags);
 +                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
  
-                 IgniteBiTuple<Integer, Integer> footer = 
PortableUtils.footerAbsolute(reader, start, fieldOffsetLen);
+                 IgniteBiTuple<Integer, Integer> footer = 
PortableUtils.footerAbsolute(reader, start);
  
                  int footerPos = footer.get1();
                  int footerEnd = footer.get2();
@@@ -432,9 -426,9 +430,9 @@@
              int footerPos = footer.get1();
              int footerEnd = footer.get2();
  
-             int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, 
fieldOffsetLen);
+             int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
  
 -            while (footerPos + 4 < footerEnd) {
 +            while (footerPos + fieldIdLen < footerEnd) {
                  int fieldId = reader.readIntPositioned(footerPos);
  
                  IgniteBiTuple<Integer, Integer> posAndLen =

Reply via email to