Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Jul 28, 2023
1 parent c48bd19 commit 6f0fd72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions dataplane/standalone/apigen/apigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ var saiTypeToProtoTypeCompound = map[string]func(subType string, xmlInfo *xmlInf
// saiTypeToProtoType returns the protobuf type string for a SAI type.
// example: sai_u8_list_t -> repeated uint32
func saiTypeToProtoType(saiType string, xmlInfo *xmlInfo) (string, error) {
typ := ""

var typ string
if protoType, ok := saiTypeToProto[saiType]; ok {
typ = protoType.ProtoType
if protoType.Repeated {
Expand All @@ -500,9 +499,11 @@ func saiTypeToProtoType(saiType string, xmlInfo *xmlInfo) (string, error) {
} else if _, ok := xmlInfo.enums[saiType]; ok {
typ = saiType
} else if splits := strings.Split(saiType, " "); len(splits) == 2 {
if fn, ok := saiTypeToProtoTypeCompound[splits[0]]; ok {
typ = fn(splits[1], xmlInfo)
fn, ok := saiTypeToProtoTypeCompound[splits[0]]
if !ok {
return "", fmt.Errorf("unknown sai type: %v", saiType)
}
typ = fn(splits[1], xmlInfo)
} else {
return "", fmt.Errorf("unknown sai type: %v", saiType)
}
Expand Down Expand Up @@ -588,6 +589,7 @@ func generate() error {
}
ccData.Funcs = append(ccData.Funcs, tf)

// TODO: handle proto in its own func.
msg := protoTmplMessage{
RequestName: strcase.UpperCamelCase(tf.Name + "_request"),
ResponseName: strcase.UpperCamelCase(tf.Name + "_response"),
Expand Down
6 changes: 4 additions & 2 deletions dataplane/standalone/apigen/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func handleEnumAttr(enum MemberDef) attrInfo {
return info
}

func handleEnum(enum MemberDef) []string {
func memberToEnumValueStrings(enum MemberDef) []string {
res := []string{}
for _, value := range enum.EnumValues {
res = append(res, value.Name)
Expand Down Expand Up @@ -171,7 +171,7 @@ func parseXMLFile(file string, xmlInfo *xmlInfo) error {
info := handleEnumAttr(enum)
xmlInfo.attrs[strings.ToUpper(matches[1])] = info
} else {
xmlInfo.enums[strings.TrimPrefix(enum.Name, "_")] = handleEnum(enum)
xmlInfo.enums[strings.TrimPrefix(enum.Name, "_")] = memberToEnumValueStrings(enum)
}
}
return nil
Expand All @@ -193,6 +193,8 @@ type attrTypeName struct {

// xmlInfo contains all the info parsed from the doxygen.
type xmlInfo struct {
// attrs is a map from sai type (sai_port_t) to its attributes.
attrs map[string]attrInfo
// attrs is a map from enum name (sai_port_media_type_t) to the values of the enum.
enums map[string][]string
}

0 comments on commit 6f0fd72

Please sign in to comment.