static public FlexReadBuffer Deserialize(LogReader S, FlexReadBuffer flexBuf) { var messageSize = S.ReadInt(flexBuf._sizeBuf); flexBuf._curSize = messageSize.Item1 + messageSize.Item2; flexBuf._curSizeSize = messageSize.Item2; if (flexBuf.Buffer != null) { throw new Exception("Flexbuffer should have been null in Deserialize"); } flexBuf.GetBuffer(); var bytesRead = S.ReadAllRequiredBytes(flexBuf._buffer, messageSize.Item2, messageSize.Item1); if (bytesRead < messageSize.Item1) { throw new Exception("Error deserializing buffer in stream"); } return(flexBuf); }
static public async Task <FlexReadBuffer> DeserializeAsync(LogReader S, FlexReadBuffer flexBuf) { var intReaderTask = S.ReadIntAsync(flexBuf._sizeBuf); var messageSize = await intReaderTask; flexBuf._curSize = messageSize.Item1 + messageSize.Item2; flexBuf._curSizeSize = messageSize.Item2; if (flexBuf.Buffer != null) { throw new Exception("Flexbuffer should have been null in Deserialize"); } flexBuf.GetBuffer(); var bytesReaderTask = S.ReadAllRequiredBytesAsync(flexBuf._buffer, messageSize.Item2, messageSize.Item1); var bytesRead = await bytesReaderTask; if (bytesRead < messageSize.Item1) { throw new Exception("Error deserializing buffer in stream"); } return(flexBuf); }
internal static void ReadBig(this LogReader reader, Stream writeToStream, long checkpointSize) { var blockSize = 1024 * 1024; var buffer = new byte[blockSize]; while (checkpointSize > 0) { int bytesRead; if (checkpointSize >= blockSize) { bytesRead = reader.Read(buffer, 0, blockSize); } else { bytesRead = reader.Read(buffer, 0, (int)checkpointSize); } writeToStream.Write(buffer, 0, bytesRead); checkpointSize -= bytesRead; } }