File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ enum Zlib {
57
57
// by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH are used.
58
58
let upperBound = CGRPCZlib_deflateBound ( & self . stream. zstream, UInt ( input. readableBytes) )
59
59
60
- // Note: readWithUnsafeMutableReadableBytes leads to an assertion whenever used
61
- // while the writer is bigger than the reader
62
- return try input. withUnsafeMutableReadableBytes { inputPointer in
60
+ return try input. readWithUnsafeMutableReadableBytes { inputPointer -> ( Int , Int ) in
63
61
64
62
self . stream. nextInputBuffer = CGRPCZlib_castVoidToBytefPointer ( inputPointer. baseAddress!)
65
63
self . stream. availableInputBytes = inputPointer. count
@@ -69,12 +67,15 @@ enum Zlib {
69
67
self . stream. availableInputBytes = 0
70
68
}
71
69
72
- return try output. writeWithUnsafeMutableBytes ( minimumWritableBytes: Int ( upperBound) ) { outputPointer in
70
+ let writtenBytes = try output. writeWithUnsafeMutableBytes ( minimumWritableBytes: Int ( upperBound) ) { outputPointer in
73
71
try self . stream. deflate (
74
72
outputBuffer: CGRPCZlib_castVoidToBytefPointer ( outputPointer. baseAddress!) ,
75
73
outputBufferSize: outputPointer. count
76
74
)
77
75
}
76
+
77
+ let bytesRead = inputPointer. count - self . stream. availableInputBytes
78
+ return ( bytesRead, writtenBytes)
78
79
}
79
80
}
80
81
Original file line number Diff line number Diff line change @@ -50,8 +50,7 @@ internal struct LengthPrefixedMessageWriter {
50
50
/// - Precondition: `compression.supported` is `true`.
51
51
/// - Note: See `LengthPrefixedMessageReader` for more details on the format.
52
52
func write( _ payload: GRPCPayload , into buffer: inout ByteBuffer , disableCompression: Bool = false ) throws {
53
- buffer. reserveCapacity ( MemoryLayout . size ( ofValue: payload) + LengthPrefixedMessageWriter. metadataLength)
54
-
53
+ buffer. reserveCapacity ( buffer. writerIndex + LengthPrefixedMessageWriter. metadataLength)
55
54
if !disableCompression, let compressor = self . compressor {
56
55
// Set the compression byte.
57
56
buffer. writeInteger ( UInt8 ( 1 ) )
You can’t perform that action at this time.
0 commit comments