v2.0.6+incompatible Latest Latest

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

Go to latest
Published: Oct 19, 2020 License: MIT Imports: 13 Imported by: 142



Package io is the hprose serialization library for Golang.



View Source
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


This section is empty.


func AcquireBytes

func AcquireBytes(size int) []byte

AcquireBytes from pool.

func GetAlias

func GetAlias(structType reflect.Type) string

GetAlias of structType

func GetStructType

func GetStructType(alias string) (structType reflect.Type)

GetStructType by alias.

func GetTag

func GetTag(structType reflect.Type) string

GetTag by structType.

func Marshal

func Marshal(v interface{}) []byte

Marshal data

func Register

func Register(proto interface{}, alias string, tag ...string)

Register the type of the proto with alias & tag.

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.

func ReleaseBytes

func ReleaseBytes(bytes []byte) bool

ReleaseBytes to pool.

func ReleaseReader

func ReleaseReader(reader *Reader)

ReleaseReader to pool.

func Serialize

func Serialize(v interface{}, simple bool) []byte

Serialize data

func Unmarshal

func Unmarshal(b []byte, p interface{})

Unmarshal data

func Unserialize

func Unserialize(b []byte, p interface{}, simple bool)

Unserialize data


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) Init

func (r *ByteReader) Init(buf []byte)

Init 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) Clear

func (w *ByteWriter) Clear()

Clear 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 {

RawReader is the hprose raw reader

func NewRawReader

func NewRawReader(buf []byte) (reader *RawReader)

NewRawReader is a constructor for RawReader

func (*RawReader) ReadRaw

func (r *RawReader) ReadRaw() (raw []byte)

ReadRaw from stream

func (*RawReader) ReadRawTo

func (r *RawReader) ReadRawTo(w *ByteWriter)

ReadRawTo buffer from stream

type Reader

type Reader struct {
	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 AcquireReader

func AcquireReader(buf []byte, simple bool) *Reader

AcquireReader from pool.

func NewReader

func NewReader(buf []byte, simple bool) (reader *Reader)

NewReader is the constructor for Hprose Reader

func (*Reader) CheckTag

func (r *Reader) CheckTag(expectTag byte) (tag byte)

CheckTag the next byte in reader is the expected tag or not

func (*Reader) CheckTags

func (r *Reader) CheckTags(expectTags []byte) (tag byte)

CheckTags the next byte in reader in the expected tags

func (*Reader) ReadBigIntWithoutTag

func (r *Reader) ReadBigIntWithoutTag() *big.Int

ReadBigIntWithoutTag from the reader

func (*Reader) ReadBool

func (r *Reader) ReadBool() bool

ReadBool from the reader

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() (b []byte)

ReadBytes from the reader

func (*Reader) ReadBytesWithoutTag

func (r *Reader) ReadBytesWithoutTag() (b []byte)

ReadBytesWithoutTag from the reader

func (*Reader) ReadComplex128

func (r *Reader) ReadComplex128() complex128

ReadComplex128 from the reader

func (*Reader) ReadComplex64

func (r *Reader) ReadComplex64() complex64

ReadComplex64 from the reader

func (*Reader) ReadCount

func (r *Reader) ReadCount() int

ReadCount of array, slice, map or struct field

func (*Reader) ReadDateTimeWithoutTag

func (r *Reader) ReadDateTimeWithoutTag() (dt time.Time)

ReadDateTimeWithoutTag from the reader

func (*Reader) ReadFloat32

func (r *Reader) ReadFloat32() float32

ReadFloat32 from the reader

func (*Reader) ReadFloat64

func (r *Reader) ReadFloat64() float64

ReadFloat64 from the reader

func (*Reader) ReadInt

func (r *Reader) ReadInt() int64

ReadInt from the reader

func (*Reader) ReadIntWithoutTag

func (r *Reader) ReadIntWithoutTag() int

ReadIntWithoutTag from the reader

func (*Reader) ReadInterface

func (r *Reader) ReadInterface() (v interface{})

ReadInterface from the reader

func (*Reader) ReadSlice

func (r *Reader) ReadSlice(v []reflect.Value)

ReadSlice from the reader

func (*Reader) ReadSliceWithoutTag

func (r *Reader) ReadSliceWithoutTag() []reflect.Value

ReadSliceWithoutTag from the reader

func (*Reader) ReadString

func (r *Reader) ReadString() string

ReadString from the reader

func (*Reader) ReadStringWithoutTag

func (r *Reader) ReadStringWithoutTag() (str string)

ReadStringWithoutTag from the reader

func (*Reader) ReadTime

func (r *Reader) ReadTime() time.Time

ReadTime from the reader

func (*Reader) ReadTimeWithoutTag

func (r *Reader) ReadTimeWithoutTag() (t time.Time)

ReadTimeWithoutTag from the reader

func (*Reader) ReadUint

func (r *Reader) ReadUint() uint64

ReadUint from the reader

func (*Reader) ReadValue

func (r *Reader) ReadValue(v reflect.Value)

ReadValue from the reader

func (*Reader) Reset

func (r *Reader) Reset()

Reset the reference counter

func (*Reader) Unserialize

func (r *Reader) Unserialize(p interface{})

Unserialize a data from the reader

type ReaderPool

type ReaderPool struct {

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 {
	Simple bool
	// contains filtered or unexported fields

Writer is a fine-grained operation struct for Hprose serialization

func NewWriter

func NewWriter(simple bool, buf ...byte) (w *Writer)

NewWriter is the constructor for Hprose Writer

func (*Writer) Reset

func (w *Writer) Reset()

Reset the reference counter

func (*Writer) Serialize

func (w *Writer) Serialize(v interface{}) *Writer

Serialize a data v to the writer

func (*Writer) WriteBigFloat

func (w *Writer) WriteBigFloat(bf *big.Float)

WriteBigFloat to the writer

func (*Writer) WriteBigInt

func (w *Writer) WriteBigInt(bi *big.Int)

WriteBigInt to the writer

func (*Writer) WriteBigRat

func (w *Writer) WriteBigRat(br *big.Rat)

WriteBigRat to the writer

func (*Writer) WriteBool

func (w *Writer) WriteBool(b bool)

WriteBool to the writer

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(bytes []byte)

WriteBytes to the writer

func (*Writer) WriteComplex128

func (w *Writer) WriteComplex128(c complex128)

WriteComplex128 to the writer

func (*Writer) WriteComplex64

func (w *Writer) WriteComplex64(c complex64)

WriteComplex64 to the writer

func (*Writer) WriteFloat

func (w *Writer) WriteFloat(f float64, bitSize int)

WriteFloat to the writer

func (*Writer) WriteInt

func (w *Writer) WriteInt(i int64)

WriteInt to the writer

func (*Writer) WriteList

func (w *Writer) WriteList(lst *list.List)

WriteList to the writer

func (*Writer) WriteNil

func (w *Writer) WriteNil()

WriteNil to the writer

func (*Writer) WriteSlice

func (w *Writer) WriteSlice(slice []reflect.Value)

WriteSlice to the writer

func (*Writer) WriteString

func (w *Writer) WriteString(str string)

WriteString to the writer

func (*Writer) WriteStringSlice

func (w *Writer) WriteStringSlice(slice []string)

WriteStringSlice to the writer

func (*Writer) WriteTime

func (w *Writer) WriteTime(t *time.Time)

WriteTime to the writer

func (*Writer) WriteTuple

func (w *Writer) WriteTuple(tuple ...interface{})

WriteTuple to the writer

func (*Writer) WriteUint

func (w *Writer) WriteUint(i uint64)

WriteUint to the writer

func (*Writer) WriteValue

func (w *Writer) WriteValue(v reflect.Value)

WriteValue to the writer

Jump to

Keyboard shortcuts

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