datacodec

package
v2.15.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Overview

Package datacodec holds the data codec registry and adds known encoders and decoders supporting media types such as `application/json` and `application/xml`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDecoder

func AddDecoder(contentType string, fn Decoder)

AddDecoder registers a decoder for a given content type. The codecs will use these to decode the data payload from a cloudevent.Event object.

func AddEncoder

func AddEncoder(contentType string, fn Encoder)

AddEncoder registers an encoder for a given content type. The codecs will use these to encode the data payload for a cloudevent.Event object.

func Decode

func Decode(ctx context.Context, contentType string, in []byte, out interface{}) error

Decode looks up and invokes the decoder registered for the given content type. An error is returned if no decoder is registered for the given content type.

func Encode

func Encode(ctx context.Context, contentType string, in interface{}) ([]byte, error)

Encode looks up and invokes the encoder registered for the given content type. An error is returned if no encoder is registered for the given content type.

Types

type Decoder

type Decoder func(ctx context.Context, in []byte, out interface{}) error

Decoder is the expected function signature for decoding `in` to `out`. If Event sent the payload as base64, Decoder assumes that `in` is the decoded base64 byte array.

type Encoder

type Encoder func(ctx context.Context, in interface{}) ([]byte, error)

Encoder is the expected function signature for encoding `in` to bytes. Returns an error if the encoder has an issue encoding `in`.

Directories

Path Synopsis
Package json holds the encoder/decoder implementation for `application/json`.
Package json holds the encoder/decoder implementation for `application/json`.
Package text holds the encoder/decoder implementation for `text/plain`.
Package text holds the encoder/decoder implementation for `text/plain`.
Package xml holds the encoder/decoder implementation for `application/xml`.
Package xml holds the encoder/decoder implementation for `application/xml`.

Jump to

Keyboard shortcuts

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