/** * @param cls type to examine. * @return true if typeId equals for passed type and current * binary enum. */ public boolean isTypeEquals(final Class<?> cls) { return ctx.descriptorForClass(cls, false, false).typeId() == typeId(); } }
/** * @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.descriptorForClass( val.getClass().getComponentType(), false, 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 Value. */ void doWriteEnum(@Nullable Enum<?> val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val.getDeclaringClass(), false, 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()); } }
desc = registerClassDescriptor(cls, deserialize); assert desc.typeId() == typeId : "Duplicate typeId [typeId=" + typeId + ", cls=" + cls + ", desc=" + desc + "]";
/** * @param val Array of objects. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { if (tryWriteAsHandle(val)) return; BinaryClassDescriptor desc = ctx.descriptorForClass( val.getClass().getComponentType(), false, 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 Class. */ void doWriteClass(@Nullable Class val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(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()); } } }
/** * Creates and registers {@link BinaryClassDescriptor} for the given user {@code class}. * * @param desc Old descriptor that should be re-registered. * @return Class descriptor. */ private BinaryClassDescriptor registerUserClassDescriptor(BinaryClassDescriptor desc) { boolean registered; registered = registerUserClassName(desc.typeId(), desc.describedClass().getName()); if (registered) { BinarySerializer serializer = desc.initialSerializer(); if (serializer == null) serializer = serializerForClass(desc.describedClass()); desc = new BinaryClassDescriptor( this, desc.describedClass(), true, desc.typeId(), desc.typeName(), desc.affFieldKeyName(), desc.mapper(), serializer, true, true ); descByCls.put(desc.describedClass(), desc); } return desc; }
/** * @throws Exception If failed. */ @Test public void testPredefinedTypeIds() throws Exception { BinaryMarshaller marsh = binaryMarshaller(); BinaryContext bCtx = binaryContext(marsh); Field field = bCtx.getClass().getDeclaredField("predefinedTypeNames"); field.setAccessible(true); Map<String, Integer> map = (Map<String, Integer>)field.get(bCtx); assertTrue(!map.isEmpty()); for (Map.Entry<String, Integer> entry : map.entrySet()) { int id = entry.getValue(); if (id == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) continue; BinaryClassDescriptor desc = bCtx.descriptorForTypeId(false, entry.getValue(), null, false); assertEquals(desc.typeId(), bCtx.typeId(desc.describedClass().getName())); } }
/** * @param proxy Proxy. */ public void doWriteProxy(Proxy proxy, Class<?>[] intfs) { if (proxy == null) out.writeByte(GridBinaryMarshaller.NULL); else { out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.PROXY); out.unsafeWriteInt(intfs.length); for (Class<?> intf : intfs) { BinaryClassDescriptor desc = ctx.descriptorForClass(intf, false, failIfUnregistered); if (desc.registered()) out.writeInt(desc.typeId()); else { out.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(intf.getName()); } } InvocationHandler ih = Proxy.getInvocationHandler(proxy); assert ih != null; doWriteObject(ih); } }
desc.describedClass(), false, desc.typeId(), desc.typeName(), desc.affFieldKeyName(), desc0.schema() != null ? Collections.singleton(desc.schema()) : null; BinaryMetadata meta = new BinaryMetadata(desc0.typeId(), desc0.typeName(), desc0.fieldsMeta(), cls.isEnum() ? enumMap(cls) : null); metaHnd.addMeta(desc0.typeId(), meta.wrap(this), false);
/** * @param reader BinaryBuilderReader. */ public BinaryBuilderEnum(BinaryBuilderReader reader) { int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } this.typeId = reader.binaryContext().descriptorForClass(cls, false, false).typeId(); } else { this.typeId = typeId; this.clsName = null; } ordinal = reader.readInt(); }
/** * @param reader Reader. */ protected BinaryObjectArrayLazyValue(BinaryBuilderReader reader) { super(reader, reader.position() - 1); int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } compTypeId = reader.binaryContext().descriptorForClass(cls, true, false).typeId(); } else { compTypeId = typeId; clsName = null; } int size = reader.readInt(); lazyValsArr = new Object[size]; for (int i = 0; i < size; i++) lazyValsArr[i] = reader.parseValue(); }
/** * @param reader Reader. */ protected BinaryEnumArrayLazyValue(BinaryBuilderReader reader) { super(reader, reader.position() - 1); int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } compTypeId = reader.binaryContext().descriptorForClass(cls, true, false).typeId(); } else { compTypeId = typeId; clsName = null; } int size = reader.readInt(); for (int i = 0; i < size; i++) reader.skipValue(); len = reader.position() - valOff; }
this.typeId = ctx.descriptorForClass(cls, false, false).typeId();
typeId = desc.typeId();
/** * @param cls type to examine. * @return true if typeId equals for passed type and current * binary enum. */ public boolean isTypeEquals(final Class<?> cls) { return ctx.descriptorForClass(cls, false, false).typeId() == typeId(); } }
/** * @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.descriptorForClass( val.getClass().getComponentType(), false, 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 Value. */ void doWriteEnum(@Nullable Enum<?> val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val.getDeclaringClass(), false, 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()); } }
/** * @param val Class. */ void doWriteClass(@Nullable Class val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(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 reader BinaryBuilderReader. */ public BinaryBuilderEnum(BinaryBuilderReader reader) { int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } this.typeId = reader.binaryContext().descriptorForClass(cls, false, false).typeId(); } else { this.typeId = typeId; this.clsName = null; } ordinal = reader.readInt(); }