Skip to content

Commit

Permalink
return message id
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Sep 6, 2016
1 parent 3e29cf9 commit 308dca4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion network/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewProcessor() *Processor {
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
func (p *Processor) Register(msg interface{}) {
func (p *Processor) Register(msg interface{}) string {
msgType := reflect.TypeOf(msg)
if msgType == nil || msgType.Kind() != reflect.Ptr {
log.Fatal("json message pointer required")
Expand All @@ -50,6 +50,7 @@ func (p *Processor) Register(msg interface{}) {
i := new(MsgInfo)
i.msgType = msgType
p.msgInfo[msgID] = i
return msgID
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
Expand Down
6 changes: 4 additions & 2 deletions network/protobuf/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Processor) SetByteOrder(littleEndian bool) {
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
func (p *Processor) Register(msg proto.Message) {
func (p *Processor) Register(msg proto.Message) uint16 {
msgType := reflect.TypeOf(msg)
if msgType == nil || msgType.Kind() != reflect.Ptr {
log.Fatal("protobuf message pointer required")
Expand All @@ -62,7 +62,9 @@ func (p *Processor) Register(msg proto.Message) {
i := new(MsgInfo)
i.msgType = msgType
p.msgInfo = append(p.msgInfo, i)
p.msgID[msgType] = uint16(len(p.msgInfo) - 1)
id := uint16(len(p.msgInfo) - 1)
p.msgID[msgType] = id
return id
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
Expand Down

0 comments on commit 308dca4

Please sign in to comment.