in metadata.go [1343:1425]
func (t *typeParser) parse() typeParserResult {
// parse the AST
ast, ok := t.parseClassNode()
if !ok {
// treat this is a custom type
return typeParserResult{
isComposite: false,
types: []TypeInfo{
NativeType{
typ: TypeCustom,
custom: t.input,
proto: t.proto,
},
},
reversed: []bool{false},
collections: nil,
}
}
// interpret the AST
if strings.HasPrefix(ast.name, COMPOSITE_TYPE) {
count := len(ast.params)
// look for a collections param
last := ast.params[count-1]
collections := map[string]TypeInfo{}
if strings.HasPrefix(last.class.name, COLLECTION_TYPE) {
count--
for _, param := range last.class.params {
// decode the name
var name string
decoded, err := hex.DecodeString(*param.name)
if err != nil {
t.logger.Printf(
"Error parsing type '%s', contains collection name '%s' with an invalid format: %v",
t.input,
*param.name,
err,
)
// just use the provided name
name = *param.name
} else {
name = string(decoded)
}
collections[name] = param.class.asTypeInfo()
}
}
types := make([]TypeInfo, count)
reversed := make([]bool, count)
for i, param := range ast.params[:count] {
class := param.class
reversed[i] = strings.HasPrefix(class.name, REVERSED_TYPE)
if reversed[i] {
class = class.params[0].class
}
types[i] = class.asTypeInfo()
}
return typeParserResult{
isComposite: true,
types: types,
reversed: reversed,
collections: collections,
}
} else {
// not composite, so one type
class := *ast
reversed := strings.HasPrefix(class.name, REVERSED_TYPE)
if reversed {
class = class.params[0].class
}
typeInfo := class.asTypeInfo()
return typeParserResult{
isComposite: false,
types: []TypeInfo{typeInfo},
reversed: []bool{reversed},
}
}
}