datacodec

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
var (
	// LatencyMs measures the latency in milliseconds for the CloudEvents generic
	// codec data methods.
	LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/latency", "The latency in milliseconds for the CloudEvents generic data codec methods.", "ms")
)
View Source
var (
	// LatencyView is an OpenCensus view that shows data codec method latency.
	LatencyView = &view.View{
		Name:        "datacodec/latency",
		Measure:     LatencyMs,
		Description: "The distribution of latency inside of the generic data codec for CloudEvents.",
		Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
		TagKeys:     observability.LatencyTags(),
	}
)

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, 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, out interface{}) error

Decoder is the expected function signature for decoding `in` to `out`. What `in` is could be decoder dependent. For example, `in` could be bytes, or a base64 string.

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`.
Text codec converts []byte or string to string and vice-versa.
Text codec converts []byte or string to string and vice-versa.
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