diff --git a/conn/message/message.go b/conn/message/message.go index c6549da0..1fc28070 100644 --- a/conn/message/message.go +++ b/conn/message/message.go @@ -73,7 +73,7 @@ type Message struct { ID uint // unique id, zero while notify mode Route string // route for locating service Data []byte // payload - compressed bool // is message compressed + Compressed bool // is message Compressed Err bool // is an error message } @@ -92,7 +92,7 @@ func (m *Message) String() string { types[m.Type], m.ID, m.Route, - m.compressed, + m.Compressed, m.Err, m.Data, len(m.Data)) @@ -146,6 +146,14 @@ func GetDictionary() map[string]uint16 { return dict } +func GetDictCode(route string) uint16 { + return routes[route] +} + +func GetDictRoute(code uint16) string { + return codes[code] +} + func (t *Type) String() string { return types[*t] } diff --git a/conn/message/message_decoder.go b/conn/message/message_decoder.go index fb39236c..49ae450e 100644 --- a/conn/message/message_decoder.go +++ b/conn/message/message_decoder.go @@ -81,7 +81,7 @@ func (md *MessagesDecoder) Decode(data []byte) (*Message, error) { if routable(m.Type) { if flag&msgRouteCompressMask == 1 { - m.compressed = true + m.Compressed = true code := binary.BigEndian.Uint16(data[offset:(offset + 2)]) routesCodesMutex.RLock() route, ok := codes[code] @@ -92,7 +92,7 @@ func (md *MessagesDecoder) Decode(data []byte) (*Message, error) { m.Route = route offset += 2 } else { - m.compressed = false + m.Compressed = false rl := data[offset] offset++ m.Route = string(data[offset:(offset + int(rl))]) diff --git a/conn/message/message_encoder.go b/conn/message/message_encoder.go index 5577c080..cc7e9c11 100644 --- a/conn/message/message_encoder.go +++ b/conn/message/message_encoder.go @@ -163,7 +163,7 @@ func Decode(data []byte) (*Message, error) { if routable(m.Type) { if flag&msgRouteCompressMask == 1 { - m.compressed = true + m.Compressed = true code := binary.BigEndian.Uint16(data[offset:(offset + 2)]) routesCodesMutex.RLock() route, ok := codes[code] @@ -174,7 +174,7 @@ func Decode(data []byte) (*Message, error) { m.Route = route offset += 2 } else { - m.compressed = false + m.Compressed = false rl := data[offset] offset++ m.Route = string(data[offset:(offset + int(rl))]) diff --git a/conn/message/message_test.go b/conn/message/message_test.go index 7528870e..0a46e47c 100644 --- a/conn/message/message_test.go +++ b/conn/message/message_test.go @@ -39,15 +39,15 @@ var encodeTables = map[string]struct { "test_wrong_type": {&Message{Type: 0xff, Data: []byte{}}, nil, false, 0x0, ErrWrongMessageType}, "test_request_type": {&Message{Type: Request, Route: "a", Data: []uint8{}}, nil, false, 0x0, nil}, - "test_request_type_compressed": {&Message{Type: Request, Route: "a", Data: []byte{}, compressed: true}, + "test_request_type_compressed": {&Message{Type: Request, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_notify_type": {&Message{Type: Notify, Route: "a", Data: []byte{}}, nil, false, 0x0, nil}, - "test_notify_type_compressed": {&Message{Type: Notify, Route: "a", Data: []byte{}, compressed: true}, + "test_notify_type_compressed": {&Message{Type: Notify, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_push_type": {&Message{Type: Push, Route: "a", Data: []byte{}}, nil, false, 0x0, nil}, - "test_push_type_compressed": {&Message{Type: Push, Route: "a", Data: []byte{}, compressed: true}, + "test_push_type_compressed": {&Message{Type: Push, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_reponse_type": {&Message{Type: Response, Data: []byte{}}, nil, false, 0x0, nil}, @@ -100,15 +100,15 @@ var decodeTables = map[string]struct { "test_wrong_type": {&Message{Type: 0xff, Data: []byte{}}, nil, false, 0x0, ErrWrongMessageType}, "test_request_type": {&Message{Type: Request, Route: "a", Data: []uint8{}}, nil, false, 0x0, nil}, - "test_request_type_compressed": {&Message{Type: Request, Route: "a", Data: []byte{}, compressed: true}, + "test_request_type_compressed": {&Message{Type: Request, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_notify_type": {&Message{Type: Notify, Route: "a", Data: []byte{}}, nil, false, 0x0, nil}, - "test_notify_type_compressed": {&Message{Type: Notify, Route: "a", Data: []byte{}, compressed: true}, + "test_notify_type_compressed": {&Message{Type: Notify, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_push_type": {&Message{Type: Push, Route: "a", Data: []byte{}}, nil, false, 0x0, nil}, - "test_push_type_compressed": {&Message{Type: Push, Route: "a", Data: []byte{}, compressed: true}, + "test_push_type_compressed": {&Message{Type: Push, Route: "a", Data: []byte{}, Compressed: true}, map[string]uint16{"a": 1}, false, 0x0, nil}, "test_reponse_type": {&Message{Type: Response, Data: []byte{}}, nil, false, 0x0, nil},