MCPcopy
hub / github.com/davyxu/cellnet / RegisterMessageMeta

Function RegisterMessageMeta

meta.go:143–173  ·  view source on GitHub ↗

* http消息 Method URL -> Meta Type -> Meta 非http消息 ID -> Meta Type -> Meta */ 注册消息元信息

(meta *MessageMeta)

Source from the content-addressed store, hash-verified

141
142// 注册消息元信息
143func RegisterMessageMeta(meta *MessageMeta) *MessageMeta {
144
145 // 注册时, 统一为非指针类型
146 if meta.Type.Kind() == reflect.Ptr {
147 meta.Type = meta.Type.Elem()
148 }
149
150 if _, ok := metaByType[meta.Type]; ok {
151 panic(fmt.Sprintf("Duplicate message meta register by type: %d name: %s", meta.ID, meta.Type.Name()))
152 } else {
153 metaByType[meta.Type] = meta
154 }
155
156 if _, ok := metaByFullName[meta.FullName()]; ok {
157 panic(fmt.Sprintf("Duplicate message meta register by fullname: %s", meta.FullName()))
158 } else {
159 metaByFullName[meta.FullName()] = meta
160 }
161
162 if meta.ID == 0 {
163 panic("message meta require 'ID' field: " + meta.TypeName())
164 }
165
166 if prev, ok := metaByID[meta.ID]; ok {
167 panic(fmt.Sprintf("Duplicate message meta register by id: %d type: %s, pre type: %s", meta.ID, meta.TypeName(), prev.TypeName()))
168 } else {
169 metaByID[meta.ID] = meta
170 }
171
172 return meta
173}
174
175// 根据名字查找消息元信息
176func MessageMetaByFullName(name string) *MessageMeta {

Callers 9

initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92

Calls 3

NameMethod · 0.65
TypeNameMethod · 0.65
FullNameMethod · 0.45

Tested by

no test coverage detected