Documentation ¶
Overview ¶
Package codec is the body's codec set.
Copyright 2015-2023 HenryLee. All Rights Reserved. Copyright 2024 sqos. 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.
Index ¶
- Constants
- Variables
- func Marshal(codecID byte, v interface{}) ([]byte, error)
- func MarshalByName(codecName string, v interface{}) ([]byte, error)
- func ProtoMarshal(v interface{}) ([]byte, error)
- func ProtoUnmarshal(data []byte, v interface{}) error
- func Reg(codec Codec)
- func ThriftMarshal(v interface{}) ([]byte, error)
- func ThriftUnmarshal(data []byte, v interface{}) error
- func Unmarshal(codecID byte, data []byte, v interface{}) error
- func UnmarshalByName(codecName string, data []byte, v interface{}) error
- type Codec
- type FormCodec
- type JSONCodec
- type PbEmpty
- type PlainCodec
- type ProtoCodec
- type ThriftCodec
- type ThriftEmpty
- type XMLCodec
Constants ¶
const ( // NilCodecID empty codec id. NilCodecID byte = 0 // NilCodecName empty codec name. NilCodecName string = "" )
const ( NAME_FORM = "form" ID_FORM = 'f' )
form(url encode) codec name and id
const ( NAME_JSON = "json" ID_JSON = 'j' )
json codec name and id
const ( NAME_PLAIN = "plain" ID_PLAIN = 's' )
plain text codec name and id
const ( NAME_PROTOBUF = "protobuf" ID_PROTOBUF = 'p' )
protobuf codec name and id
const ( NAME_THRIFT = "thrift" ID_THRIFT = 't' )
thrift codec name and id
const ( NAME_XML = "xml" ID_XML = 'x' )
xml codec name and id
Variables ¶
var File_empty_proto protoreflect.FileDescriptor
var GoUnusedProtection__ int
var ( // PbEmptyStruct empty struct for protobuf PbEmptyStruct = new(PbEmpty) )
var ( // ThriftEmptyStruct empty struct for thrift ThriftEmptyStruct = new(ThriftEmpty) )
Functions ¶
func MarshalByName ¶
MarshalByName returns the encoding of v.
func ProtoMarshal ¶
ProtoMarshal returns the Protobuf encoding of v.
func ProtoUnmarshal ¶
ProtoUnmarshal parses the Protobuf-encoded data and stores the result in the value pointed to by v.
func ThriftMarshal ¶
ThriftMarshal returns the Thriftbuf encoding of v.
func ThriftUnmarshal ¶
ThriftUnmarshal parses the Thriftbuf-encoded data and stores the result in the value pointed to by v.
func Unmarshal ¶
Unmarshal parses the encoded data and stores the result in the value pointed to by v.
func UnmarshalByName ¶
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
type FormCodec ¶
type FormCodec struct{}
FormCodec url encode codec
type JSONCodec ¶
type JSONCodec struct{}
JSONCodec json codec
type PbEmpty ¶
type PbEmpty struct {
// contains filtered or unexported fields
}
func (*PbEmpty) Descriptor
deprecated
func (*PbEmpty) ProtoMessage ¶
func (*PbEmpty) ProtoMessage()
func (*PbEmpty) ProtoReflect ¶
func (x *PbEmpty) ProtoReflect() protoreflect.Message
type PlainCodec ¶
type PlainCodec struct{}
PlainCodec plain text codec
func (PlainCodec) Marshal ¶
func (PlainCodec) Marshal(v interface{}) ([]byte, error)
Marshal returns the string encoding of v.
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) Marshal ¶
func (ProtoCodec) Marshal(v interface{}) ([]byte, error)
Marshal returns the Protobuf encoding of v.
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) Marshal ¶
func (ThriftCodec) Marshal(v interface{}) ([]byte, error)
Marshal returns the Thriftbuf encoding of v.
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) String ¶
func (p *ThriftEmpty) String() string