コード例 #1
0
            internal MemoryStream SerializeWithHeader <T>(T value, CompressionMethod compression)
            {
                RecyclableMemoryStream ms = (RecyclableMemoryStream)RecyclableMemoryStreamManager.Default.GetStream("JSON.SerializeWithHeader", 4096, true);

                ms.WriteAsPtr(0L);
                using (var writer = new StreamWriter(ms, Encoding.UTF8, 4096, true))
                    using (var jsonwriter = new JsonTextWriter(writer))
                    {
                        jsonwriter.ArrayPool = JsonNetArrayPool.Pool;
                        _serializer.Serialize(writer, value);
                    }
                // we created the stream with initial positoin 0, return to that position
                if (compression == CompressionMethod.DefaultOrNone)
                {
                    ms.Position = 0;
                    ms.WriteAsPtr(checked ((int)ms.Length));
                    ms.Position = 0;
                    return(ms);
                }
                else
                {
                    //foreach (var chunk in ms.Chunks)
                    //{
                    //    if (chunk.Count != ms.Length)
                    //    {
                    //        throw new NotImplementedException("TODO JSON compression");
                    //    }
                    //    CompressedArrayBinaryConverter<byte>.Instance.Write(chunk,)

                    //}
                    throw new NotImplementedException("TODO JSON compression");
                    // max buffer
                    //var buffer = BufferPool<byte>.Rent(8 + 16 + (Environment.ProcessorCount * 4) + checked((int)ms.Length));
                    //var array = ms.ToArray();
                    //ms.Dispose();
                    //CompressedArrayBinaryConverter<byte>.Instance.Write(array,)
                }
            }