Skip to content

Commit

Permalink
Expose stream protocol method to close Writer (#506)
Browse files Browse the repository at this point in the history
Provides a stream protocol method to close out the resources of the given Writer.

The corresponding Close() method on Reader will be implemented in a follow-up PR.

Refs DR-609
  • Loading branch information
dianale31 authored Jun 28, 2021
1 parent 766cbfa commit c9605ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions gen/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func BenchmarkRoundTrip(b *testing.B) {
give, ok := bb.give.(streamingThriftType)
require.True(b, ok)
require.NoError(b, give.Encode(writer), "StreamEncode")
require.NoError(b, writer.Close(), "Close StreamWriter")
}
}

Expand Down
7 changes: 7 additions & 0 deletions protocol/binary/stream_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,10 @@ func (sw *StreamWriter) WriteMapBegin(m stream.MapHeader) error {
func (sw *StreamWriter) WriteMapEnd() error {
return nil
}

// Close frees up the resources used by the StreamWriter and returns it back
// to the pool.
func (sw *StreamWriter) Close() error {
ReturnStreamWriter(sw)
return nil
}
1 change: 1 addition & 0 deletions protocol/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Writer interface {
WriteSetEnd() error
WriteListBegin(l ListHeader) error
WriteListEnd() error
Close() error
}

// Reader defines an decoder for a Thrift value, implemented in a streaming
Expand Down

0 comments on commit c9605ac

Please sign in to comment.