Skip to content

Commit

Permalink
Allow nondeterministic object encoding in HTTP response bodies.
Browse files Browse the repository at this point in the history
Kubernetes-commit: dee76a460ec80f15dc199c93e506586687d42291
  • Loading branch information
benluddy authored and k8s-publishing-bot committed Oct 28, 2024
1 parent c56b207 commit 42acd35
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/runtime/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,21 @@ func (e *encoderWithAllocator) Encode(obj Object, w io.Writer) error {
func (e *encoderWithAllocator) Identifier() Identifier {
return e.encoder.Identifier()
}

type nondeterministicEncoderToEncoderAdapter struct {
NondeterministicEncoder
}

func (e nondeterministicEncoderToEncoderAdapter) Encode(obj Object, w io.Writer) error {
return e.EncodeNondeterministic(obj, w)
}

// UseNondeterministicEncoding returns an Encoder that encodes objects using the provided Encoder's
// EncodeNondeterministic method if it implements NondeterministicEncoder, otherwise it returns the
// provided Encoder as-is.
func UseNondeterministicEncoding(encoder Encoder) Encoder {
if nondeterministic, ok := encoder.(NondeterministicEncoder); ok {
return nondeterministicEncoderToEncoderAdapter{nondeterministic}
}
return encoder
}

0 comments on commit 42acd35

Please sign in to comment.