@@ -17,7 +17,7 @@ type context struct {
1717// 消息元信息
1818type MessageMeta struct {
1919 Codec Codec // 消息用到的编码
20- Type reflect.Type // 消息类型
20+ Type reflect.Type // 消息类型, 注册时使用指针类型
2121
2222 ID int // 消息ID (二进制协议中使用)
2323
@@ -31,10 +31,6 @@ func (self *MessageMeta) TypeName() string {
3131 return ""
3232 }
3333
34- if self .Type .Kind () == reflect .Ptr {
35- return self .Type .Elem ().Name ()
36- }
37-
3834 return self .Type .Name ()
3935}
4036
@@ -44,15 +40,10 @@ func (self *MessageMeta) FullName() string {
4440 return ""
4541 }
4642
47- rtype := self .Type
48- if rtype .Kind () == reflect .Ptr {
49- rtype = rtype .Elem ()
50- }
51-
5243 var sb strings.Builder
53- sb .WriteString (path .Base (rtype .PkgPath ()))
44+ sb .WriteString (path .Base (self . Type .PkgPath ()))
5445 sb .WriteString ("." )
55- sb .WriteString (rtype .Name ())
46+ sb .WriteString (self . Type .Name ())
5647
5748 return sb .String ()
5849}
@@ -151,7 +142,10 @@ Type -> Meta
151142// 注册消息元信息
152143func RegisterMessageMeta (meta * MessageMeta ) * MessageMeta {
153144
154- // 非http类,才需要包装Type必须唯一
145+ // 注册时, 统一为非指针类型
146+ if meta .Type .Kind () == reflect .Ptr {
147+ meta .Type = meta .Type .Elem ()
148+ }
155149
156150 if _ , ok := metaByType [meta .Type ]; ok {
157151 panic (fmt .Sprintf ("Duplicate message meta register by type: %d name: %s" , meta .ID , meta .Type .Name ()))
0 commit comments