/** * Deserializes data from the given ArrayView into the given object. * * @param data The ArrayView to deserialize from. * @param target The target object to apply the deserialization to. * @throws IOException If an IO Exception occurred. */ public void deserialize(ArrayView data, ReaderType target) throws IOException { deserialize(data.getReader(), target); }
/** * Deserializes data from the given ArrayView and creates a new object with the result. * * @param data The ArrayView to deserialize from. * @return A new instance of TargetType with the deserialized data. * @throws IOException If an IO Exception occurred. */ public TargetType deserialize(ArrayView data) throws IOException { return deserialize(data.getReader()); }
/** * Deserializes data from the given ArrayView and creates a new object with the result. * * @param data The ArrayView to deserialize from. * @return A new instance of TargetType with the deserialized data. * @throws IOException If an IO Exception occurred. */ public BaseType deserialize(ArrayView data) throws IOException { return deserialize(data.getReader()); }
@SneakyThrows(IOException.class) private DataFrame.DataFrameEntryIterator readFrame(DataFrame dataFrame) { return DataFrame.read(dataFrame.getData().getReader(), dataFrame.getLength(), dataFrame.getAddress()); }
source.getReader(sourceOffset - HEADER_LENGTH, getTotalLength()), getTotalLength())); } else { this.serialization = source;
private ArrayList<LogItem> toDataFrames(ArrayList<TestItem> items) throws Exception { val result = new ArrayList<LogItem>(RECORD_COUNT); Consumer<DataFrame> addCallback = df -> result.add(new LogItem(df.getData().getReader(), df.getData().getLength(), new TestLogAddress(result.size()))); try (val dos = new DataFrameOutputStream(FRAME_SIZE, addCallback)) { for (TestItem item : items) { dos.startNewRecord(); long beginSequence = result.size(); dos.write(item.data); dos.endRecord(); item.address = new TestLogAddress(result.size()); for (long s = beginSequence; s <= item.address.getSequence(); s++) { item.dataFrames.add(s); } } dos.flush(); } return result; }
/** * Tests the ability to append a set of records to a DataFrame, serialize it, deserialize it, and then read those * records back. */ @Test public void testSerialization() throws Exception { int maxFrameSize = 2 * 1024 * 1024; int maxRecordCount = 4500; int minRecordSize = 0; int maxRecordSize = 1024; List<ByteArraySegment> allRecords = DataFrameTestHelpers.generateRecords(maxRecordCount, minRecordSize, maxRecordSize, ByteArraySegment::new); // Append some records. DataFrame writeFrame = DataFrame.ofSize(maxFrameSize); int recordsAppended = appendRecords(allRecords, writeFrame); AssertExtensions.assertGreaterThan("Did not append enough records. Test may not be valid.", allRecords.size() / 2, recordsAppended); writeFrame.seal(); val frameData = writeFrame.getData(); Assert.assertEquals("Unexpected length from getData().", writeFrame.getLength(), frameData.getLength()); // Read them back, by deserializing the frame. val contents = DataFrame.read(frameData.getReader(), frameData.getLength(), writeFrame.getAddress()); DataFrameTestHelpers.checkReadRecords(contents, allRecords, b -> b); }
df.seal(); ArrayView serialization = df.getData(); return new InjectedReadItem(serialization.getReader(), serialization.getLength(), readItem.getAddress());