hprose

package
v0.0.0-...-39887aa Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2014 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Normal = ResultMode(iota)
	Serialized
	Raw
	RawWithEndTag
)
View Source
const (
	/* Serialize Tags */
	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'
)

Variables

View Source
var ClassManager = initClassManager()

ClassManager used to be register class with alias for hprose serialize/unserialize.

View Source
var NilError = errors.New("nil")

Functions

func Marshal

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

func RegisterClientFactory

func RegisterClientFactory(scheme string, newClient func(string) Client)

func Serialize

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

func Unmarshal

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

func Unserialize

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

Types

type ArgsFixer

type ArgsFixer interface {
	FixArgs(args []reflect.Value, lastParamType reflect.Type, context interface{}) []reflect.Value
}

type BaseClient

type BaseClient struct {
	Transporter
	ByRef        bool
	SimpleMode   bool
	DebugEnabled bool
	// contains filtered or unexported fields
}

func NewBaseClient

func NewBaseClient(trans Transporter) *BaseClient

func (*BaseClient) AddFilter

func (client *BaseClient) AddFilter(filter Filter)

func (*BaseClient) GetFilter

func (client *BaseClient) GetFilter() Filter

func (*BaseClient) Invoke

func (client *BaseClient) Invoke(name string, args []interface{}, options *InvokeOptions, result interface{}) <-chan error

func (*BaseClient) RemoveFilter

func (client *BaseClient) RemoveFilter(filter Filter)

func (*BaseClient) SetFilter

func (client *BaseClient) SetFilter(filter Filter)

func (*BaseClient) SetUri

func (client *BaseClient) SetUri(uri string)

func (*BaseClient) Uri

func (client *BaseClient) Uri() string

func (*BaseClient) UseService

func (client *BaseClient) UseService(args ...interface{})

UseService(uri string) UseService(remoteObject interface{}) UseService(uri string, remoteObject interface{})

type BaseService

type BaseService struct {
	*Methods
	ServiceEvent
	DebugEnabled bool
	// contains filtered or unexported fields
}

func NewBaseService

func NewBaseService() *BaseService

func (*BaseService) AddFilter

func (service *BaseService) AddFilter(filter Filter)

func (*BaseService) GetFilter

func (service *BaseService) GetFilter() Filter

func (*BaseService) Handle

func (service *BaseService) Handle(data []byte, context interface{}) (output []byte)

func (*BaseService) RemoveFilter

func (service *BaseService) RemoveFilter(filter Filter)

func (*BaseService) SetFilter

func (service *BaseService) SetFilter(filter Filter)

type BufReader

type BufReader interface {
	Read(p []byte) (n int, err error)
	ReadByte() (c byte, err error)
	ReadRune() (r rune, size int, err error)
	ReadString(delim byte) (line string, err error)
}

type BufWriter

type BufWriter interface {
	Write(p []byte) (n int, err error)
	WriteByte(c byte) error
	WriteRune(r rune) (n int, err error)
	WriteString(s string) (n int, err error)
}

type BytesReader

type BytesReader struct {
	// contains filtered or unexported fields
}

func NewBytesReader

func NewBytesReader(b []byte) *BytesReader

func (*BytesReader) Read

func (r *BytesReader) Read(b []byte) (n int, err error)

func (*BytesReader) ReadByte

func (r *BytesReader) ReadByte() (b byte, err error)

func (*BytesReader) ReadRune

func (r *BytesReader) ReadRune() (ch rune, size int, err error)

func (*BytesReader) ReadString

func (r *BytesReader) ReadString(delim byte) (line string, err error)

type Client

type Client interface {
	UseService(...interface{})
	Invoke(string, []interface{}, *InvokeOptions, interface{}) <-chan error
	Uri() string
	SetUri(string)
	GetFilter() Filter
	SetFilter(filter Filter)
	AddFilter(filter Filter)
	RemoveFilter(filter Filter)
	TLSClientConfig() *tls.Config
	SetTLSClientConfig(config *tls.Config)
	SetKeepAlive(enable bool)
	Close()
}

func NewClient

func NewClient(uri string) Client

func NewHttpClient

func NewHttpClient(uri string) Client

func NewTcpClient

func NewTcpClient(uri string) Client

type Filter

type Filter interface {
	InputFilter(data []byte, context interface{}) []byte
	OutputFilter(data []byte, context interface{}) []byte
}

type HttpClient

type HttpClient struct {
	*BaseClient
}

func (*HttpClient) Close

func (client *HttpClient) Close()

func (*HttpClient) Compression

func (client *HttpClient) Compression() bool

func (*HttpClient) Http

func (client *HttpClient) Http() *http.Client

func (*HttpClient) KeepAlive

func (client *HttpClient) KeepAlive() bool

func (*HttpClient) MaxIdleConnsPerHost

func (client *HttpClient) MaxIdleConnsPerHost() int

func (*HttpClient) SetCompression

func (client *HttpClient) SetCompression(enable bool)

func (*HttpClient) SetKeepAlive

func (client *HttpClient) SetKeepAlive(enable bool)

func (*HttpClient) SetMaxIdleConnsPerHost

func (client *HttpClient) SetMaxIdleConnsPerHost(value int)

func (*HttpClient) SetTLSClientConfig

func (client *HttpClient) SetTLSClientConfig(config *tls.Config)

func (*HttpClient) SetUri

func (client *HttpClient) SetUri(uri string)

func (*HttpClient) TLSClientConfig

func (client *HttpClient) TLSClientConfig() *tls.Config

type HttpContext

type HttpContext struct {
	Response http.ResponseWriter
	Request  *http.Request
}

type HttpService

type HttpService struct {
	*BaseService
	P3PEnabled         bool
	GetEnabled         bool
	CrossDomainEnabled bool
	// contains filtered or unexported fields
}

func NewHttpService

func NewHttpService() *HttpService

func (*HttpService) AddAccessControlAllowOrigin

func (service *HttpService) AddAccessControlAllowOrigin(origin string)

func (*HttpService) ClientAccessPolicyXmlContent

func (service *HttpService) ClientAccessPolicyXmlContent() []byte

func (*HttpService) ClientAccessPolicyXmlFile

func (service *HttpService) ClientAccessPolicyXmlFile() string

func (*HttpService) CrossDomainXmlContent

func (service *HttpService) CrossDomainXmlContent() []byte

func (*HttpService) CrossDomainXmlFile

func (service *HttpService) CrossDomainXmlFile() string

func (*HttpService) RemoveAccessControlAllowOrigin

func (service *HttpService) RemoveAccessControlAllowOrigin(origin string)

func (*HttpService) ServeHTTP

func (service *HttpService) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*HttpService) SetClientAccessPolicyXmlContent

func (service *HttpService) SetClientAccessPolicyXmlContent(content []byte)

func (*HttpService) SetClientAccessPolicyXmlFile

func (service *HttpService) SetClientAccessPolicyXmlFile(filename string)

func (*HttpService) SetCrossDomainXmlContent

func (service *HttpService) SetCrossDomainXmlContent(content []byte)

func (*HttpService) SetCrossDomainXmlFile

func (service *HttpService) SetCrossDomainXmlFile(filename string)

type HttpServiceEvent

type HttpServiceEvent interface {
	ServiceEvent
	OnSendHeader(response http.ResponseWriter, request *http.Request)
}

type HttpTransporter

type HttpTransporter struct {
	*http.Client
}

func (*HttpTransporter) SendAndReceive

func (h *HttpTransporter) SendAndReceive(uri string, data []byte) ([]byte, error)

type InvokeOptions

type InvokeOptions struct {
	ByRef      interface{} // true, false, nil
	SimpleMode interface{} // true, false, nil
	ResultMode ResultMode
}

type Method

type Method struct {
	Function   reflect.Value
	ResultMode ResultMode
	SimpleMode bool
}

type Methods

type Methods struct {
	MethodNames   []string
	RemoteMethods map[string]*Method
}

func NewMethods

func NewMethods() *Methods

func (*Methods) AddAllMethods

func (methods *Methods) AddAllMethods(obj interface{}, options ...interface{})

AddAllMethods will publish all methods and non-nil function fields on the obj self and on its anonymous or non-anonymous struct fields (or pointer to pointer ... to pointer struct fields). This is a recursive operation. So it's a pit, if you do not know what you are doing, do not step on.

func (*Methods) AddFunction

func (methods *Methods) AddFunction(name string, function interface{}, options ...interface{})

func (*Methods) AddFunctions

func (methods *Methods) AddFunctions(names []string, functions []interface{}, options ...interface{})

func (*Methods) AddMethods

func (methods *Methods) AddMethods(obj interface{}, options ...interface{})

func (*Methods) AddMissingMethod

func (methods *Methods) AddMissingMethod(method MissingMethod, options ...interface{})

type MissingMethod

type MissingMethod func(name string, args []reflect.Value) (result []reflect.Value)

type RawReader

type RawReader struct {
	// contains filtered or unexported fields
}

func NewRawReader

func NewRawReader(stream BufReader) *RawReader

func (*RawReader) ReadRaw

func (r *RawReader) ReadRaw() (raw []byte, err error)

func (*RawReader) ReadRawTo

func (r *RawReader) ReadRawTo(ostream BufWriter) (err error)

type Reader

type Reader struct {
	*RawReader
	// contains filtered or unexported fields
}

func NewReader

func NewReader(stream BufReader, simple bool) *Reader

func (*Reader) CheckTag

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

func (*Reader) CheckTags

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

func (*Reader) ReadArray

func (r *Reader) ReadArray(a []reflect.Value) error

func (*Reader) ReadBigInt

func (r *Reader) ReadBigInt() (*big.Int, error)

func (*Reader) ReadBigIntWithoutTag

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

func (*Reader) ReadBool

func (r *Reader) ReadBool() (bool, error)

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() (*[]byte, error)

func (*Reader) ReadBytesWithoutTag

func (r *Reader) ReadBytesWithoutTag() (*[]byte, error)

func (*Reader) ReadDateTime

func (r *Reader) ReadDateTime() (time.Time, error)

func (*Reader) ReadDateWithoutTag

func (r *Reader) ReadDateWithoutTag() (time.Time, error)

func (*Reader) ReadFloat32

func (r *Reader) ReadFloat32() (float32, error)

func (*Reader) ReadFloat32WithoutTag

func (r *Reader) ReadFloat32WithoutTag() (float32, error)

func (*Reader) ReadFloat64

func (r *Reader) ReadFloat64() (float64, error)

func (*Reader) ReadFloat64WithoutTag

func (r *Reader) ReadFloat64WithoutTag() (float64, error)

func (*Reader) ReadInt

func (r *Reader) ReadInt() (int, error)

func (*Reader) ReadInt16

func (r *Reader) ReadInt16() (int16, error)

func (*Reader) ReadInt16WithoutTag

func (r *Reader) ReadInt16WithoutTag() (int16, error)

func (*Reader) ReadInt32

func (r *Reader) ReadInt32() (int32, error)

func (*Reader) ReadInt32WithoutTag

func (r *Reader) ReadInt32WithoutTag() (int32, error)

func (*Reader) ReadInt64

func (r *Reader) ReadInt64() (int64, error)

func (*Reader) ReadInt64WithoutTag

func (r *Reader) ReadInt64WithoutTag() (int64, error)

func (*Reader) ReadInt8

func (r *Reader) ReadInt8() (int8, error)

func (*Reader) ReadInt8WithoutTag

func (r *Reader) ReadInt8WithoutTag() (int8, error)

func (*Reader) ReadIntWithoutTag

func (r *Reader) ReadIntWithoutTag() (int, error)

func (*Reader) ReadInteger

func (r *Reader) ReadInteger(tag byte) (int, error)

func (*Reader) ReadList

func (r *Reader) ReadList() (*list.List, error)

func (*Reader) ReadListWithoutTag

func (r *Reader) ReadListWithoutTag() (*list.List, error)

func (*Reader) ReadMap

func (r *Reader) ReadMap(p interface{}) error

func (*Reader) ReadMapWithoutTag

func (r *Reader) ReadMapWithoutTag(p interface{}) error

func (*Reader) ReadObject

func (r *Reader) ReadObject(p interface{}) error

func (*Reader) ReadObjectWithoutTag

func (r *Reader) ReadObjectWithoutTag(p interface{}) error

func (*Reader) ReadSlice

func (r *Reader) ReadSlice(p interface{}) error

func (*Reader) ReadSliceWithoutTag

func (r *Reader) ReadSliceWithoutTag(p interface{}) error

func (*Reader) ReadString

func (r *Reader) ReadString() (string, error)

func (*Reader) ReadStringWithoutTag

func (r *Reader) ReadStringWithoutTag() (str string, err error)

func (*Reader) ReadTimeWithoutTag

func (r *Reader) ReadTimeWithoutTag() (time.Time, error)

func (*Reader) ReadUUID

func (r *Reader) ReadUUID() (*UUID, error)

func (*Reader) ReadUUIDWithoutTag

func (r *Reader) ReadUUIDWithoutTag() (*UUID, error)

func (*Reader) ReadUint

func (r *Reader) ReadUint() (uint, error)

func (*Reader) ReadUint16

func (r *Reader) ReadUint16() (uint16, error)

func (*Reader) ReadUint16WithoutTag

func (r *Reader) ReadUint16WithoutTag() (uint16, error)

func (*Reader) ReadUint32

func (r *Reader) ReadUint32() (uint32, error)

func (*Reader) ReadUint32WithoutTag

func (r *Reader) ReadUint32WithoutTag() (uint32, error)

func (*Reader) ReadUint64

func (r *Reader) ReadUint64() (uint64, error)

func (*Reader) ReadUint64WithoutTag

func (r *Reader) ReadUint64WithoutTag() (uint64, error)

func (*Reader) ReadUint8

func (r *Reader) ReadUint8() (uint8, error)

func (*Reader) ReadUint8WithoutTag

func (r *Reader) ReadUint8WithoutTag() (uint8, error)

func (*Reader) ReadUintWithoutTag

func (r *Reader) ReadUintWithoutTag() (uint, error)

func (*Reader) ReadUinteger

func (r *Reader) ReadUinteger(tag byte) (uint, error)

func (*Reader) ReadValue

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

func (*Reader) Reset

func (r *Reader) Reset()

func (*Reader) Stream

func (r *Reader) Stream() BufReader

func (*Reader) Unserialize

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

type ResultMode

type ResultMode int

func (ResultMode) String

func (result_mode ResultMode) String() string

type ServiceEvent

type ServiceEvent interface {
	OnBeforeInvoke(name string, args []reflect.Value, byref bool, context interface{})
	OnAfterInvoke(name string, args []reflect.Value, byref bool, result []reflect.Value, context interface{})
	OnSendError(err error, context interface{})
}

type TcpClient

type TcpClient struct {
	*BaseClient
	// contains filtered or unexported fields
}

func (*TcpClient) Close

func (client *TcpClient) Close()

func (*TcpClient) SetKeepAlive

func (client *TcpClient) SetKeepAlive(keepalive bool)

func (*TcpClient) SetKeepAlivePeriod

func (client *TcpClient) SetKeepAlivePeriod(d time.Duration)

func (*TcpClient) SetLinger

func (client *TcpClient) SetLinger(sec int)

func (*TcpClient) SetNoDelay

func (client *TcpClient) SetNoDelay(noDelay bool)

func (*TcpClient) SetReadBuffer

func (client *TcpClient) SetReadBuffer(bytes int)

func (*TcpClient) SetReadTimeout

func (client *TcpClient) SetReadTimeout(d time.Duration)

func (*TcpClient) SetTLSClientConfig

func (client *TcpClient) SetTLSClientConfig(config *tls.Config)

func (*TcpClient) SetTimeout

func (client *TcpClient) SetTimeout(d time.Duration)

func (*TcpClient) SetUri

func (client *TcpClient) SetUri(uri string)

func (*TcpClient) SetWriteBuffer

func (client *TcpClient) SetWriteBuffer(bytes int)

func (*TcpClient) SetWriteTimeout

func (client *TcpClient) SetWriteTimeout(d time.Duration)

func (*TcpClient) TLSClientConfig

func (client *TcpClient) TLSClientConfig() *tls.Config

func (*TcpClient) Timeout

func (client *TcpClient) Timeout() time.Duration

type TcpConnEntry

type TcpConnEntry struct {
	// contains filtered or unexported fields
}

func (*TcpConnEntry) Close

func (connEntry *TcpConnEntry) Close()

func (*TcpConnEntry) Get

func (connEntry *TcpConnEntry) Get() net.Conn

func (*TcpConnEntry) Set

func (connEntry *TcpConnEntry) Set(conn net.Conn)

type TcpConnPool

type TcpConnPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TcpConnPool) Close

func (connPool *TcpConnPool) Close(uri string)

func (*TcpConnPool) Free

func (connPool *TcpConnPool) Free(entry *TcpConnEntry)

func (*TcpConnPool) Get

func (connPool *TcpConnPool) Get(uri string) *TcpConnEntry

func (*TcpConnPool) SetTimeout

func (connPool *TcpConnPool) SetTimeout(d time.Duration)

func (*TcpConnPool) Timeout

func (connPool *TcpConnPool) Timeout() time.Duration

type TcpServer

type TcpServer struct {
	*TcpService
	URL         string
	ThreadCount int
	// contains filtered or unexported fields
}

func NewTcpServer

func NewTcpServer(uri string) *TcpServer

func (*TcpServer) Start

func (server *TcpServer) Start() (err error)

func (*TcpServer) Stop

func (server *TcpServer) Stop()

type TcpService

type TcpService struct {
	*BaseService
	// contains filtered or unexported fields
}

func NewTcpService

func NewTcpService() *TcpService

func (*TcpService) ServeTCP

func (service *TcpService) ServeTCP(conn *net.TCPConn) (err error)

func (*TcpService) SetKeepAlive

func (service *TcpService) SetKeepAlive(keepalive bool)

func (*TcpService) SetKeepAlivePeriod

func (service *TcpService) SetKeepAlivePeriod(d time.Duration)

func (*TcpService) SetLinger

func (service *TcpService) SetLinger(sec int)

func (*TcpService) SetNoDelay

func (service *TcpService) SetNoDelay(noDelay bool)

func (*TcpService) SetReadBuffer

func (service *TcpService) SetReadBuffer(bytes int)

func (*TcpService) SetReadTimeout

func (service *TcpService) SetReadTimeout(d time.Duration)

func (*TcpService) SetTLSConfig

func (service *TcpService) SetTLSConfig(config *tls.Config)

func (*TcpService) SetTimeout

func (service *TcpService) SetTimeout(d time.Duration)

func (*TcpService) SetWriteBuffer

func (service *TcpService) SetWriteBuffer(bytes int)

func (*TcpService) SetWriteTimeout

func (service *TcpService) SetWriteTimeout(d time.Duration)

type TcpTransporter

type TcpTransporter struct {
	*TcpClient
	// contains filtered or unexported fields
}

func (*TcpTransporter) SendAndReceive

func (t *TcpTransporter) SendAndReceive(uri string, odata []byte) (idata []byte, err error)

type Transporter

type Transporter interface {
	SendAndReceive(uri string, data []byte) ([]byte, error)
}

type UUID

type UUID []byte

This type is only a UUID wrapper for hprose serialize/unserialize, If you want to generate UUIDs, you should use other UUID package.

func ToUUID

func ToUUID(s string) UUID

ToUUID decodes s into a UUID or returns nil. Both the UUID form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded.

func (UUID) String

func (uuid UUID) String() string

String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(stream BufWriter, simple bool) *Writer

func (*Writer) Reset

func (w *Writer) Reset()

func (*Writer) Serialize

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

func (*Writer) Stream

func (w *Writer) Stream() BufWriter

func (*Writer) WriteArray

func (w *Writer) WriteArray(v []reflect.Value) (err error)

func (*Writer) WriteBigInt

func (w *Writer) WriteBigInt(v *big.Int) (err error)

func (*Writer) WriteBool

func (w *Writer) WriteBool(v bool) error

func (*Writer) WriteBytes

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

func (*Writer) WriteBytesWithRef

func (w *Writer) WriteBytesWithRef(bytes []byte) (err error)

func (*Writer) WriteFloat64

func (w *Writer) WriteFloat64(v float64) (err error)

func (*Writer) WriteInt64

func (w *Writer) WriteInt64(v int64) (err error)

func (*Writer) WriteNull

func (w *Writer) WriteNull() error

func (*Writer) WriteString

func (w *Writer) WriteString(str string) (err error)

func (*Writer) WriteStringWithRef

func (w *Writer) WriteStringWithRef(str string) (err error)

func (*Writer) WriteTime

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

func (*Writer) WriteUint64

func (w *Writer) WriteUint64(v uint64) (err error)

func (*Writer) WriteValue

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

Jump to

Keyboard shortcuts

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