encoding

package module
v0.1.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 6 Imported by: 1

README

Encoding

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunc

type FilterFunc func(pre []byte) ([]byte, error)

FilterFunc is a function which handle binary data. Possible tasks are:

  • Textual content charset encoding / decoding.
  • Compression / Decompression
  • Encryption / Decryption.
  • Signing / Verifying.
  • ...

func DecodeWith

func DecodeWith(encoding encoding.Encoding) FilterFunc

DecodeWith produces a FilterFunc which decodes the binary data from specific encoding. If the encoding provided is nil, the returned FilterFunc just keep the origin binary data.

func DecodingWithCharset

func DecodingWithCharset(name string) FilterFunc

DecodingWithCharset produces a FilterFunc which decodes the binary data from encoding of specific name. If the charset / encoding is not supported by runtime platform, the produced FilterFunc won't decode the data and return a non-nil error.

func EncodeWith

func EncodeWith(encoding encoding.Encoding) FilterFunc

EncodeWith produces a FilterFunc which re-encodes the binary data to specific encoding. If the encoding provided is nil, the returned FilterFunc just keep the origin binary data.

func EncodeWithCharset

func EncodeWithCharset(name string) FilterFunc

EncodeWithCharset produces a FilterFunc which re-encodes the binary data to encoding of specific name. If the charset / encoding is not supported by runtime platform, the produced FilterFunc won't encode the data and return a non-nil error.

type Marshaler

type Marshaler interface {
	// Marshal encodes a value of supported type into binary data.
	// If the type of the value is not supported, an error will be returned.
	// Any error occurred during the encoding process would be returned.
	// When the returned error is not nil, the content of the result is not
	// guaranteed.
	//
	// If an encoding can be extract from the context, it would be used to
	// encode the final binary data.
	Marshal(ctx context.Context, v interface{}) ([]byte, error)
}

Marshaler can encode a value of supported type into binary data.

func FilterMarshaler

func FilterMarshaler(marshaler Marshaler, filterFunc ...FilterFunc) Marshaler

FilterMarshaler decorates a marshaler with FilterFunc. The binary data the decorated Marshaler produced will be reprocessed by the FilterFunc.

func GetMarshaler

func GetMarshaler(name string) Marshaler

GetMarshaler retrieve a Marshaler by type name. If no MarshalerSupplier is registered with the name, nil will be returned. This function will ignore the case of the name.

type MarshalerSupplier

type MarshalerSupplier func() Marshaler

MarshalerSupplier is a function which supplies Marshalers.

func RegisterMarshaler

func RegisterMarshaler(name string, supplier MarshalerSupplier) MarshalerSupplier

RegisterMarshaler register a MarshalerSupplier with a specific type name. It more that one MarshalerSupplier registered by the same type name, the later one wins. This function will ignore the case of the name.

type Unmarshaler

type Unmarshaler interface {
	// Unmarshal decodes value from the binary data.
	// If the type of the target value is not supported, an error will be returned.
	// Any error occurred during the decoding process would be returned.
	// When the returned error is not nil, the state of the target value is not
	// guaranteed.
	//
	// If an encoding can be extract from the context, it would be used to
	// decode the input binary data before decoding to the value.
	//
	// Unmarshaler must copy the data if it wishes to retain the data
	// after returning.
	Unmarshal(ctx context.Context, data []byte, v interface{}) error
}

Unmarshaler can decode value from the binary data to supported type.

func FilterUnmarshaler

func FilterUnmarshaler(unmarshaler Unmarshaler, filterFunc ...FilterFunc) Unmarshaler

FilterUnmarshaler decorates a unmarshaler with FilterFunc. The binary data the decorated Unmarshaler to produce will be processed by the FilterFunc first.

func GetUnmarshaler

func GetUnmarshaler(name string) Unmarshaler

GetUnmarshaler retrieve an Unmarshaler by type name. If no UnmarshalerSupplier is registered with the name, nil will be returned. This function will ignore the case of the name.

type UnmarshalerSupplier

type UnmarshalerSupplier func() Unmarshaler

UnmarshalerSupplier is a function which supplies Unmarshalers.

func RegisterUnmarshaler

func RegisterUnmarshaler(name string, supplier UnmarshalerSupplier) UnmarshalerSupplier

RegisterUnmarshaler register a UnmarshalerSupplier with a specific type name. It more that one UnmarshalerSupplier registered by the same type name, the later one wins. This function will ignore the case of the name.

Directories

Path Synopsis
Package text defines and registers Marshaler/Unmarshaler handling textual type.
Package text defines and registers Marshaler/Unmarshaler handling textual type.

Jump to

Keyboard shortcuts

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