/// <summary> /// Make a complete payload from <see cref="FbnsConnectionData"/> using Thrift. /// </summary> /// <returns>Payload</returns> public static async Task <IByteBuffer> BuildPayload(FbnsConnectionData data) { _memoryBufferTransport = new TMemoryBufferTransport(); _thrift = new TCompactProtocol(_memoryBufferTransport); _payloadData = data; var rawPayload = await ToThrift(); // zlib deflate var dataStream = new MemoryStream(512); using (var zlibStream = new ZlibStream(dataStream, CompressionMode.Compress, CompressionLevel.Level9, true)) { await zlibStream.WriteAsync(rawPayload, 0, rawPayload.Length); } var readData = new byte[dataStream.Length]; dataStream.Position = 0; await dataStream.ReadAsync(readData, 0, readData.Length); dataStream.Dispose(); var compressed = Unpooled.CopiedBuffer(readData); return(compressed); }
/// <summary> /// Make a complete payload from <see cref="FbnsConnectionData"/> using Thrift. /// </summary> /// <returns>Payload</returns> public static async Task <IBuffer> BuildPayload(FbnsConnectionData data) { _memoryBufferTransport = new TMemoryBufferTransport(); _thrift = new TCompactProtocol(_memoryBufferTransport); _payloadData = data; var rawPayload = await ToThrift(); // zlib deflate var dataStream = new MemoryStream(512); using (var zlibStream = new ZlibStream(dataStream, CompressionMode.Compress, CompressionLevel.Level9, true)) { await zlibStream.WriteAsync(rawPayload, 0, rawPayload.Length); } var compressed = dataStream.GetWindowsRuntimeBuffer(0, (int)dataStream.Length); return(compressed); }