codec

package
v6.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 15 Imported by: 11

Documentation

Overview

Package codec is the body's codec set.

Copyright 2015-2019 HenryLee. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package codec is a generated protocol buffer package.

It is generated from these files:

empty.proto

It has these top-level messages:

PbEmpty

Index

Constants

View Source
const (
	// NilCodecID empty codec id.
	NilCodecID byte = 0
	// NilCodecName empty codec name.
	NilCodecName string = ""
)
View Source
const (
	NAME_FORM = "form"
	ID_FORM   = 'f'
)

form(url encode) codec name and id

View Source
const (
	NAME_JSON = "json"
	ID_JSON   = 'j'
)

json codec name and id

View Source
const (
	NAME_PLAIN = "plain"
	ID_PLAIN   = 's'
)

plain text codec name and id

View Source
const (
	NAME_PROTOBUF = "protobuf"
	ID_PROTOBUF   = 'p'
)

protobuf codec name and id

View Source
const (
	NAME_THRIFT = "thrift"
	ID_THRIFT   = 't'
)

thrift codec name and id

View Source
const (
	NAME_XML = "xml"
	ID_XML   = 'x'
)

xml codec name and id

Variables

View Source
var (
	ErrInvalidLengthEmpty = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowEmpty   = fmt.Errorf("proto: integer overflow")
)
View Source
var GoUnusedProtection__ int
View Source
var (
	// PbEmptyStruct empty struct for protobuf
	PbEmptyStruct = new(PbEmpty)
)
View Source
var (
	// ThriftEmptyStruct empty struct for thrift
	ThriftEmptyStruct = new(ThriftEmpty)
)

Functions

func Marshal

func Marshal(codecID byte, v interface{}) ([]byte, error)

Marshal returns the encoding of v.

func MarshalByName

func MarshalByName(codecName string, v interface{}) ([]byte, error)

MarshalByName returns the encoding of v.

func ProtoMarshal

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

ProtoMarshal returns the Protobuf encoding of v.

func ProtoUnmarshal

func ProtoUnmarshal(data []byte, v interface{}) error

ProtoUnmarshal parses the Protobuf-encoded data and stores the result in the value pointed to by v.

func Reg

func Reg(codec Codec)

Reg registers Codec.

func ThriftMarshal

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

ThriftMarshal returns the Thriftbuf encoding of v.

func ThriftUnmarshal

func ThriftUnmarshal(data []byte, v interface{}) error

ThriftUnmarshal parses the Thriftbuf-encoded data and stores the result in the value pointed to by v.

func Unmarshal

func Unmarshal(codecID byte, data []byte, v interface{}) error

Unmarshal parses the encoded data and stores the result in the value pointed to by v.

func UnmarshalByName

func UnmarshalByName(codecName string, data []byte, v interface{}) error

UnmarshalByName parses the encoded data and stores the result in the value pointed to by v.

Types

type Codec

type Codec interface {
	// ID returns codec id.
	ID() byte
	// Name returns codec name.
	Name() string
	// Marshal returns the encoding of v.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal parses the encoded data and stores the result
	// in the value pointed to by v.
	Unmarshal(data []byte, v interface{}) error
}

Codec makes the body's Encoder and Decoder

func Get

func Get(codecID byte) (Codec, error)

Get returns Codec by id.

func GetByName

func GetByName(codecName string) (Codec, error)

GetByName returns Codec by name.

type FormCodec

type FormCodec struct{}

FormCodec url encode codec

func (FormCodec) ID

func (FormCodec) ID() byte

ID returns codec id.

func (FormCodec) Marshal

func (FormCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the url encoded date of v.

func (FormCodec) Name

func (FormCodec) Name() string

Name returns codec name.

func (FormCodec) Unmarshal

func (FormCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the url encoded data and stores the result in the value pointed to by v.

type JSONCodec

type JSONCodec struct{}

JSONCodec json codec

func (JSONCodec) ID

func (JSONCodec) ID() byte

ID returns codec id.

func (JSONCodec) Marshal

func (JSONCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the JSON encoding of v.

func (JSONCodec) Name

func (JSONCodec) Name() string

Name returns codec name.

func (JSONCodec) Unmarshal

func (JSONCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.

type PbEmpty

type PbEmpty struct {
}

func (*PbEmpty) Descriptor

func (*PbEmpty) Descriptor() ([]byte, []int)

func (*PbEmpty) Marshal

func (m *PbEmpty) Marshal() (dAtA []byte, err error)

func (*PbEmpty) MarshalTo

func (m *PbEmpty) MarshalTo(dAtA []byte) (int, error)

func (*PbEmpty) ProtoMessage

func (*PbEmpty) ProtoMessage()

func (*PbEmpty) Reset

func (m *PbEmpty) Reset()

func (*PbEmpty) Size

func (m *PbEmpty) Size() (n int)

func (*PbEmpty) String

func (m *PbEmpty) String() string

func (*PbEmpty) Unmarshal

func (m *PbEmpty) Unmarshal(dAtA []byte) error

type PlainCodec

type PlainCodec struct{}

PlainCodec plain text codec

func (PlainCodec) ID

func (PlainCodec) ID() byte

ID returns codec id.

func (PlainCodec) Marshal

func (PlainCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the string encoding of v.

func (PlainCodec) Name

func (PlainCodec) Name() string

Name returns codec name.

func (PlainCodec) Unmarshal

func (PlainCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the string-encoded data and stores the result in the value pointed to by v.

type ProtoCodec

type ProtoCodec struct{}

ProtoCodec protobuf codec

func (ProtoCodec) ID

func (ProtoCodec) ID() byte

ID returns codec id.

func (ProtoCodec) Marshal

func (ProtoCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the Protobuf encoding of v.

func (ProtoCodec) Name

func (ProtoCodec) Name() string

Name returns codec name.

func (ProtoCodec) Unmarshal

func (ProtoCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the Protobuf-encoded data and stores the result in the value pointed to by v.

type ThriftCodec

type ThriftCodec struct{}

ThriftCodec thrift codec

func (ThriftCodec) ID

func (ThriftCodec) ID() byte

ID returns codec id.

func (ThriftCodec) Marshal

func (ThriftCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the Thriftbuf encoding of v.

func (ThriftCodec) Name

func (ThriftCodec) Name() string

Name returns codec name.

func (ThriftCodec) Unmarshal

func (ThriftCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the Thriftbuf-encoded data and stores the result in the value pointed to by v.

type ThriftEmpty

type ThriftEmpty struct {
}

func NewThriftEmpty

func NewThriftEmpty() *ThriftEmpty

func (*ThriftEmpty) Read

func (p *ThriftEmpty) Read(iprot thrift.TProtocol) error

func (*ThriftEmpty) String

func (p *ThriftEmpty) String() string

func (*ThriftEmpty) Write

func (p *ThriftEmpty) Write(oprot thrift.TProtocol) error

type XMLCodec

type XMLCodec struct{}

XMLCodec xml codec

func (XMLCodec) ID

func (XMLCodec) ID() byte

ID returns codec id.

func (XMLCodec) Marshal

func (XMLCodec) Marshal(v interface{}) ([]byte, error)

Marshal returns the XML encoding of v.

func (XMLCodec) Name

func (XMLCodec) Name() string

Name returns codec name.

func (XMLCodec) Unmarshal

func (XMLCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal parses the XML-encoded data and stores the result in the value pointed to by v.

Jump to

Keyboard shortcuts

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