Esempio n. 1
0
        private JSONDocument DeserializeDocument(byte[] data)
        {
            var stream = new ClusteredMemoryStream(data);
            int header = stream.ReadByte();

            if ((header & (long)PersistenceBits.Compressed) == (decimal)PersistenceBits.Compressed)
            {
                stream = CompressionUtil.Decompress(stream);
            }
            var document = JSONDocument.Deserialize(stream);// CompactBinaryFormatter.Deserialize(stream, string.Empty);

            stream.Dispose();
            return(document as JSONDocument);
        }
Esempio n. 2
0
        private byte[] SerializeDocument(JSONDocument document)
        {
            Stream stream = new ClusteredMemoryStream();

            JSONDocument.Serialize(stream, document);
            stream.Position = 0;
            if (enableCompression)
            {
                stream = CompressionUtil.Compress(stream);
            }

            var array = new byte[stream.Length + 1];

            if (enableCompression)
            {
                array[0] |= (byte)PersistenceBits.Compressed;
            }

            stream.Read(array, 1, (int)stream.Length);
            stream.Dispose();
            return(array);
        }