codec

package
v3.3.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package codec is the body's codec set.

Copyright 2015-2017 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_JSON = "json"
	ID_JSON   = 'j'
)

json codec id

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

protobuf codec id

View Source
const (
	NAME_STRING = "string"
	ID_STRING   = 's'
)

protobuf codec id

Variables

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

Functions

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

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(id byte) (Codec, error)

Get returns Codec

func GetByName

func GetByName(name string) (Codec, error)

GetByName returns Codec

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 string

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 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 string

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 StringCodec

type StringCodec struct{}

StringCodec string codec

func (StringCodec) Id

func (StringCodec) Id() byte

Id returns codec id

func (StringCodec) Marshal

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

Marshal returns the string encoding of v.

func (StringCodec) Name

func (StringCodec) Name() string

Name returns codec string

func (StringCodec) Unmarshal

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

Unmarshal parses the string-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