Documentation ¶
Index ¶
- Constants
- Variables
- func AppendInt64(buf []byte, i int64) []byte
- func AppendUint64(buf []byte, i uint64) []byte
- func Convert(src interface{}, t reflect.Type) (interface{}, error)
- func FreeDecoder(decoder *Decoder)
- func FreeEncoder(encoder *Encoder)
- func GetConverter(src, dest reflect.Type) func(dec *Decoder, o interface{}, p interface{})
- func GetStructType(alias string) reflect.Type
- func Marshal(v interface{}) ([]byte, error)
- func Register(proto interface{}, tag ...string)
- func RegisterConverter(src, dest reflect.Type, ...)
- func RegisterName(alias string, proto interface{}, tag ...string)
- func RegisterValueDecoder(v interface{}, valdec ValueDecoder)
- func RegisterValueEncoder(v interface{}, valenc ValueEncoder)
- func Unmarshal(data []byte, v interface{}) error
- func UnmarshalFromReader(reader io.Reader, v interface{}) error
- type CastError
- type DecodeError
- type DecodeHandler
- type Decoder
- func (dec *Decoder) AddReference(o interface{})
- func (dec *Decoder) Decode(p interface{}, tag ...byte)
- func (dec *Decoder) IsSimple() bool
- func (dec *Decoder) LastReferenceIndex() int
- func (dec *Decoder) Next(n int) []byte
- func (dec *Decoder) NextByte() (b byte)
- func (dec *Decoder) Read(t reflect.Type, tag ...byte) (result interface{})
- func (dec *Decoder) ReadBigFloat() *big.Float
- func (dec *Decoder) ReadBigInt() *big.Int
- func (dec *Decoder) ReadBytes() []byte
- func (dec *Decoder) ReadDateTime() (t time.Time)
- func (dec *Decoder) ReadFloat32() (value float32)
- func (dec *Decoder) ReadFloat64() (value float64)
- func (dec *Decoder) ReadInt() (value int)
- func (dec *Decoder) ReadInt16() (value int16)
- func (dec *Decoder) ReadInt32() (value int32)
- func (dec *Decoder) ReadInt64() (value int64)
- func (dec *Decoder) ReadInt8() (value int8)
- func (dec *Decoder) ReadObject() interface{}
- func (dec *Decoder) ReadReference(p interface{})
- func (dec *Decoder) ReadSafeString() (s string)
- func (dec *Decoder) ReadString() (s string)
- func (dec *Decoder) ReadStringAsBytes() (data []byte)
- func (dec *Decoder) ReadStruct(t reflect.Type)
- func (dec *Decoder) ReadTime() (t time.Time)
- func (dec *Decoder) ReadUUID() uuid.UUID
- func (dec *Decoder) ReadUint() (value uint)
- func (dec *Decoder) ReadUint16() (value uint16)
- func (dec *Decoder) ReadUint32() (value uint32)
- func (dec *Decoder) ReadUint64() (value uint64)
- func (dec *Decoder) ReadUint8() (value uint8)
- func (dec *Decoder) ReadUnsafeString() (s string)
- func (dec *Decoder) Remains() (data []byte)
- func (dec *Decoder) Reset() *Decoder
- func (dec *Decoder) ResetBuffer() *Decoder
- func (dec *Decoder) ResetBytes(input []byte) *Decoder
- func (dec *Decoder) ResetReader(reader io.Reader) *Decoder
- func (dec *Decoder) SetReference(i int, o interface{})
- func (dec *Decoder) Simple(simple bool) *Decoder
- func (dec *Decoder) Skip()
- func (dec *Decoder) UnsafeNext(n int) (data []byte)
- func (dec *Decoder) UnsafeUntil(delim byte) (data []byte)
- func (dec *Decoder) Until(delim byte) []byte
- type EncodeHandler
- type Encoder
- func (enc *Encoder) AddReferenceCount(n int)
- func (enc *Encoder) Buffer() []byte
- func (enc *Encoder) Bytes() []byte
- func (enc *Encoder) Encode(v interface{}) (err error)
- func (enc *Encoder) EncodeReference(valenc ValueEncoder, v interface{})
- func (enc *Encoder) EncodeString(s string)
- func (enc *Encoder) Flush() (err error)
- func (enc *Encoder) IsSimple() bool
- func (enc *Encoder) Reset() *Encoder
- func (enc *Encoder) ResetBuffer() *Encoder
- func (enc *Encoder) SetReference(v interface{})
- func (enc *Encoder) SetStringReference(s string)
- func (enc *Encoder) Simple(simple bool) *Encoder
- func (enc *Encoder) String() string
- func (enc *Encoder) UnsafeString() string
- func (enc *Encoder) Write(v interface{}) (err error)
- func (enc *Encoder) WriteArray(v interface{})
- func (enc *Encoder) WriteBigFloat(f *big.Float)
- func (enc *Encoder) WriteBigInt(i *big.Int)
- func (enc *Encoder) WriteBigRat(r *big.Rat)
- func (enc *Encoder) WriteBool(b bool)
- func (enc *Encoder) WriteComplex128(c complex128)
- func (enc *Encoder) WriteComplex64(c complex64)
- func (enc *Encoder) WriteError(e error)
- func (enc *Encoder) WriteFloat32(f float32)
- func (enc *Encoder) WriteFloat64(f float64)
- func (enc *Encoder) WriteFoot()
- func (enc *Encoder) WriteInt(i int)
- func (enc *Encoder) WriteInt16(i int16)
- func (enc *Encoder) WriteInt32(i int32)
- func (enc *Encoder) WriteInt64(i int64)
- func (enc *Encoder) WriteInt8(i int8)
- func (enc *Encoder) WriteListHead(n int)
- func (enc *Encoder) WriteMap(v interface{})
- func (enc *Encoder) WriteMapHead(n int)
- func (enc *Encoder) WriteNil()
- func (enc *Encoder) WriteObjectHead(r int)
- func (enc *Encoder) WriteReference(v interface{}) bool
- func (enc *Encoder) WriteSlice(v interface{})
- func (enc *Encoder) WriteString(s string)
- func (enc *Encoder) WriteStringReference(s string) bool
- func (enc *Encoder) WriteStructType(t reflect.Type, action func()) (r int)
- func (enc *Encoder) WriteTag(tag byte)
- func (enc *Encoder) WriteUint(i uint)
- func (enc *Encoder) WriteUint16(i uint16)
- func (enc *Encoder) WriteUint32(i uint32)
- func (enc *Encoder) WriteUint64(i uint64)
- func (enc *Encoder) WriteUint8(i uint8)
- type FieldAccessor
- type Formatter
- type ListType
- type LongType
- type MapType
- type RealType
- type StructType
- type UnsupportedTypeError
- type ValueDecoder
- type ValueEncoder
Constants ¶
const ( // Serialize Type. TagInteger byte = 'i' TagLong byte = 'l' TagDouble byte = 'd' TagNull byte = 'n' TagEmpty byte = 'e' TagTrue byte = 't' TagFalse byte = 'f' TagNaN byte = 'N' TagInfinity byte = 'I' TagDate byte = 'D' TagTime byte = 'T' TagUTC byte = 'Z' TagBytes byte = 'b' TagUTF8Char byte = 'u' TagString byte = 's' TagGUID byte = 'g' TagList byte = 'a' TagMap byte = 'm' TagClass byte = 'c' TagObject byte = 'o' TagRef byte = 'r' // Serialize Marks. TagPos byte = '+' TagNeg byte = '-' TagSemicolon byte = ';' TagOpenbrace byte = '{' TagClosebrace byte = '}' TagQuote byte = '"' TagPoint byte = '.' // Protocol Tags. TagHeader byte = 'H' TagCall byte = 'C' TagResult byte = 'R' TagError byte = 'E' TagEnd byte = 'z' )
Hprose Tags.
Variables ¶
var ErrInvalidUTF8 = errors.New("hprose/io: invalid UTF-8")
ErrInvalidUTF8 means that a decoder encountered invalid UTF-8.
Functions ¶
func FreeDecoder ¶ added in v3.0.5
func FreeDecoder(decoder *Decoder)
func FreeEncoder ¶ added in v3.0.5
func FreeEncoder(encoder *Encoder)
func GetConverter ¶
GetConverter returns the converter for converting src to dest.
func Register ¶
func Register(proto interface{}, tag ...string)
Register the type of the proto with tag.
func RegisterConverter ¶
func RegisterConverter(src, dest reflect.Type, converter func(dec *Decoder, o interface{}, p interface{}))
RegisterConverter for converting src to dest.
func RegisterName ¶
RegisterName the type of the proto with name & tag.
func RegisterValueDecoder ¶
func RegisterValueDecoder(v interface{}, valdec ValueDecoder)
RegisterValueDecoder valdec.
func RegisterValueEncoder ¶
func RegisterValueEncoder(v interface{}, valenc ValueEncoder)
RegisterValueEncoder of type(v).
func UnmarshalFromReader ¶ added in v3.0.5
Types ¶
type CastError ¶
A CastError is returned by Decoder when can not cast source type to destination type.
type DecodeError ¶
type DecodeError string
DecodeError is returned by Decoder when the data is wrong.
func (DecodeError) Error ¶
func (e DecodeError) Error() string
type DecodeHandler ¶
DecodeHandler is an decode handler.
func GetDecodeHandler ¶
func GetDecodeHandler(t reflect.Type) DecodeHandler
GetDecodeHandler for specified type.
type Decoder ¶
type Decoder struct { Error error LongType RealType MapType StructType ListType // contains filtered or unexported fields }
Decoder is a io.Reader like object, with hprose specific read functions. Error is not returned as return value, but stored as Error member on this decoder instance.
func GetDecoder ¶ added in v3.0.5
func GetDecoder() *Decoder
func NewDecoder ¶
NewDecoder creates an Decoder instance from byte array.
func NewDecoderFromReader ¶
NewDecoderFromReader creates an Decoder instance from io.Reader.
func (*Decoder) AddReference ¶
func (dec *Decoder) AddReference(o interface{})
AddReference adds o to the reference.
func (*Decoder) LastReferenceIndex ¶
LastReferenceIndex returns the last index of the reference.
func (*Decoder) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The returned slice is always valid.
func (*Decoder) NextByte ¶
NextByte reads and returns the next byte from the dec. If no byte is available, it returns 0.
func (*Decoder) ReadBigFloat ¶
ReadBigFloat reads *big.Float.
func (*Decoder) ReadDateTime ¶
ReadDateTime reads time.Time and add reference.
func (*Decoder) ReadFloat32 ¶
ReadFloat32 reads float32.
func (*Decoder) ReadFloat64 ¶
ReadFloat64 reads float64.
func (*Decoder) ReadObject ¶
func (dec *Decoder) ReadObject() interface{}
ReadObject reads object and add reference.
func (*Decoder) ReadReference ¶
func (dec *Decoder) ReadReference(p interface{})
ReadReference to p.
func (*Decoder) ReadSafeString ¶
ReadSafeString reads safe string.
func (*Decoder) ReadString ¶
ReadString reads safe string and add reference.
func (*Decoder) ReadStringAsBytes ¶
ReadStringAsBytes reads string as bytes.
func (*Decoder) ReadStruct ¶
ReadStruct reads struct type.
func (*Decoder) ReadUint16 ¶
ReadUint16 reads uint16.
func (*Decoder) ReadUint32 ¶
ReadUint32 reads uint32.
func (*Decoder) ReadUint64 ¶
ReadUint64 reads uint64.
func (*Decoder) ReadUnsafeString ¶
ReadUnsafeString reads unsafe string.
func (*Decoder) Remains ¶
Remains reads and returns all bytes data in this iter that has not been read.
func (*Decoder) ResetBuffer ¶ added in v3.0.5
ResetBuffer of the Decoder.
func (*Decoder) ResetBytes ¶
ResetBytes reuse decoder instance by specifying another byte array as input.
func (*Decoder) ResetReader ¶
ResetReader reuse decoder instance by specifying another reader.
func (*Decoder) SetReference ¶
SetReference sets o to the reference at index i.
func (*Decoder) UnsafeNext ¶
UnsafeNext returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The returned slice is only valid until the next call to a read method.
func (*Decoder) UnsafeUntil ¶
UnsafeUntil reads until the first occurrence of delim in the input, returning a slice containing the data up to and not including the delimiter. The returned slice is only valid until the next call to a read method.
type EncodeHandler ¶
type EncodeHandler func(enc *Encoder, v interface{})
EncodeHandler is an encode handler.
func GetEncodeHandler ¶
func GetEncodeHandler(t reflect.Type) (handler EncodeHandler)
GetEncodeHandler for specified type.
type Encoder ¶
An Encoder writes hprose data to an output stream.
func GetEncoder ¶ added in v3.0.5
func GetEncoder() *Encoder
func (*Encoder) AddReferenceCount ¶
AddReferenceCount n.
func (*Encoder) Encode ¶
Encode writes the hprose io of v to stream. If v is already written to stream, it will writes it as reference.
func (*Encoder) EncodeReference ¶
func (enc *Encoder) EncodeReference(valenc ValueEncoder, v interface{})
EncodeReference to encoder.
func (*Encoder) ResetBuffer ¶ added in v3.0.5
ResetBuffer of the Encoder.
func (*Encoder) SetStringReference ¶
SetStringReference of v.
func (*Encoder) UnsafeString ¶ added in v3.0.5
UnsafeString returns the accumulated string.
func (*Encoder) Write ¶
Write writes the hprose io of v to stream. If v is already written to stream, it will writes it as value.
func (*Encoder) WriteBigFloat ¶
WriteBigFloat to encoder.
func (*Encoder) WriteComplex128 ¶
func (enc *Encoder) WriteComplex128(c complex128)
WriteComplex128 to encoder.
func (*Encoder) WriteComplex64 ¶
WriteComplex64 to encoder.
func (*Encoder) WriteListHead ¶
WriteListHead to encoder, n is the count of elements in list.
func (*Encoder) WriteMapHead ¶
WriteMapHead to encoder, n is the count of elements in map.
func (*Encoder) WriteObjectHead ¶
WriteObjectHead to encoder, r is the reference number of struct.
func (*Encoder) WriteReference ¶
WriteReference of v to stream.
func (*Encoder) WriteStringReference ¶
WriteStringReference of v to stream.
func (*Encoder) WriteStructType ¶
WriteStructType of t to stream with action.
type FieldAccessor ¶
type FieldAccessor struct { Type reflect2.Type Alias string Field reflect2.StructField Encode EncodeHandler Decode DecodeHandler }
FieldAccessor .
type LongType ¶
type LongType int8
LongType represents the default type for decode long integer.
const ( // LongTypeInt represents the default type is int. LongTypeInt LongType = iota // LongTypeUint represents the default type is uint. LongTypeUint // LongTypeInt64 represents the default type is int64. LongTypeInt64 // LongTypeUint64 represents the default type is uint64. LongTypeUint64 // LongTypeBigInt represents the default type is *big.Int. LongTypeBigInt )
type StructType ¶ added in v3.0.15
type StructType int8
const ( // StructTypePtr represents the default type is *T. StructTypePtr StructType = iota // StructTypeValue represents the default type is T. StructTypeValue )
type UnsupportedTypeError ¶
An UnsupportedTypeError is returned by Encoder when attempting to encode an unsupported value type.
func (UnsupportedTypeError) Error ¶
func (e UnsupportedTypeError) Error() string
type ValueDecoder ¶
ValueDecoder is the interface that groups the basic Decode methods.
func GetValueDecoder ¶
func GetValueDecoder(v interface{}) (valdec ValueDecoder)
GetValueDecoder of Type t.
type ValueEncoder ¶
type ValueEncoder interface { Encode(enc *Encoder, v interface{}) Write(enc *Encoder, v interface{}) }
ValueEncoder is the interface that groups the basic Write and Encode methods.
Source Files ¶
- array_decoder.go
- array_encoder.go
- big_decoder.go
- big_encoder.go
- bool_decoder.go
- bytes_decoder.go
- complex_decoder.go
- converter.go
- decode_handler.go
- decoder.go
- decoder_refer.go
- encode.go
- encode_handler.go
- encoder.go
- encoder_refer.go
- error.go
- error_encoder.go
- float_decoder.go
- formatter.go
- int_decoder.go
- interface_deocder.go
- interface_encoder.go
- list_decoder.go
- list_encoder.go
- map_decoder.go
- map_encoder.go
- num_decoder.go
- num_encoder.go
- pool.go
- ptr_decoder.go
- ptr_encoder.go
- reflect.go
- slice_decoder.go
- slice_encoder.go
- string_decoder.go
- string_encoder.go
- struct_decoder.go
- struct_encoder.go
- struct_manager.go
- tags.go
- time_decoder.go
- time_encoder.go
- uuid_decoder.go
- uuid_encoder.go
- value_decoder.go
- value_encoder.go