Esempio n. 1
0
func NewMessageMeta(msg interface{}) *MessageMeta {

	msgType := reflect.TypeOf(msg)

	if msgType.Kind() == reflect.Ptr {
		msgType = msgType.Elem()
	}

	msgName := msgType.String()

	return &MessageMeta{
		Type: msgType,
		Name: msgName,
		ID:   int(util.StringHashNoCase(msgName)),
	}
}
Esempio n. 2
0
func Name2ID(name string) int {

	return int(util.StringHashNoCase(name))
}
Esempio n. 3
0
func Type2ID(msg proto.Message) int {

	name := reflect.TypeOf(msg).Elem().String()

	return int(util.StringHashNoCase(name))
}
Esempio n. 4
0
File: file.go Progetto: Rsl4/cellnet
func printFile(gen *Generator, file *pbmeta.FileDescriptor) {

	gen.Println("// Generated by github.com/davyxu/cellnet/protoc-gen-msg")
	gen.Println("// DO NOT EDIT!")
	gen.Println("// Source: ", file.FileName())

	gen.In()
	for _, v := range file.Define.Dependency {
		gen.Println("// ", v)
	}
	gen.Out()

	gen.Println("package ", file.PackageName())
	gen.Println()
	gen.Println("import (")
	gen.In()
	gen.Println("\"github.com/davyxu/cellnet\"")
	gen.Out()
	gen.Println(")")

	gen.Println()
	gen.Println("func init() {")
	gen.In()

	for i := 0; i < file.MessageCount(); i++ {

		msg := file.Message(i)

		msgFullName := file.PackageName() + "." + msg.Name()

		gen.Println("cellnet.RegisterMessageMeta(\"", msgFullName, "\", (*", msg.Name(), ")(nil), ", int(util.StringHashNoCase(msgFullName)), ")")
	}

	gen.Out()
	gen.Println("}")

}