Documentation
¶
Overview ¶
Package codec provides an implementation of marshalkit.Marshaler that uses a set of priority-ordered codecs to marshal and unmarshal types and values.
Index ¶
- type Capabilities
- type Codec
- type Marshaler
- func (m *Marshaler) Marshal(v any) (marshalkit.Packet, error)
- func (m *Marshaler) MarshalAs(v any, mediaTypes []string) (p marshalkit.Packet, ok bool, err error)
- func (m *Marshaler) MarshalType(rt reflect.Type) (string, error)
- func (m *Marshaler) MediaTypesFor(rt reflect.Type) []string
- func (m *Marshaler) Unmarshal(p marshalkit.Packet) (any, error)
- func (m *Marshaler) UnmarshalType(n string) (reflect.Type, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities struct {
// Types is a map of the supported types to their portable type name.
Types map[reflect.Type]string
}
Capabilities describes the capabilities of a codec as it relates to specific Go types.
type Codec ¶
type Codec interface {
// Query returns the capabilities of the codec for the given types.
Query(types []reflect.Type) Capabilities
// BasicMediaType returns the type and subtype portion of the media-type
// used to identify data encoded by this codec.
BasicMediaType() string
// Marshal returns the binary representation of v.
Marshal(v any) ([]byte, error)
// Unmarshal decodes a binary representation into v.
Unmarshal(data []byte, v any) error
}
Codec is an interface for encoding and decoding values.
type Marshaler ¶
type Marshaler struct {
// contains filtered or unexported fields
}
Marshaler uses a set of priority-ordered codecs to marshal and unmarshal types and values.
func NewMarshaler ¶
NewMarshaler returns a new marshaler that uses the given set of codecs to marshal and unmarshal values.
The codecs are given in order of preference.
func (*Marshaler) Marshal ¶
func (m *Marshaler) Marshal(v any) (marshalkit.Packet, error)
Marshal returns a binary representation of v.
func (*Marshaler) MarshalAs ¶ added in v0.5.0
func (m *Marshaler) MarshalAs( v any, mediaTypes []string, ) (p marshalkit.Packet, ok bool, err error)
MarshalAs returns a binary representation of v encoded using a format associated with one of the supplied media-types.
mediaTypes is a list of acceptible media-types, in order of preference. If none of the media-types are supported, ok is false.
func (*Marshaler) MarshalType ¶
MarshalType marshals a type to its portable representation.
func (*Marshaler) MediaTypesFor ¶ added in v0.5.0
MediaTypesFor returns the media-types that the marshaler can use to represent the given type, in order of preference.
It returns an empty slice if the type is not supported.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
portablename
Package portablename generates portable names for arbitrary types.
|
Package portablename generates portable names for arbitrary types. |
|
Package json contains a codec that uses Go's standard JSON marshaling.
|
Package json contains a codec that uses Go's standard JSON marshaling. |
|
Package protobuf contains codec implementations for protocol buffers types.
|
Package protobuf contains codec implementations for protocol buffers types. |
|
Package stateless contains a codec implementation for dogma.StatelessProcessRoot values.
|
Package stateless contains a codec implementation for dogma.StatelessProcessRoot values. |