Documentation ¶
Overview ¶
Package io is the hprose serialization library for Golang.
Index ¶
- Constants
- func AcquireBytes(size int) []byte
- func GetAlias(structType reflect.Type) string
- func GetStructType(alias string) (structType reflect.Type)
- func GetTag(structType reflect.Type) string
- func Marshal(v interface{}) []byte
- func Register(proto interface{}, alias string, tag ...string)
- func RegisterMapEncoder(m interface{}, encoder func(*Writer, interface{}))
- func RegisterSliceEncoder(s interface{}, encoder func(*Writer, interface{}))
- func ReleaseBytes(bytes []byte) bool
- func ReleaseReader(reader *Reader)
- func Serialize(v interface{}, simple bool) []byte
- func Unmarshal(b []byte, p interface{})
- func Unserialize(b []byte, p interface{}, simple bool)
- type ByteReader
- type ByteWriter
- type RawReader
- type Reader
- func (r *Reader) CheckTag(expectTag byte) (tag byte)
- func (r *Reader) CheckTags(expectTags []byte) (tag byte)
- func (r *Reader) ReadBigIntWithoutTag() *big.Int
- func (r *Reader) ReadBool() bool
- func (r *Reader) ReadBytes() (b []byte)
- func (r *Reader) ReadBytesWithoutTag() (b []byte)
- func (r *Reader) ReadComplex128() complex128
- func (r *Reader) ReadComplex64() complex64
- func (r *Reader) ReadCount() int
- func (r *Reader) ReadDateTimeWithoutTag() (dt time.Time)
- func (r *Reader) ReadFloat32() float32
- func (r *Reader) ReadFloat64() float64
- func (r *Reader) ReadInt() int64
- func (r *Reader) ReadIntWithoutTag() int
- func (r *Reader) ReadInterface() (v interface{})
- func (r *Reader) ReadSlice(v []reflect.Value)
- func (r *Reader) ReadSliceWithoutTag() []reflect.Value
- func (r *Reader) ReadString() string
- func (r *Reader) ReadStringWithoutTag() (str string)
- func (r *Reader) ReadTime() time.Time
- func (r *Reader) ReadTimeWithoutTag() (t time.Time)
- func (r *Reader) ReadUint() uint64
- func (r *Reader) ReadValue(v reflect.Value)
- func (r *Reader) Reset()
- func (r *Reader) Unserialize(p interface{})
- type ReaderPool
- type Writer
- func (w *Writer) Reset()
- func (w *Writer) Serialize(v interface{}) *Writer
- func (w *Writer) WriteBigFloat(bf *big.Float)
- func (w *Writer) WriteBigInt(bi *big.Int)
- func (w *Writer) WriteBigRat(br *big.Rat)
- func (w *Writer) WriteBool(b bool)
- func (w *Writer) WriteBytes(bytes []byte)
- func (w *Writer) WriteComplex128(c complex128)
- func (w *Writer) WriteComplex64(c complex64)
- func (w *Writer) WriteFloat(f float64, bitSize int)
- func (w *Writer) WriteInt(i int64)
- func (w *Writer) WriteList(lst *list.List)
- func (w *Writer) WriteNil()
- func (w *Writer) WriteSlice(slice []reflect.Value)
- func (w *Writer) WriteString(str string)
- func (w *Writer) WriteStringSlice(slice []string)
- func (w *Writer) WriteTime(t *time.Time)
- func (w *Writer) WriteTuple(tuple ...interface{})
- func (w *Writer) WriteUint(i uint64)
- func (w *Writer) WriteValue(v reflect.Value)
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 TagFunctions byte = 'F' TagCall byte = 'C' TagResult byte = 'R' TagArgument byte = 'A' TagError byte = 'E' TagEnd byte = 'z' )
Hprose Tags
Variables ¶
This section is empty.
Functions ¶
func GetStructType ¶
GetStructType by alias.
func RegisterMapEncoder ¶
func RegisterMapEncoder(m interface{}, encoder func(*Writer, interface{}))
RegisterMapEncoder for fast serialize custom map type. This function is usually used for code generators. This function should be called in package init function.
func RegisterSliceEncoder ¶
func RegisterSliceEncoder(s interface{}, encoder func(*Writer, interface{}))
RegisterSliceEncoder for fast serialize custom slice type. This function is usually used for code generators. This function should be called in package init function.
Types ¶
type ByteReader ¶
type ByteReader struct {
// contains filtered or unexported fields
}
ByteReader implements the io.Reader and io.ByteReader interfaces by reading from a byte slice
func NewByteReader ¶
func NewByteReader(buf []byte) (reader *ByteReader)
NewByteReader is a constructor for ByteReader
func (*ByteReader) Next ¶
func (r *ByteReader) Next(n int) (data []byte)
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, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*ByteReader) Read ¶
func (r *ByteReader) Read(b []byte) (n int, err error)
Read reads the next len(b) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data, err is io.EOF (unless len(b) is zero); otherwise it is nil.
func (*ByteReader) ReadByte ¶
func (r *ByteReader) ReadByte() (byte, error)
ReadByte reads and returns a single byte. If no byte is available, it returns error io.EOF.
func (*ByteReader) Unread ¶
func (r *ByteReader) Unread(n int)
Unread n bytes from the current position.
func (*ByteReader) UnreadByte ¶
func (r *ByteReader) UnreadByte() error
UnreadByte unreads 1 byte from the current position.
type ByteWriter ¶
type ByteWriter struct {
// contains filtered or unexported fields
}
ByteWriter implements the io.Writer and io.ByteWriter interfaces by writing to a byte slice
func NewByteWriter ¶
func NewByteWriter(buf []byte) (w *ByteWriter)
NewByteWriter create a ByteWriter in append mode
func (*ByteWriter) Bytes ¶
func (w *ByteWriter) Bytes() []byte
Bytes returns the byte slice of this writer.
func (*ByteWriter) Grow ¶
func (w *ByteWriter) Grow(n int)
Grow the the byte slice capacity of this writer.
func (*ByteWriter) Len ¶
func (w *ByteWriter) Len() int
Len return the number of byte of this writer.
func (*ByteWriter) String ¶
func (w *ByteWriter) String() string
String returns the contents of this writer as a string. If the ByteWriter is a nil pointer, it returns "<nil>".
func (*ByteWriter) Write ¶
func (w *ByteWriter) Write(b []byte) (int, error)
Write the contents of b to the byte slice of this writer.
func (*ByteWriter) WriteByte ¶
func (w *ByteWriter) WriteByte(c byte) error
WriteByte c to the byte slice of this writer.
type RawReader ¶
type RawReader struct {
ByteReader
}
RawReader is the hprose raw reader
func NewRawReader ¶
NewRawReader is a constructor for RawReader
func (*RawReader) ReadRawTo ¶
func (r *RawReader) ReadRawTo(w *ByteWriter)
ReadRawTo buffer from stream
type Reader ¶
type Reader struct { RawReader Simple bool JSONCompatible bool // contains filtered or unexported fields }
Reader is a fine-grained operation struct for Hprose unserialization when JSONCompatible is true, the Map data will unserialize to map[string]interface as the default type
func (*Reader) ReadBigIntWithoutTag ¶
ReadBigIntWithoutTag from the reader
func (*Reader) ReadBytesWithoutTag ¶
ReadBytesWithoutTag from the reader
func (*Reader) ReadComplex128 ¶
func (r *Reader) ReadComplex128() complex128
ReadComplex128 from the reader
func (*Reader) ReadComplex64 ¶
ReadComplex64 from the reader
func (*Reader) ReadDateTimeWithoutTag ¶
ReadDateTimeWithoutTag from the reader
func (*Reader) ReadIntWithoutTag ¶
ReadIntWithoutTag from the reader
func (*Reader) ReadInterface ¶
func (r *Reader) ReadInterface() (v interface{})
ReadInterface from the reader
func (*Reader) ReadSliceWithoutTag ¶
ReadSliceWithoutTag from the reader
func (*Reader) ReadStringWithoutTag ¶
ReadStringWithoutTag from the reader
func (*Reader) ReadTimeWithoutTag ¶
ReadTimeWithoutTag from the reader
func (*Reader) Unserialize ¶
func (r *Reader) Unserialize(p interface{})
Unserialize a data from the reader
type ReaderPool ¶
ReaderPool is a reader pool for hprose client & service
func (*ReaderPool) AcquireReader ¶
func (pool *ReaderPool) AcquireReader(buf []byte, simple bool) (reader *Reader)
AcquireReader from pool.
func (*ReaderPool) ReleaseReader ¶
func (pool *ReaderPool) ReleaseReader(reader *Reader)
ReleaseReader to pool.
type Writer ¶
type Writer struct { ByteWriter Simple bool // contains filtered or unexported fields }
Writer is a fine-grained operation struct for Hprose serialization
func (*Writer) WriteBigFloat ¶
WriteBigFloat to the writer
func (*Writer) WriteComplex128 ¶
func (w *Writer) WriteComplex128(c complex128)
WriteComplex128 to the writer
func (*Writer) WriteComplex64 ¶
WriteComplex64 to the writer
func (*Writer) WriteFloat ¶
WriteFloat to the writer
func (*Writer) WriteSlice ¶
WriteSlice to the writer
func (*Writer) WriteStringSlice ¶
WriteStringSlice to the writer
func (*Writer) WriteTuple ¶
func (w *Writer) WriteTuple(tuple ...interface{})
WriteTuple to the writer
Source Files ¶
- array_decoder.go
- bool_decoder.go
- byte_pool.go
- byte_reader.go
- byte_writer.go
- complex128_decoder.go
- complex64_decoder.go
- decoder.go
- doc.go
- encoder.go
- float32_decoder.go
- float64_decoder.go
- formatter.go
- int_decoder.go
- interface_decoder.go
- map_decoder.go
- map_encoder.go
- ptr_decoder.go
- raw_reader.go
- reader.go
- reader_pool.go
- slice_decoder.go
- slice_encoder.go
- string_decoder.go
- struct_decoder.go
- struct_encoder.go
- tags.go
- types.go
- uint_decoder.go
- writer.go