mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
introduces a new streaming encoder that utilizes a memory allocator during objects serialization
This commit is contained in:
parent
034868e6af
commit
9dd77ac017
@ -134,3 +134,23 @@ func (e *encoder) Encode(obj runtime.Object) error {
|
|||||||
e.buf.Reset()
|
e.buf.Reset()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type encoderWithAllocator struct {
|
||||||
|
writer io.Writer
|
||||||
|
encoder runtime.EncoderWithAllocator
|
||||||
|
memAllocator runtime.MemoryAllocator
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEncoderWithAllocator returns a new streaming encoder
|
||||||
|
func NewEncoderWithAllocator(w io.Writer, e runtime.EncoderWithAllocator, a runtime.MemoryAllocator) Encoder {
|
||||||
|
return &encoderWithAllocator{
|
||||||
|
writer: w,
|
||||||
|
encoder: e,
|
||||||
|
memAllocator: a,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode writes the provided object to the nested writer
|
||||||
|
func (e *encoderWithAllocator) Encode(obj runtime.Object) error {
|
||||||
|
return e.encoder.EncodeWithAllocator(obj, e.writer, e.memAllocator)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user