private JObject ReadDocument(Tuple <MemoryStream, JObject> stream, JsonDocumentMetadata metadata) { if (stream.Item2 != null) { return(stream.Item2); } var memoryStream = stream.Item1; if (documentCodecs.Count() > 0) { byte[] buffer = memoryStream.GetBuffer(); var metadataCopy = new JObject(metadata.Metadata); var dataBuffer = new byte[memoryStream.Length - memoryStream.Position]; Buffer.BlockCopy(buffer, (int)memoryStream.Position, dataBuffer, 0, dataBuffer.Length); documentCodecs.Aggregate(dataBuffer, (bytes, codec) => codec.Value.Decode(metadata.Key, metadataCopy, bytes)); memoryStream = new MemoryStream(dataBuffer); } var result = memoryStream.ToJObject(); storage.SetCachedDocument(metadata.Key, metadata.Etag, Tuple.Create(new JObject(metadata.Metadata), new JObject(result))); return(result); }
private RavenJObject ReadDocument(Tuple <MemoryStream, RavenJObject> stream, JsonDocumentMetadata metadata) { if (stream.Item2 != null) { return(stream.Item2); } RavenJObject result; Stream docDataStream = stream.Item1; if (documentCodecs.Count() > 0) { var metadataCopy = (RavenJObject)metadata.Metadata.CloneToken(); using (docDataStream = documentCodecs.Aggregate(docDataStream, (dataStream, codec) => codec.Value.Decode(metadata.Key, metadataCopy, dataStream))) result = docDataStream.ToJObject(); } else { result = docDataStream.ToJObject(); } Debug.Assert(metadata.Etag != null); documentCacher.SetCachedDocument(metadata.Key, metadata.Etag.Value, result, metadata.Metadata); return(result); }
private RavenJObject ReadDocument(Tuple <MemoryStream, RavenJObject> stream, JsonDocumentMetadata metadata) { if (stream.Item2 != null) { return(stream.Item2); } var memoryStream = stream.Item1; if (documentCodecs.Count() > 0) { byte[] buffer = memoryStream.GetBuffer(); var metadataCopy = (RavenJObject)metadata.Metadata.CloneToken(); var dataBuffer = new byte[memoryStream.Length - memoryStream.Position]; Buffer.BlockCopy(buffer, (int)memoryStream.Position, dataBuffer, 0, dataBuffer.Length); documentCodecs.Aggregate(dataBuffer, (bytes, codec) => codec.Value.Decode(metadata.Key, metadataCopy, bytes)); memoryStream = new MemoryStream(dataBuffer); } var result = memoryStream.ToJObject(); Debug.Assert(metadata.Etag != null); documentCacher.SetCachedDocument(metadata.Key, metadata.Etag.Value, result, metadata.Metadata); return(result); }