| 12345678910111213141516171819202122232425 |
- package comp
- import (
- pb "git.wanbits.io/joe/franklin/protos"
- "github.com/golang/protobuf/proto"
- "strings"
- )
- // 根据 Pb 协议结构体,获得协议字符串名称
- func GetMsgName(st proto.Message) string {
- name := proto.MessageReflect(st).Descriptor().FullName()
- //name := proto.MessageName(st)
- parts := strings.Split(string(name), ".")
- return parts[len(parts)-1]
- }
- // 根据协议名称获得协议ID
- func GetMsgId(name string) int32 {
- msg_id, ok := pb.MsgId_value[name]
- if !ok {
- return -1
- }
- return msg_id
- }
|