/** * Deserialize from given byte array into given writable, * using given reusable UnsafeReusableByteArrayInput. * * @param data Byte array representing writable * @param to Object to fill * @param reusableInput Reusable input to use * @param <T> Type of the object */ public static <T extends Writable> void fromByteArrayUnsafe( byte[] data, T to, UnsafeReusableByteArrayInput reusableInput) { try { reusableInput.initialize(data, 0, data.length); to.readFields(reusableInput); if (reusableInput.available() != 0) { throw new RuntimeException( "Serialization encountered issues, " + reusableInput.available() + " bytes left to be read"); } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public M next() { long pointer = iterator.nextLong(); try { int index = (int) (pointer >>> 32); int offset = (int) pointer; ExtendedDataOutput buffer = msgBuffer.getDataOutput(index); messageReader.initialize(buffer.getByteArray(), offset, buffer.getPos()); reusableMsg.readFields(messageReader); } catch (IOException e) { throw new IllegalStateException("Got exception : " + e); } return reusableMsg; }
reusableOut.reset(); original.write(reusableOut); reusableIn.initialize( reusableOut.getByteArray(), 0, reusableOut.getPos()); copy.readFields(reusableIn);