This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 91a1de9db8c [MINOR] Inline binary writer methods (#12032)
91a1de9db8c is described below
commit 91a1de9db8c6ca568d1988e6386e23d5b13e6613
Author: Nikolay <[email protected]>
AuthorDate: Wed Apr 23 16:01:12 2025 +0300
[MINOR] Inline binary writer methods (#12032)
---
.../internal/binary/BinaryClassDescriptor.java | 8 +-
.../internal/binary/BinaryFieldAccessor.java | 4 +-
.../ignite/internal/binary/BinaryWriterExImpl.java | 921 ++++++++-------------
3 files changed, 365 insertions(+), 568 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 78fe947a468..e2b041134c8 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -770,7 +770,7 @@ public class BinaryClassDescriptor {
case OBJECT_ARR:
if (obj instanceof BinaryArray)
- writer.doWriteBinaryArray(((BinaryArray)obj));
+ writer.writeBinaryArray(((BinaryArray)obj));
else
writer.writeObjectArray((Object[])obj);
@@ -792,13 +792,13 @@ public class BinaryClassDescriptor {
break;
case BINARY_ENUM:
- writer.doWriteBinaryEnum((BinaryEnumObjectImpl)obj);
+ writer.writeBinaryEnum((BinaryEnumObjectImpl)obj);
break;
case ENUM_ARR:
if (obj instanceof BinaryArray)
- writer.doWriteBinaryArray(((BinaryArray)obj));
+ writer.writeBinaryArray(((BinaryArray)obj));
else
writer.doWriteEnumArray((Object[])obj);
@@ -810,7 +810,7 @@ public class BinaryClassDescriptor {
break;
case PROXY:
- writer.doWriteProxy((Proxy)obj, intfs);
+ writer.writeProxy((Proxy)obj, intfs);
break;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
index 81a7365356e..02345be7555 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
@@ -672,7 +672,7 @@ abstract class BinaryFieldAccessor {
break;
case BINARY_ENUM:
- writer.doWriteBinaryEnum((BinaryEnumObjectImpl)val);
+ writer.writeBinaryEnum((BinaryEnumObjectImpl)val);
break;
@@ -684,7 +684,7 @@ abstract class BinaryFieldAccessor {
case BINARY:
case OBJECT:
case PROXY:
- writer.writeObjectField(val);
+ writer.writeObject(val);
break;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index ded0d41cce0..84c8d57adb7 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -277,7 +277,7 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
out.position(out.position() + GridBinaryMarshaller.DFLT_HDR_LEN);
if (clsName != null)
- doWriteString(clsName);
+ writeString(clsName);
}
/**
@@ -409,385 +409,11 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
out.write(val, off, len);
}
- /**
- * @param val String value.
- */
- private void doWriteDecimal(@Nullable BigDecimal val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4 + 4);
-
- out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL);
-
- out.unsafeWriteInt(val.scale());
-
- BigInteger intVal = val.unscaledValue();
-
- boolean negative = intVal.signum() == -1;
-
- if (negative)
- intVal = intVal.negate();
-
- byte[] vals = intVal.toByteArray();
-
- if (negative)
- vals[0] |= -0x80;
-
- out.unsafeWriteInt(vals.length);
- out.writeByteArray(vals);
- }
- }
-
- /**
- * @param val String value.
- */
- private void doWriteString(@Nullable String val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- byte[] strArr;
-
- if (BinaryUtils.USE_STR_SERIALIZATION_VER_2)
- strArr = BinaryUtils.strToUtf8Bytes(val);
- else
- strArr = val.getBytes(UTF_8);
-
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.STRING);
- out.unsafeWriteInt(strArr.length);
-
- out.writeByteArray(strArr);
- }
- }
-
- /**
- * @param uuid UUID.
- */
- private void doWriteUuid(@Nullable UUID uuid) {
- if (uuid == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 8 + 8);
- out.unsafeWriteByte(GridBinaryMarshaller.UUID);
- out.unsafeWriteLong(uuid.getMostSignificantBits());
- out.unsafeWriteLong(uuid.getLeastSignificantBits());
- }
- }
-
- /**
- * @param date Date.
- */
- private void doWriteDate(@Nullable Date date) {
- if (date == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 8);
- out.unsafeWriteByte(GridBinaryMarshaller.DATE);
- out.unsafeWriteLong(date.getTime());
- }
- }
-
- /**
- * @param ts Timestamp.
- */
- private void doWriteTimestamp(@Nullable Timestamp ts) {
- if (ts == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 8 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP);
- out.unsafeWriteLong(ts.getTime());
- out.unsafeWriteInt(ts.getNanos() % 1000000);
- }
- }
-
- /**
- * @param time Time.
- */
- private void doWriteTime(@Nullable Time time) {
- if (time == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 8);
- out.unsafeWriteByte(GridBinaryMarshaller.TIME);
- out.unsafeWriteLong(time.getTime());
- }
- }
-
- /**
- * Write object.
- *
- * @param obj Object.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- private void doWriteObject(@Nullable Object obj) throws
BinaryObjectException {
- if (obj == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out,
schema, handles());
-
- writer.failIfUnregistered(failIfUnregistered);
-
- writer.marshal(obj);
- }
- }
-
- /**
- * @param val Byte array.
- */
- private void doWriteByteArray(@Nullable byte[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.BYTE_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeByteArray(val);
- }
- }
-
- /**
- * @param val Short array.
- */
- private void doWriteShortArray(@Nullable short[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.SHORT_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeShortArray(val);
- }
- }
-
- /**
- * @param val Integer array.
- */
- private void doWriteIntArray(@Nullable int[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.INT_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeIntArray(val);
- }
- }
-
- /**
- * @param val Long array.
- */
- private void doWriteLongArray(@Nullable long[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.LONG_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeLongArray(val);
- }
- }
-
- /**
- * @param val Float array.
- */
- private void doWriteFloatArray(@Nullable float[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.FLOAT_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeFloatArray(val);
- }
- }
-
- /**
- * @param val Double array.
- */
- private void doWriteDoubleArray(@Nullable double[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.DOUBLE_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeDoubleArray(val);
- }
- }
-
- /**
- * @param val Char array.
- */
- private void doWriteCharArray(@Nullable char[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.CHAR_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeCharArray(val);
- }
- }
-
- /**
- * @param val Boolean array.
- */
- private void doWriteBooleanArray(@Nullable boolean[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.BOOLEAN_ARR);
- out.unsafeWriteInt(val.length);
-
- out.writeBooleanArray(val);
- }
- }
-
- /**
- * @param val Array of strings.
- */
- private void doWriteDecimalArray(@Nullable BigDecimal[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL_ARR);
- out.unsafeWriteInt(val.length);
-
- for (BigDecimal str : val)
- doWriteDecimal(str);
- }
- }
-
- /**
- * @param val Array of strings.
- */
- void doWriteStringArray(@Nullable String[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.STRING_ARR);
- out.unsafeWriteInt(val.length);
-
- for (String str : val)
- doWriteString(str);
- }
- }
-
- /**
- * @param val Array of UUIDs.
- */
- private void doWriteUuidArray(@Nullable UUID[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.UUID_ARR);
- out.unsafeWriteInt(val.length);
-
- for (UUID uuid : val)
- doWriteUuid(uuid);
- }
- }
-
- /**
- * @param val Array of dates.
- */
- private void doWriteDateArray(@Nullable Date[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.DATE_ARR);
- out.unsafeWriteInt(val.length);
-
- for (Date date : val)
- doWriteDate(date);
- }
- }
-
- /**
- * @param val Array of timestamps.
- */
- private void doWriteTimestampArray(@Nullable Timestamp[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP_ARR);
- out.unsafeWriteInt(val.length);
-
- for (Timestamp ts : val)
- doWriteTimestamp(ts);
- }
- }
-
- /**
- * @param val Array of time.
- */
- private void doWriteTimeArray(@Nullable Time[] val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.TIME_ARR);
- out.unsafeWriteInt(val.length);
-
- for (Time time : val)
- doWriteTime(time);
- }
- }
-
- /**
- * @param val Array of objects.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- private void doWriteObjectArray(@Nullable Object[] val) throws
BinaryObjectException {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- BinaryClassDescriptor desc = ctx.registerClass(
- val.getClass().getComponentType(),
- true,
- failIfUnregistered);
-
- out.unsafeEnsure(1 + 4);
- out.unsafeWriteByte(GridBinaryMarshaller.OBJ_ARR);
-
- if (desc.registered())
- out.unsafeWriteInt(desc.typeId());
- else {
- out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
-
- doWriteString(val.getClass().getComponentType().getName());
- }
-
- out.writeInt(val.length);
-
- for (Object obj : val)
- doWriteObject(obj);
- }
- }
-
/**
* @param val Array wrapper.
* @throws BinaryObjectException In case of error.
*/
- void doWriteBinaryArray(BinaryArray val) throws BinaryObjectException {
+ void writeBinaryArray(BinaryArray val) throws BinaryObjectException {
if (val.array() == null)
out.writeByte(GridBinaryMarshaller.NULL);
else {
@@ -802,87 +428,19 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
out.unsafeWriteInt(val.componentTypeId());
if (val.componentTypeId() ==
GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- doWriteString(val.componentClassName());
+ writeString(val.componentClassName());
out.writeInt(val.array().length);
for (Object obj : val.array())
- doWriteObject(obj);
- }
- }
-
- /**
- * @param col Collection.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- private void doWriteCollection(@Nullable Collection<?> col) throws
BinaryObjectException {
- if (col == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- if (tryWriteAsHandle(col))
- return;
-
- out.unsafeEnsure(1 + 4 + 1);
- out.unsafeWriteByte(GridBinaryMarshaller.COL);
- out.unsafeWriteInt(col.size());
- out.unsafeWriteByte(ctx.collectionType(col.getClass()));
-
- for (Object obj : col)
- doWriteObject(obj);
- }
- }
-
- /**
- * @param map Map.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- private void doWriteMap(@Nullable Map<?, ?> map) throws
BinaryObjectException {
- if (map == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- if (tryWriteAsHandle(map))
- return;
-
- out.unsafeEnsure(1 + 4 + 1);
- out.unsafeWriteByte(GridBinaryMarshaller.MAP);
- out.unsafeWriteInt(map.size());
- out.unsafeWriteByte(ctx.mapType(map.getClass()));
-
- for (Map.Entry<?, ?> e : map.entrySet()) {
- doWriteObject(e.getKey());
- doWriteObject(e.getValue());
- }
- }
- }
-
- /**
- * @param val Value.
- */
- private void doWriteEnum(@Nullable Enum<?> val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- BinaryClassDescriptor desc =
ctx.registerClass(val.getDeclaringClass(), true, failIfUnregistered);
-
- out.unsafeEnsure(1 + 4);
-
- out.unsafeWriteByte(GridBinaryMarshaller.ENUM);
-
- if (desc.registered())
- out.unsafeWriteInt(desc.typeId());
- else {
- out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
- doWriteString(val.getDeclaringClass().getName());
- }
-
- out.writeInt(val.ordinal());
+ writeObject(obj);
}
}
/**
* @param val Value.
*/
- void doWriteBinaryEnum(BinaryEnumObjectImpl val) {
+ void writeBinaryEnum(BinaryEnumObjectImpl val) {
assert val != null;
int typeId = val.typeId();
@@ -900,73 +458,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
out.unsafeWriteByte(GridBinaryMarshaller.BINARY_ENUM);
out.unsafeWriteInt(typeId);
- doWriteString(val.className());
+ writeString(val.className());
out.writeInt(val.enumOrdinal());
}
}
- /**
- * @param val Array.
- */
- void doWriteEnumArray(@Nullable Object[] val) {
- assert val == null || val.getClass().getComponentType().isEnum();
-
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- BinaryClassDescriptor desc = ctx.registerClass(
- val.getClass().getComponentType(),
- true,
- failIfUnregistered);
-
- out.unsafeEnsure(1 + 4);
-
- out.unsafeWriteByte(GridBinaryMarshaller.ENUM_ARR);
-
- if (desc.registered())
- out.unsafeWriteInt(desc.typeId());
- else {
- out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
-
- doWriteString(val.getClass().getComponentType().getName());
- }
-
- out.writeInt(val.length);
-
- // TODO: Denis: Redundant data for each element of the array.
- for (Object o : val)
- doWriteEnum((Enum<?>)o);
- }
- }
-
- /**
- * @param val Class.
- */
- private void doWriteClass(@Nullable Class val) {
- if (val == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- BinaryClassDescriptor desc = ctx.registerClass(val, false,
failIfUnregistered);
-
- out.unsafeEnsure(1 + 4);
-
- out.unsafeWriteByte(GridBinaryMarshaller.CLASS);
-
- if (desc.registered())
- out.unsafeWriteInt(desc.typeId());
- else {
- out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
-
- doWriteString(val.getName());
- }
- }
- }
-
/**
* @param proxy Proxy.
*/
- public void doWriteProxy(Proxy proxy, Class<?>[] intfs) {
+ public void writeProxy(Proxy proxy, Class<?>[] intfs) {
if (proxy == null)
out.writeByte(GridBinaryMarshaller.NULL);
else {
@@ -983,7 +484,7 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
else {
out.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
- doWriteString(intf.getName());
+ writeString(intf.getName());
}
}
@@ -991,25 +492,7 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
assert ih != null;
- doWriteObject(ih);
- }
- }
-
- /**
- * @param po Binary object.
- */
- private void doWriteBinaryObject(@Nullable BinaryObjectImpl po) {
- if (po == null)
- out.writeByte(GridBinaryMarshaller.NULL);
- else {
- byte[] poArr = po.array();
-
- out.unsafeEnsure(1 + 4 + poArr.length + 4);
-
- out.unsafeWriteByte(GridBinaryMarshaller.BINARY_OBJ);
- out.unsafeWriteInt(poArr.length);
- out.writeByteArray(poArr);
- out.unsafeWriteInt(po.start());
+ writeObject(ih);
}
}
@@ -1037,7 +520,23 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
* @param val Class.
*/
void writeClass(@Nullable Class val) {
- doWriteClass(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ BinaryClassDescriptor desc = ctx.registerClass(val, false,
failIfUnregistered);
+
+ out.unsafeEnsure(1 + 4);
+
+ out.unsafeWriteByte(GridBinaryMarshaller.CLASS);
+
+ if (desc.registered())
+ out.unsafeWriteInt(desc.typeId());
+ else {
+ out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+
+ writeString(val.getName());
+ }
+ }
}
/**
@@ -1180,20 +679,23 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
writeBooleanFieldPrimitive(val);
}
- /**
- * @param obj Object.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- void writeObjectField(@Nullable Object obj) throws BinaryObjectException {
- doWriteObject(obj);
- }
-
/**
* @param po Binary object.
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
public void writeBinaryObject(@Nullable BinaryObjectImpl po) throws
BinaryObjectException {
- doWriteBinaryObject(po);
+ if (po == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ byte[] poArr = po.array();
+
+ out.unsafeEnsure(1 + 4 + poArr.length + 4);
+
+ out.unsafeWriteByte(GridBinaryMarshaller.BINARY_OBJ);
+ out.unsafeWriteInt(poArr.length);
+ out.writeByteArray(poArr);
+ out.unsafeWriteInt(po.start());
+ }
}
/** {@inheritDoc} */
@@ -1292,7 +794,30 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeDecimal(@Nullable BigDecimal val) throws
BinaryObjectException {
- doWriteDecimal(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4 + 4);
+
+ out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL);
+
+ out.unsafeWriteInt(val.scale());
+
+ BigInteger intVal = val.unscaledValue();
+
+ boolean negative = intVal.signum() == -1;
+
+ if (negative)
+ intVal = intVal.negate();
+
+ byte[] vals = intVal.toByteArray();
+
+ if (negative)
+ vals[0] |= -0x80;
+
+ out.unsafeWriteInt(vals.length);
+ out.writeByteArray(vals);
+ }
}
/** {@inheritDoc} */
@@ -1303,7 +828,22 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeString(@Nullable String val) throws
BinaryObjectException {
- doWriteString(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ byte[] strArr;
+
+ if (BinaryUtils.USE_STR_SERIALIZATION_VER_2)
+ strArr = BinaryUtils.strToUtf8Bytes(val);
+ else
+ strArr = val.getBytes(UTF_8);
+
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.STRING);
+ out.unsafeWriteInt(strArr.length);
+
+ out.writeByteArray(strArr);
+ }
}
/** {@inheritDoc} */
@@ -1314,7 +854,14 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeUuid(@Nullable UUID val) throws
BinaryObjectException {
- doWriteUuid(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 8 + 8);
+ out.unsafeWriteByte(GridBinaryMarshaller.UUID);
+ out.unsafeWriteLong(val.getMostSignificantBits());
+ out.unsafeWriteLong(val.getLeastSignificantBits());
+ }
}
/** {@inheritDoc} */
@@ -1325,7 +872,13 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeDate(@Nullable Date val) throws
BinaryObjectException {
- doWriteDate(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 8);
+ out.unsafeWriteByte(GridBinaryMarshaller.DATE);
+ out.unsafeWriteLong(val.getTime());
+ }
}
/** {@inheritDoc} */
@@ -1336,7 +889,14 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeTimestamp(@Nullable Timestamp val) throws
BinaryObjectException {
- doWriteTimestamp(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 8 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP);
+ out.unsafeWriteLong(val.getTime());
+ out.unsafeWriteInt(val.getNanos() % 1000000);
+ }
}
/** {@inheritDoc} */
@@ -1347,18 +907,32 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeTime(@Nullable Time val) throws
BinaryObjectException {
- doWriteTime(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 8);
+ out.unsafeWriteByte(GridBinaryMarshaller.TIME);
+ out.unsafeWriteLong(val.getTime());
+ }
}
/** {@inheritDoc} */
@Override public void writeObject(String fieldName, @Nullable Object obj)
throws BinaryObjectException {
writeFieldId(fieldName);
- writeObjectField(obj);
+ writeObject(obj);
}
/** {@inheritDoc} */
@Override public void writeObject(@Nullable Object obj) throws
BinaryObjectException {
- doWriteObject(obj);
+ if (obj == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out,
schema, handles());
+
+ writer.failIfUnregistered(failIfUnregistered);
+
+ writer.marshal(obj);
+ }
}
/** {@inheritDoc} */
@@ -1382,7 +956,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeByteArray(@Nullable byte[] val) throws
BinaryObjectException {
- doWriteByteArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.BYTE_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeByteArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1393,7 +975,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeShortArray(@Nullable short[] val) throws
BinaryObjectException {
- doWriteShortArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.SHORT_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeShortArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1404,7 +994,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeIntArray(@Nullable int[] val) throws
BinaryObjectException {
- doWriteIntArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.INT_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeIntArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1415,7 +1013,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeLongArray(@Nullable long[] val) throws
BinaryObjectException {
- doWriteLongArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.LONG_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeLongArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1426,7 +1032,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeFloatArray(@Nullable float[] val) throws
BinaryObjectException {
- doWriteFloatArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.FLOAT_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeFloatArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1438,7 +1052,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeDoubleArray(@Nullable double[] val) throws
BinaryObjectException {
- doWriteDoubleArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.DOUBLE_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeDoubleArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1449,7 +1071,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeCharArray(@Nullable char[] val) throws
BinaryObjectException {
- doWriteCharArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.CHAR_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeCharArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1461,7 +1091,15 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeBooleanArray(@Nullable boolean[] val) throws
BinaryObjectException {
- doWriteBooleanArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.BOOLEAN_ARR);
+ out.unsafeWriteInt(val.length);
+
+ out.writeBooleanArray(val);
+ }
}
/** {@inheritDoc} */
@@ -1473,7 +1111,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeDecimalArray(@Nullable BigDecimal[] val) throws
BinaryObjectException {
- doWriteDecimalArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (BigDecimal str : val)
+ writeDecimal(str);
+ }
}
/** {@inheritDoc} */
@@ -1485,7 +1132,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeStringArray(@Nullable String[] val) throws
BinaryObjectException {
- doWriteStringArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.STRING_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (String str : val)
+ writeString(str);
+ }
}
/** {@inheritDoc} */
@@ -1496,7 +1152,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeUuidArray(@Nullable UUID[] val) throws
BinaryObjectException {
- doWriteUuidArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.UUID_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (UUID uuid : val)
+ writeUuid(uuid);
+ }
}
/** {@inheritDoc} */
@@ -1507,7 +1172,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeDateArray(@Nullable Date[] val) throws
BinaryObjectException {
- doWriteDateArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.DATE_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (Date date : val)
+ writeDate(date);
+ }
}
/** {@inheritDoc} */
@@ -1518,7 +1192,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeTimestampArray(@Nullable Timestamp[] val)
throws BinaryObjectException {
- doWriteTimestampArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (Timestamp ts : val)
+ writeTimestamp(ts);
+ }
}
/** {@inheritDoc} */
@@ -1529,7 +1212,16 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeTimeArray(@Nullable Time[] val) throws
BinaryObjectException {
- doWriteTimeArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.TIME_ARR);
+ out.unsafeWriteInt(val.length);
+
+ for (Time time : val)
+ writeTime(time);
+ }
}
/** {@inheritDoc} */
@@ -1540,7 +1232,33 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public void writeObjectArray(@Nullable Object[] val) throws
BinaryObjectException {
- doWriteObjectArray(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ BinaryClassDescriptor desc = ctx.registerClass(
+ val.getClass().getComponentType(),
+ true,
+ failIfUnregistered);
+
+ out.unsafeEnsure(1 + 4);
+ out.unsafeWriteByte(GridBinaryMarshaller.OBJ_ARR);
+
+ if (desc.registered())
+ out.unsafeWriteInt(desc.typeId());
+ else {
+ out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+
+ writeString(val.getClass().getComponentType().getName());
+ }
+
+ out.writeInt(val.length);
+
+ for (Object obj : val)
+ writeObject(obj);
+ }
}
/** {@inheritDoc} */
@@ -1552,7 +1270,20 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public <T> void writeCollection(@Nullable Collection<T> col)
throws BinaryObjectException {
- doWriteCollection(col);
+ if (col == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ if (tryWriteAsHandle(col))
+ return;
+
+ out.unsafeEnsure(1 + 4 + 1);
+ out.unsafeWriteByte(GridBinaryMarshaller.COL);
+ out.unsafeWriteInt(col.size());
+ out.unsafeWriteByte(ctx.collectionType(col.getClass()));
+
+ for (Object obj : col)
+ writeObject(obj);
+ }
}
/** {@inheritDoc} */
@@ -1564,7 +1295,22 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public <K, V> void writeMap(@Nullable Map<K, V> map) throws
BinaryObjectException {
- doWriteMap(map);
+ if (map == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ if (tryWriteAsHandle(map))
+ return;
+
+ out.unsafeEnsure(1 + 4 + 1);
+ out.unsafeWriteByte(GridBinaryMarshaller.MAP);
+ out.unsafeWriteInt(map.size());
+ out.unsafeWriteByte(ctx.mapType(map.getClass()));
+
+ for (Map.Entry<?, ?> e : map.entrySet()) {
+ writeObject(e.getKey());
+ writeObject(e.getValue());
+ }
+ }
}
/** {@inheritDoc} */
@@ -1575,7 +1321,24 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
/** {@inheritDoc} */
@Override public <T extends Enum<?>> void writeEnum(T val) throws
BinaryObjectException {
- doWriteEnum(val);
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ BinaryClassDescriptor desc =
ctx.registerClass(val.getDeclaringClass(), true, failIfUnregistered);
+
+ out.unsafeEnsure(1 + 4);
+
+ out.unsafeWriteByte(GridBinaryMarshaller.ENUM);
+
+ if (desc.registered())
+ out.unsafeWriteInt(desc.typeId());
+ else {
+ out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+ writeString(val.getDeclaringClass().getName());
+ }
+
+ out.writeInt(val.ordinal());
+ }
}
/** {@inheritDoc} */
@@ -1589,6 +1352,40 @@ public class BinaryWriterExImpl implements BinaryWriter,
BinaryRawWriterEx, Obje
doWriteEnumArray(val);
}
+ /**
+ * @param val Array.
+ */
+ void doWriteEnumArray(@Nullable Object[] val) {
+ assert val == null || val.getClass().getComponentType().isEnum();
+
+ if (val == null)
+ out.writeByte(GridBinaryMarshaller.NULL);
+ else {
+ BinaryClassDescriptor desc = ctx.registerClass(
+ val.getClass().getComponentType(),
+ true,
+ failIfUnregistered);
+
+ out.unsafeEnsure(1 + 4);
+
+ out.unsafeWriteByte(GridBinaryMarshaller.ENUM_ARR);
+
+ if (desc.registered())
+ out.unsafeWriteInt(desc.typeId());
+ else {
+ out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+
+ writeString(val.getClass().getComponentType().getName());
+ }
+
+ out.writeInt(val.length);
+
+ // TODO: Denis: Redundant data for each element of the array.
+ for (Object o : val)
+ writeEnum((Enum<?>)o);
+ }
+ }
+
/** {@inheritDoc} */
@Override public BinaryRawWriter rawWriter() {
if (rawOffPos == 0)