Skip to content

Commit

Permalink
Merge pull request #128456 from benluddy/nondeterministic-response-en…
Browse files Browse the repository at this point in the history
…coding

KEP-4222: Allow nondeterministic object encoding in HTTP response bodies.

Kubernetes-commit: dc1d7f41ef4765552193c10cf1c1ed2b0c4e149b
  • Loading branch information
k8s-publishing-bot committed Oct 30, 2024
2 parents c56b207 + 42acd35 commit a25029a
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 a25029a

Please sign in to comment.