helper.go 532 B

12345678910111213141516171819202122232425
  1. package comp
  2. import (
  3. "git.wanbits.io/joe/franklin/protos"
  4. "github.com/golang/protobuf/proto"
  5. "strings"
  6. )
  7. // 根据 Pb 协议结构体,获得协议字符串名称
  8. func GetMsgName(st proto.Message) string {
  9. name := proto.MessageReflect(st).Descriptor().FullName()
  10. //name := proto.MessageName(st)
  11. parts := strings.Split(string(name), ".")
  12. return parts[len(parts)-1]
  13. }
  14. // 根据协议名称获得协议ID
  15. func GetMsgId(name string) int32 {
  16. msg_id, ok := protos.MsgId_value[name]
  17. if !ok {
  18. return -1
  19. }
  20. return msg_id
  21. }