Skip to content

Commit 42acd35

Browse files
benluddyk8s-publishing-bot
authored andcommitted
Allow nondeterministic object encoding in HTTP response bodies.
Kubernetes-commit: dee76a460ec80f15dc199c93e506586687d42291
1 parent c56b207 commit 42acd35

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/runtime/helper.go

+18
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,21 @@ func (e *encoderWithAllocator) Encode(obj Object, w io.Writer) error {
284284
func (e *encoderWithAllocator) Identifier() Identifier {
285285
return e.encoder.Identifier()
286286
}
287+
288+
type nondeterministicEncoderToEncoderAdapter struct {
289+
NondeterministicEncoder
290+
}
291+
292+
func (e nondeterministicEncoderToEncoderAdapter) Encode(obj Object, w io.Writer) error {
293+
return e.EncodeNondeterministic(obj, w)
294+
}
295+
296+
// UseNondeterministicEncoding returns an Encoder that encodes objects using the provided Encoder's
297+
// EncodeNondeterministic method if it implements NondeterministicEncoder, otherwise it returns the
298+
// provided Encoder as-is.
299+
func UseNondeterministicEncoding(encoder Encoder) Encoder {
300+
if nondeterministic, ok := encoder.(NondeterministicEncoder); ok {
301+
return nondeterministicEncoderToEncoderAdapter{nondeterministic}
302+
}
303+
return encoder
304+
}

0 commit comments

Comments
 (0)