Source File
decode_stream_pool.go
Belonging Package
github.com/francoispqt/gojay
package gojayimport ()var streamDecPool = sync.Pool{New: newStreamDecoderPool,}// NewDecoder returns a new StreamDecoder.// It takes an io.Reader implementation as data input.// It initiates the done channel returned by Done().func ( stream) ( io.Reader) *StreamDecoder {:= NewDecoder():= &StreamDecoder{Decoder: ,done: make(chan struct{}, 1),mux: sync.RWMutex{},}return}func newStreamDecoderPool() interface{} {return Stream.NewDecoder(nil)}// BorrowDecoder borrows a StreamDecoder from the pool.// It takes an io.Reader implementation as data input.// It initiates the done channel returned by Done().//// If no StreamEncoder is available in the pool, it returns a fresh onefunc ( stream) ( io.Reader) *StreamDecoder {return .borrowDecoder(, 512)}func ( stream) ( io.Reader, int) *StreamDecoder {:= streamDecPool.Get().(*StreamDecoder).called = 0.keysDone = 0.cursor = 0.err = nil.r =.length = 0.isPooled = 0.done = make(chan struct{}, 1)if > 0 {.data = make([]byte, )}return}// Release sends back a Decoder to the pool.// If a decoder is used after calling Release// a panic will be raised with an InvalidUsagePooledDecoderError error.func ( *StreamDecoder) () {.isPooled = 1streamDecPool.Put()}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |