func convertMessageType(curPkg *ProtoPackage, msg *descriptor.DescriptorProto) (schema []*Field, err error) { if glog.V(4) { glog.Info("Converting message: ", proto.MarshalTextString(msg)) } for _, fieldDesc := range msg.GetField() { field, err := convertField(curPkg, fieldDesc, msg) if err != nil { glog.Errorf("Failed to convert field %s in %s: %v", fieldDesc.GetName(), msg.GetName(), err) return nil, err } schema = append(schema, field) } return }
func relativelyLookupNestedType(desc *descriptor.DescriptorProto, name string) (*descriptor.DescriptorProto, bool) { components := strings.Split(name, ".") componentLoop: for _, component := range components { for _, nested := range desc.GetNestedType() { if nested.GetName() == component { desc = nested continue componentLoop } } glog.Infof("no such nested message %s in %s", component, desc.GetName()) return nil, false } return desc, true }
func registerType(pkgName *string, msg *descriptor.DescriptorProto) { pkg := globalPkg if pkgName != nil { for _, node := range strings.Split(*pkgName, ".") { if pkg == globalPkg && node == "" { // Skips leading "." continue } child, ok := pkg.children[node] if !ok { child = &ProtoPackage{ name: pkg.name + "." + node, parent: pkg, children: make(map[string]*ProtoPackage), types: make(map[string]*descriptor.DescriptorProto), } pkg.children[node] = child } pkg = child } } pkg.types[msg.GetName()] = msg }