/** {@inheritDoc} */ @Override public KeyCacheObject copy(int part) { if (this.part == part) return this; BinaryObjectImpl cp = new BinaryObjectImpl(ctx, arr, start); cp.part = part; return cp; }
/** * @return Heap-based copy. */ public BinaryObject heapCopy() { return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start); }
/** {@inheritDoc} */ @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception { byte[] bytes = marsh.marshal(obj); return new BinaryObjectImpl(ctx, bytes, 0); } }
/** * @return Detached binary object. */ public BinaryObjectImpl detach() { if (!detachAllowed || detached()) return this; int len = length(); byte[] arr0 = new byte[len]; U.arrayCopy(arr, start, arr0, 0, len); return new BinaryObjectImpl(ctx, arr0, 0); }
/** {@inheritDoc} */ @Override public KeyCacheObject toKeyCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) throws IgniteCheckedException { switch (type) { case BinaryObjectImpl.TYPE_BINARY: return new BinaryObjectImpl(binaryContext(), bytes, 0); case CacheObject.TYPE_BYTE_ARR: throw new IllegalArgumentException("Byte arrays cannot be used as cache keys."); case CacheObject.TYPE_REGULAR: return new KeyCacheObjectImpl(ctx.kernalContext().cacheObjects().unmarshal(ctx, bytes, null), bytes, -1); } throw new IllegalArgumentException("Invalid object type: " + type); }
/** * @param fieldId Field ID. * @return Binary object. * @throws BinaryObjectException In case of error. */ @Nullable BinaryObject readBinaryObject(int fieldId) throws BinaryObjectException { if (findFieldById(fieldId)) { if (checkFlag(BINARY_OBJ) == Flag.NULL) return null; return new BinaryObjectImpl(ctx, BinaryUtils.doReadByteArray(in), in.readInt()); } else return null; }
/** {@inheritDoc} */ @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) { switch (type) { case BinaryObjectImpl.TYPE_BINARY: return new BinaryObjectImpl(binaryContext(), bytes, 0); case BinaryObjectImpl.TYPE_BINARY_ENUM: return new BinaryEnumObjectImpl(binaryContext(), bytes); case CacheObject.TYPE_BYTE_ARR: return new CacheObjectByteArrayImpl(bytes); case CacheObject.TYPE_REGULAR: return new CacheObjectImpl(null, bytes); } throw new IllegalArgumentException("Invalid object type: " + type); }
/** {@inheritDoc} */ @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception { byte[] bytes = marsh.marshal(obj); return new BinaryObjectImpl(binaryContext(marsh), bytes, 0); } }
/** * @param obj Object to transform to a binary object. * @param marsh Binary marshaller. * @return Binary object. */ protected BinaryObjectImpl toBinary(Object obj, BinaryMarshaller marsh) throws Exception { byte[] bytes = marsh.marshal(obj); return new BinaryObjectImpl(binaryContext(marsh), bytes, 0); }
/** {@inheritDoc} */ @Override public BinaryObject build() { try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { Thread curThread = Thread.currentThread(); if (curThread instanceof IgniteThread) writer.failIfUnregistered(((IgniteThread)curThread).isForbiddenToRequestBinaryMetadata()); writer.typeId(typeId); BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer(); serializationCtx.registerObjectWriting(this, 0); serializeTo(writer, serializationCtx); byte[] arr = writer.array(); return new BinaryObjectImpl(ctx, arr, 0); } }
/** * @param obj Object. * @param marsh Marshaller. * @return Binary object. */ private <T> BinaryObjectImpl marshal(T obj, BinaryMarshaller marsh) throws IgniteCheckedException { byte[] bytes = marsh.marshal(obj); return new BinaryObjectImpl(U.<GridBinaryMarshaller>field(marsh, "impl").context(), bytes, 0); }
/** * Perform post-write hash code update if necessary. * * @param clsName Class name. Always null if class is registered. */ public void postWriteHashCode(@Nullable String clsName) { int typeId = clsName == null ? this.typeId : ctx.typeId(clsName); BinaryIdentityResolver identity = ctx.identity(typeId); if (out.hasArray()) { // Heap. byte[] data = out.array(); BinaryObjectImpl obj = new BinaryObjectImpl(ctx, data, start); BinaryPrimitives.writeInt(data, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } else { // Offheap. long ptr = out.rawOffheapPointer(); assert ptr != 0; BinaryObjectOffheapImpl obj = new BinaryObjectOffheapImpl(ctx, ptr, start, out.capacity()); BinaryPrimitives.writeInt(ptr, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } }
/** * @return Value. */ public static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach) { if (in.offheapPointer() > 0) { int len = in.readInt(); int pos = in.position(); in.position(in.position() + len); int start = in.readInt(); return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len); } else { byte[] arr = doReadByteArray(in); int start = in.readInt(); BinaryObjectImpl binO = new BinaryObjectImpl(ctx, arr, start); if (detach) { binO.detachAllowed(true); return binO.detach(); } return binO; } }
BinaryObjectImpl binaryObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
BinaryObjectImpl binaryObj = new BinaryObjectImpl(ctx, arr, pos - 4 - size + start);
po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0); po = new BinaryObjectImpl(ctx, in.array(), start); else po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
/** {@inheritDoc} */ @Override public KeyCacheObject copy(int part) { if (this.part == part) return this; BinaryObjectImpl cp = new BinaryObjectImpl(ctx, arr, start); cp.part = part; return cp; }
/** * @return Heap-based copy. */ public BinaryObject heapCopy() { return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start); }
msg = new BinaryObjectImpl();
/** * @return Detached binary object. */ public BinaryObjectImpl detach() { if (!detachAllowed || detached()) return this; int len = length(); byte[] arr0 = new byte[len]; U.arrayCopy(arr, start, arr0, 0, len); return new BinaryObjectImpl(ctx, arr0, 0); }