Documentation
¶
Index ¶
- Variables
- func DecodeBytes(ctx context.Context, dec Decoder, data []byte) (runtime.Value, error)
- func EncodeBytes(ctx context.Context, enc Encoder, value runtime.Value) ([]byte, error)
- func WithReadOnlyRegistry(ctx context.Context, registry *Registry) context.Context
- func WithRegistry(ctx context.Context, registry *Registry) context.Context
- type Codec
- type CodecRegistrar
- type CodecResolver
- type Consumer
- type Content
- type Decoder
- type DecoderConfigurer
- type Encoder
- type EncoderConfigurer
- type Metadata
- type Output
- type PostDecoderHook
- type PostEncoderHook
- type PreDecoderHook
- type PreEncoderHook
- type Registry
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilRegistry = errors.New("encoding: registry is nil") ErrNilCodec = errors.New("encoding: codec is nil") ErrEmptyContentType = errors.New("encoding: content type is empty") ErrCodecNotFound = errors.New("encoding: codec not found") ErrRegistryNotFound = errors.New("encoding: registry not found in context") )
var ( // ErrOutputInUse identifies a competing consumption attempt. ErrOutputInUse = result.ErrInUse // ErrOutputClosed identifies consumption after stopping, or interrupted by Close. ErrOutputClosed = result.ErrClosed )
Functions ¶
func DecodeBytes ¶
DecodeBytes decodes a complete byte document through the reader-based API.
func EncodeBytes ¶
EncodeBytes collects an encoder's writes into caller-owned bytes, including any prefix written before an error. Publish the bytes only on success when whole-document output must be atomic.
func WithReadOnlyRegistry ¶
WithReadOnlyRegistry adds a finalized registry to the context. Lookup helpers share the registered codecs, and RegistryFrom returns a shallow snapshot of the registrations. The caller must keep the original registrations fixed.
Types ¶
type CodecRegistrar ¶
CodecRegistrar registers codecs by content type.
type CodecResolver ¶
type CodecResolver interface {
Codec(contentType string) (Codec, error)
Encoder(contentType string) (Encoder, error)
Decoder(contentType string) (Decoder, error)
}
CodecResolver looks up registered codecs and their encoding and decoding capabilities.
type Decoder ¶
type Decoder interface {
Decode(ctx context.Context, src io.Reader) (runtime.Value, error)
DecodeWith() DecoderConfigurer
}
Decoder reads one complete document into a materialized runtime value. It borrows src only until Decode returns and must not close or retain it, or read asynchronously. It may buffer and read ahead. Failure may consume part or all of src. The caller owns the reader's lifecycle. Context is propagated, but cannot interrupt arbitrary blocking reader implementations. Nil contexts and readers must return an error wrapping runtime.ErrInvalidArgument. Decoders reject extra roots, malformed input, and truncated containers.
type DecoderConfigurer ¶
type DecoderConfigurer interface {
PreHook(PreDecoderHook) DecoderConfigurer
PostHook(PostDecoderHook) DecoderConfigurer
Decoder() Decoder
}
type Encoder ¶
type Encoder interface {
Encode(ctx context.Context, dst io.Writer, value runtime.Value) error
EncodeWith() EncoderConfigurer
}
Encoder writes a runtime value to a borrowed writer using the caller's context. It must not close or retain the writer, or use it after returning. Write buffers may be reused after Write returns, as required by io.Writer. Success completes all codec-owned writes and flushing; the caller owns flushing, finalizing, and closing its own wrappers. Failure may leave a prefix in dst. Use EncodeBytes and publish only on success for atomic output. Codecs may buffer internally and cannot interrupt arbitrary blocking I/O. Nil contexts and writers must return an error wrapping runtime.ErrInvalidArgument. Preserve non-nil I/O errors; incomplete writes without an error return io.ErrShortWrite and stop without retrying.
type EncoderConfigurer ¶
type EncoderConfigurer interface {
PreHook(PreEncoderHook) EncoderConfigurer
PostHook(PostEncoderHook) EncoderConfigurer
Encoder() Encoder
}
type Output ¶
Output is a caller-owned, one-shot encoded output handle. Consume or Collect observes its terminal outcome; Close abandons it and reports cleanup errors.
type PostDecoderHook ¶
PostDecoderHook runs once after decoding, with the decoded value on success or runtime.None on failure. Hooks run in order and stop on the first error.
type PostEncoderHook ¶
PostEncoderHook runs after each visited value, including on encoding failure. Ancestor hooks receive descendant failures. Hooks stop on the first error.
type PreDecoderHook ¶
PreDecoderHook runs once before decoding, without consuming the input. Returning an error skips decoding and post-hooks.
type PreEncoderHook ¶
PreEncoderHook runs before each visited value, in registration order. Returning an error skips that value's encoding and post-hooks.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores codecs by content type.
func NewEmptyRegistry ¶
func NewEmptyRegistry() *Registry
NewEmptyRegistry creates a registry without predefined codecs.
func NewRegistry ¶
NewRegistry creates a registry seeded with the provided codecs.
func RegistryFrom ¶
RegistryFrom gets the registry from the context. A registry bound with WithRegistry is returned directly. A registry bound with WithReadOnlyRegistry is cloned, so edits to the returned registrations are local to the clone. Codec instances are shared in both cases.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
codecutil
Package codecutil owns the built-in codecs' bounded I/O, cancellation checkpoints, borrowed adoption callbacks, and acquired iterator cleanup.
|
Package codecutil owns the built-in codecs' bounded I/O, cancellation checkpoints, borrowed adoption callbacks, and acquired iterator cleanup. |