(msg interface{})
| 267 | } |
| 268 | |
| 269 | func MessageSize(msg interface{}) int { |
| 270 | |
| 271 | if msg == nil { |
| 272 | return 0 |
| 273 | } |
| 274 | |
| 275 | // 获取消息元信息 |
| 276 | meta := MessageMetaByType(reflect.TypeOf(msg)) |
| 277 | if meta == nil { |
| 278 | return 0 |
| 279 | } |
| 280 | |
| 281 | // 将消息编码为字节数组 |
| 282 | raw, err := meta.Codec.Encode(msg, nil) |
| 283 | |
| 284 | if err != nil { |
| 285 | return 0 |
| 286 | } |
| 287 | |
| 288 | return len(raw.([]byte)) |
| 289 | } |
| 290 | |
| 291 | func MessageToString(msg interface{}) string { |
| 292 |
no test coverage detected