/** * @return The marshaller context. */ public BinaryContext context() { return impl.context(); }
/** * Deserializes Ignite binary object from input stream. * * @return Binary object. */ public <T> T unmarshal(BinaryInputStream in) { return impl.unmarshal(in); }
/** * Sets {@link BinaryContext}. * <p/> * @param ctx Binary context. */ private void setBinaryContext(BinaryContext ctx, IgniteConfiguration cfg) { ctx.configure(this, cfg); impl = new GridBinaryMarshaller(ctx); }
/** * @param in Input stream. * @return Binary object. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ @Nullable public <T> T unmarshal(BinaryInputStream in) throws BinaryObjectException { BinaryContext oldCtx = pushContext(ctx); try { return (T)BinaryUtils.unmarshal(in, ctx, null); } finally { popContext(oldCtx); } }
if (binaryMarsh.mustDeserialize(obj)) return obj; // No need to go through marshal-unmarshal because result will be the same as initial object. byte[] arr = binaryMarsh.marshal(obj, failIfUnregistered); Object obj0 = binaryMarsh.unmarshal(arr, null);
/** * Serializes Java object into a byte array. */ public byte[] marshal(Object obj) { return impl.marshal(obj, false); }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ctx = GridBinaryMarshaller.threadLocalContext(); typeId = in.readInt(); clsName = (String)in.readObject(); ord = in.readInt(); }
/** {@inheritDoc} */ @Override protected <T> T unmarshal0(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { return impl.deserialize(bytes, clsLdr); }
/** * Push binary context and return the old one. * * @return Old binary context. */ public BinaryContext pushContext() { return pushContext(ctx); }
/** * @param bytes Bytes array. * @return Binary object. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException { assert bytes != null; BinaryContext oldCtx = pushContext(ctx); try { return (T) BinaryUtils.unmarshal(BinaryHeapInputStream.create(bytes, 0), ctx, clsLdr); } finally { popContext(oldCtx); } }
if (binaryMarsh.mustDeserialize(obj)) return obj; // No need to go through marshal-unmarshal because result will be the same as initial object. byte[] arr = binaryMarsh.marshal(obj, failIfUnregistered); Object obj0 = binaryMarsh.unmarshal(arr, null);
/** * @param obj Object. * @return Bytes. * @throws BinaryObjectException If failed. */ public byte[] marshal(@Nullable Object obj) throws BinaryObjectException { byte[] arr = binaryMarsh.marshal(obj, false); assert arr.length > 0; return arr; }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ctx = GridBinaryMarshaller.threadLocalContext(); arr = new byte[in.readInt()]; in.readFully(arr); start = in.readInt(); } /** {@inheritDoc} */
/** {@inheritDoc} */ @Override protected <T> T unmarshal0(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); // we have to fully read the InputStream because GridBinaryMarshaller requires support of a method that // returns number of bytes remaining. try { byte[] arr = new byte[4096]; int cnt; while ((cnt = in.read(arr)) != -1) buf.write(arr, 0, cnt); buf.flush(); return impl.deserialize(buf.toByteArray(), clsLdr); } catch (IOException e) { throw new BinaryObjectException("Failed to unmarshal the object from InputStream", e); } }
/** * Push binary context and return the old one. * * @return Old binary context. */ public BinaryContext pushContext() { return pushContext(ctx); }
/** {@inheritDoc} */ @Override public void onUndeploy(ClassLoader ldr) { impl.context().onUndeploy(ldr); }
/** * @param ptr Off-heap pointer. * @param forceHeap If {@code true} creates heap-based object. * @return Object. * @throws BinaryObjectException If failed. */ public Object unmarshal(long ptr, boolean forceHeap) throws BinaryObjectException { assert ptr > 0 : ptr; int size = GridUnsafe.getInt(ptr); ptr += 4; byte type = GridUnsafe.getByte(ptr++); if (type != CacheObject.TYPE_BYTE_ARR) { assert size > 0 : size; BinaryInputStream in = new BinaryOffheapInputStream(ptr, size, forceHeap); return binaryMarsh.unmarshal(in); } else return U.copyMemory(ptr, size); }
/** * @param arr Byte array. * @param ldr Class loader. * @return Deserialized object. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException { assert arr != null; assert arr.length > 0; if (arr[0] == NULL) return null; BinaryContext oldCtx = pushContext(ctx); try { return (T)new BinaryReaderExImpl(ctx, BinaryHeapInputStream.create(arr, 0), ldr, true).deserialize(); } finally { popContext(oldCtx); } }