Documentation ¶
Index ¶
- Constants
- Variables
- func Encode(m *Message, routes map[string]uint16) ([]byte, error)
- func GetSerializer(typ uint16) serialize.Serializer
- func GetSerializerType(s serialize.Serializer) uint16
- func ParseDictionary(dict map[string]uint16) (map[string]uint16, map[uint16]string)
- func ReadDictionary() (map[string]uint16, map[uint16]string)
- func ReadSerializers() map[string]serialize.Serializer
- func RouteSerialize(serializers map[string]serialize.Serializer, route string, v interface{}) ([]byte, error)
- func Serialize(v interface{}) ([]byte, error)
- func ShortVersion(version string) uint32
- func WriteDictionary(dict map[string]uint16) (map[string]uint16, map[uint16]string)
- func WriteDictionaryItem(route string, code uint16) (map[string]uint16, map[uint16]string)
- func WriteSerializerItem(route string, typ uint16) map[string]serialize.Serializer
- func WriteSerializers(serializers map[string]uint16) map[string]serialize.Serializer
- type Message
- type Type
Constants ¶
const ( Unknown uint16 = iota JSON Protobuf RawString )
Variables ¶
var ( // Routes is a map from route to code Routes = make(map[string]uint16) // Codes is a map from code to route Codes = make(map[uint16]string) )
var ( ErrWrongMessageType = errors.New("wrong message type") ErrInvalidMessage = errors.New("invalid message") ErrRouteInfoNotFound = errors.New("route info not found in dictionary") ErrInvalidRouteLength = errors.New("invalid route length") )
Errors that could be occurred in message codec
var ( // Serializers is a map from route to serializer Serializers = make(map[string]serialize.Serializer) )
Functions ¶
func Encode ¶
Encode marshals message to binary format. Different message types is corresponding to different message header, message types is identified by 2-4 bit of flag field. The relationship between message types and message header is presented as follows: The figure above indicates that the bit does not affect the type of message. See ref: https://github.com/lonnng/nano/blob/master/docs/communication_protocol.md
func GetSerializer ¶
func GetSerializer(typ uint16) serialize.Serializer
func GetSerializerType ¶
func GetSerializerType(s serialize.Serializer) uint16
func ParseDictionary ¶
ParseDictionary parses dictionary into routes and codes independently
func ReadDictionary ¶
ReadDictionary returns dictionary for compressed route.
func ReadSerializers ¶
func ReadSerializers() map[string]serialize.Serializer
ReadSerializers returns serializers for compressed route.
func RouteSerialize ¶
func ShortVersion ¶
func WriteDictionary ¶
WriteDictionary is to set dictionary when new route dictionary is found.
func WriteDictionaryItem ¶
WriteDictionaryItem is to set dictionary item when server registers.
func WriteSerializerItem ¶
func WriteSerializerItem(route string, typ uint16) map[string]serialize.Serializer
WriteSerializerItem is to set serializer item when server registers.
func WriteSerializers ¶
func WriteSerializers(serializers map[string]uint16) map[string]serialize.Serializer
WriteSerializers is to set serializers when new serializer dictionary is found.
Types ¶
type Message ¶
type Message struct { Type Type // message type ShortVer uint32 // message short version ID uint64 // unique id, zero while notify mode Route string // route for locating service Data []byte // payload Compressed bool // is message compressed }
Message represents a unmarshaled message or a message which to be marshaled