encoding

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(codec Codec, v any) ([]byte, error)

func Unmarshal

func Unmarshal(codec Codec, data []byte, v any) error

Types

type Codec

type Codec interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
}

type InputPayload

type InputPayload struct {
	Required    bool        `json:"required"`
	ContentType *string     `json:"contentType,omitempty"`
	JsonSchema  interface{} `json:"jsonSchema,omitempty"`
}

func InputPayloadFor

func InputPayloadFor(codec PayloadCodec, i any) *InputPayload

type OutputPayload

type OutputPayload struct {
	ContentType           *string     `json:"contentType,omitempty"`
	SetContentTypeIfEmpty bool        `json:"setContentTypeIfEmpty"`
	JsonSchema            interface{} `json:"jsonSchema,omitempty"`
}

func OutputPayloadFor

func OutputPayloadFor(codec PayloadCodec, o any) *OutputPayload

type PayloadCodec

type PayloadCodec interface {
	InputPayload() *InputPayload
	OutputPayload() *OutputPayload
	Codec
}
var (
	// BinaryCodec marshals []byte and unmarshals into *[]byte
	// In handlers, it uses a content type of application/octet-stream
	BinaryCodec PayloadCodec = binaryCodec{}
	// VoidCodec marshals anything into []byte(nil) and skips unmarshaling
	// In handlers, it requires that there is no input content-type and does not set an output content-type
	VoidCodec PayloadCodec = voidCodec{}
	// ProtoCodec marshals proto.Message and unmarshals into proto.Message or pointers to types that implement proto.Message
	// In handlers, it uses a content-type of application/proto
	ProtoCodec PayloadCodec = protoCodec{}
	// JSONCodec marshals any json.Marshallable type and unmarshals into any json.Unmarshallable type
	// In handlers, it uses a content-type of application/json
	JSONCodec PayloadCodec = jsonCodec{}
)

type RestateMarshaler

type RestateMarshaler interface {
	RestateMarshal(codec Codec) ([]byte, error)
	OutputPayload(codec Codec) *OutputPayload
}

RestateMarshaler can be implemented by types that want to control their own marshaling

func RestateMarshalerFor

func RestateMarshalerFor[O any]() (RestateMarshaler, bool)

type RestateUnmarshaler

type RestateUnmarshaler interface {
	RestateUnmarshal(codec Codec, data []byte) error
	InputPayload(codec Codec) *InputPayload
}

type Void

type Void struct{}

Void is a placeholder to signify 'no value' where a type is otherwise needed

func (Void) InputPayload

func (v Void) InputPayload(codec Codec) *InputPayload

func (Void) OutputPayload

func (v Void) OutputPayload(codec Codec) *OutputPayload

func (Void) RestateMarshal

func (v Void) RestateMarshal(codec Codec) ([]byte, error)

func (Void) RestateUnmarshal

func (v Void) RestateUnmarshal(codec Codec, data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL