codec

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package codec is the registration center for supported codecs you can register whatever codec implementation you want

e.g. for json codec, you can register you own codec implementation based on other json library (other than encoding/json)

by default, using encoding/json for json codec and gogoproto for protobuf codec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBytesBuf added in v0.4.4

func GetBytesBuf(size int) []byte

func PutBytesBuf added in v0.4.4

func PutBytesBuf(b *[]byte)

func Register added in v0.4.4

func Register(kind arhatgopb.CodecType, codec Interface)

Types

type Decoder added in v0.4.4

type Decoder interface {
	// Decode one message from stream
	Decode(out interface{}) error
}

Decoder for stream data decoding

type Encoder added in v0.4.4

type Encoder interface {
	// Encode one message to stream
	Encode(any interface{}) error
}

Encoder for stream data encoding

type Interface added in v0.4.4

type Interface interface {
	// Type is the codec kind
	Type() arhatgopb.CodecType

	// NewEncoder creates a new Encoder which will encode messages to the Writer
	NewEncoder(w io.Writer) Encoder

	// NewEncoder creates a new Decoder which will decode messages from the Reader
	NewDecoder(r io.Reader) Decoder

	// Unmarshal non stream data
	Unmarshal(data []byte, out interface{}) error

	// Marshal v as non stream data
	Marshal(v interface{}) ([]byte, error)
}

Interface of codec knows how to encode/decode all kinds of data, including stream data

func Get added in v0.4.4

func Get(kind arhatgopb.CodecType) (Interface, bool)

type MarshalFunc added in v0.4.4

type MarshalFunc func(v interface{}) ([]byte, error)

type UnmarshalFunc added in v0.4.4

type UnmarshalFunc func(data []byte, out interface{}) error

Directories

Path Synopsis
Package codecpb implements protobuf codec for libext
Package codecpb implements protobuf codec for libext
Package codecjson uses stdlib json for libext
Package codecjson uses stdlib json for libext

Jump to

Keyboard shortcuts

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