hessian

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TAG_READ        = int32(-1)
	ASCII_GAP       = 32
	CHUNK_SIZE      = 4096
	BC_BINARY       = byte('B') // final chunk
	BC_BINARY_CHUNK = byte('A') // non-final chunk

	BC_BINARY_DIRECT  = byte(0x20) // 1-byte length binary
	BINARY_DIRECT_MAX = byte(0x0f)
	BC_BINARY_SHORT   = byte(0x34) // 2-byte length binary
	BINARY_SHORT_MAX  = 0x3ff      // 0-1023 binary

	BC_DATE        = byte(0x4a) // 64-bit millisecond UTC date
	BC_DATE_MINUTE = byte(0x4b) // 32-bit minute UTC date

	BC_DOUBLE = byte('D') // IEEE 64-bit double

	BC_DOUBLE_ZERO  = byte(0x5b)
	BC_DOUBLE_ONE   = byte(0x5c)
	BC_DOUBLE_BYTE  = byte(0x5d)
	BC_DOUBLE_SHORT = byte(0x5e)
	BC_DOUBLE_MILL  = byte(0x5f)

	BC_FALSE = byte('F') // boolean false

	BC_INT = byte('I') // 32-bit int

	INT_DIRECT_MIN = -0x10
	INT_DIRECT_MAX = byte(0x2f)
	BC_INT_ZERO    = byte(0x90)

	INT_BYTE_MIN     = -0x800
	INT_BYTE_MAX     = 0x7ff
	BC_INT_BYTE_ZERO = byte(0xc8)

	BC_END = byte('Z')

	INT_SHORT_MIN     = -0x40000
	INT_SHORT_MAX     = 0x3ffff
	BC_INT_SHORT_ZERO = byte(0xd4)

	BC_LIST_VARIABLE         = byte(0x55)
	BC_LIST_FIXED            = byte('V')
	BC_LIST_VARIABLE_UNTYPED = byte(0x57)
	BC_LIST_FIXED_UNTYPED    = byte(0x58)

	BC_LIST_DIRECT         = byte(0x70)
	BC_LIST_DIRECT_UNTYPED = byte(0x78)
	LIST_DIRECT_MAX        = byte(0x7)

	BC_LONG         = byte('L') // 64-bit signed integer
	LONG_DIRECT_MIN = -0x08
	LONG_DIRECT_MAX = byte(0x0f)
	BC_LONG_ZERO    = byte(0xe0)

	LONG_BYTE_MIN     = -0x800
	LONG_BYTE_MAX     = 0x7ff
	BC_LONG_BYTE_ZERO = byte(0xf8)

	LONG_SHORT_MIN     = -0x40000
	LONG_SHORT_MAX     = 0x3ffff
	BC_LONG_SHORT_ZERO = byte(0x3c)

	BC_LONG_INT = byte(0x59)

	BC_MAP         = byte('M')
	BC_MAP_UNTYPED = byte('H')

	BC_NULL = byte('N') // x4e

	BC_OBJECT     = byte('O')
	BC_OBJECT_DEF = byte('C')

	BC_OBJECT_DIRECT  = byte(0x60)
	OBJECT_DIRECT_MAX = byte(0x0f)

	BC_REF = byte(0x51)

	BC_STRING       = byte('S') // final string
	BC_STRING_CHUNK = byte('R') // non-final string

	BC_STRING_DIRECT  = byte(0x00)
	STRING_DIRECT_MAX = byte(0x1f)
	BC_STRING_SHORT   = byte(0x30)
	STRING_SHORT_MAX  = 0x3ff

	BC_TRUE = byte('T')

	P_PACKET_CHUNK = byte(0x4f)
	P_PACKET       = byte('P')

	P_PACKET_DIRECT   = byte(0x80)
	PACKET_DIRECT_MAX = byte(0x7f)

	P_PACKET_SHORT   = byte(0x70)
	PACKET_SHORT_MAX = 0xfff
	ARRAY_STRING     = "[string"
	ARRAY_INT        = "[int"
	ARRAY_DOUBLE     = "[double"
	ARRAY_FLOAT      = "[float"
	ARRAY_BOOL       = "[boolean"
	ARRAY_LONG       = "[long"

	PATH_KEY      = "path"
	INTERFACE_KEY = "interface"
	VERSION_KEY   = "version"
	TIMEOUT_KEY   = "timeout"

	STRING_NIL   = "null"
	STRING_TRUE  = "true"
	STRING_FALSE = "false"
	STRING_ZERO  = "0.0"
	STRING_ONE   = "1.0"
)
View Source
const (
	// header length.
	HEADER_LENGTH = 16

	// magic header
	MAGIC      = uint16(0xdabb)
	MAGIC_HIGH = byte(0xda)
	MAGIC_LOW  = byte(0xbb)

	// message flag.
	FLAG_REQUEST = byte(0x80)
	FLAG_TWOWAY  = byte(0x40)
	FLAG_EVENT   = byte(0x20) // for heartbeat
	SERIAL_MASK  = 0x1f

	DUBBO_VERSION = "2.5.4"
	DEFAULT_LEN   = 8388608 // 8 * 1024 * 1024 default body max length
)

*

  • 协议头是16字节的定长数据
  • 2字节magic字符串0xdabb,0-7高位,8-15低位
  • 1字节的消息标志位。16-20序列id,21 event,22 two way,23请求或响应标识
  • 1字节状态。当消息类型为响应时,设置响应状态。24-31位。
  • 8字节,消息ID,long类型,32-95位。
  • 4字节,消息长度,96-127位 *
View Source
const (
	Response_OK                byte = 20
	Response_CLIENT_TIMEOUT    byte = 30
	Response_SERVER_TIMEOUT    byte = 31
	Response_BAD_REQUEST       byte = 40
	Response_BAD_RESPONSE      byte = 50
	Response_SERVICE_NOT_FOUND byte = 60
	Response_SERVICE_ERROR     byte = 70
	Response_SERVER_ERROR      byte = 80
	Response_CLIENT_ERROR      byte = 90

	RESPONSE_WITH_EXCEPTION int32 = 0
	RESPONSE_VALUE          int32 = 1
	RESPONSE_NULL_VALUE     int32 = 2
)
View Source
const (
	// dubbogo version
	Version string = "2.0.0"
	DATE           = "2018/04/27"
)

Variables

View Source
var (
	ErrNotEnoughBuf    = jerrors.Errorf("not enough buf")
	ErrIllegalRefIndex = jerrors.Errorf("illegal ref index")
)

Functions

func NewCodec

func NewCodec(rwc io.ReadWriteCloser) codec.Codec

func PackFloat64

func PackFloat64(v float64) []byte

[10].pack('G').bytes => [64, 36, 0, 0, 0, 0, 0, 0] func PackFloat64(v float64, b []byte) []byte { 直接使用math库相关函数优化float64的pack/unpack

func PackInt16

func PackInt16(v int16) []byte

[10].pack('N').bytes => [0, 0, 0, 10] func PackInt16(v int16, b []byte) []byte {

func PackInt32

func PackInt32(v int32) []byte

[10].pack('N').bytes => [0, 0, 0, 10] func PackInt32(v int32, b []byte) []byte {

func PackInt64

func PackInt64(v int64) []byte

[10].pack('q>').bytes => [0, 0, 0, 0, 0, 0, 0, 10] func PackInt64(v int64, b []byte) []byte {

func PackInt8

func PackInt8(v int8, b []byte) []byte

func PackUint16

func PackUint16(v uint16) []byte

[10].pack('N').bytes => [0, 0, 0, 10] func PackUint16(v uint16, b []byte) []byte {

func ReflectResponse

func ReflectResponse(in interface{}, out interface{}) error

reflect return value

func RegisterJavaEnum

func RegisterJavaEnum(o POJOEnum) int

Register a value type JavaEnum variable.

func RegisterPOJO

func RegisterPOJO(o POJO) int

Register a POJO instance. The return value is -1 if @o has been registered.

# definition for an object (compact map) class-def ::= 'C' string int string*

func SprintHex

func SprintHex(b []byte) (rs string)

将字节数组格式化成 hex

func UnpackFloat64

func UnpackFloat64(b []byte) float64

Double (0,8).unpack('G)

func UnpackInt16

func UnpackInt16(b []byte) int16

(0,2).unpack('n')

func UnpackInt32

func UnpackInt32(b []byte) int32

(0,4).unpack('N')

func UnpackInt64

func UnpackInt64(b []byte) int64

long (0,8).unpack('q>')

func UnpackUint16

func UnpackUint16(b []byte) uint16

(0,2).unpack('n')

Types

type Decoder

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

func NewDecoder

func NewDecoder(b []byte) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode() (interface{}, error)

解析 hessian 数据包

type Encoder

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

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Append

func (e *Encoder) Append(buf []byte)

func (*Encoder) Buffer

func (e *Encoder) Buffer() []byte

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

If @v can not be encoded, the return value is nil. At present only struct may can not be encoded.

type JavaEnum

type JavaEnum int32
const (
	InvalidJavaEnum JavaEnum = -1
)

type JavaEnumClass

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

type POJO

type POJO interface {
	JavaClassName() string // 获取对应的java classs的package name
}

Pls attention that Every field name should be upper case. Otherwise the app may panic.

type POJOEnum

type POJOEnum interface {
	POJO
	String() string
	EnumValue(string) JavaEnum
}

type POJORegistry

type POJORegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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