Skip to content

Commit

Permalink
change raw handler
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Sep 6, 2016
1 parent 308dca4 commit e2fc311
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
7 changes: 1 addition & 6 deletions network/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ func (p *Processor) SetHandler(msg interface{}, msgHandler MsgHandler) {
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
func (p *Processor) SetRawHandler(msg interface{}, msgRawHandler MsgHandler) {
msgType := reflect.TypeOf(msg)
if msgType == nil || msgType.Kind() != reflect.Ptr {
log.Fatal("json message pointer required")
}
msgID := msgType.Elem().Name()
func (p *Processor) SetRawHandler(msgID string, msgRawHandler MsgHandler) {
i, ok := p.msgInfo[msgID]
if !ok {
log.Fatal("message %v not registered", msgID)
Expand Down
8 changes: 3 additions & 5 deletions network/protobuf/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ func (p *Processor) SetHandler(msg proto.Message, msgHandler MsgHandler) {
}

// It's dangerous to call the method on routing or marshaling (unmarshaling)
func (p *Processor) SetRawHandler(msg proto.Message, msgRawHandler MsgHandler) {
msgType := reflect.TypeOf(msg)
id, ok := p.msgID[msgType]
if !ok {
log.Fatal("message %s not registered", msgType)
func (p *Processor) SetRawHandler(id uint16, msgRawHandler MsgHandler) {
if id >= uint16(len(p.msgInfo)) {
log.Fatal("message id %v not registered", id)
}

p.msgInfo[id].msgRawHandler = msgRawHandler
Expand Down

0 comments on commit e2fc311

Please sign in to comment.