Fix types to generated code.

This commit is contained in:
John Beisley 2013-10-06 22:39:16 +01:00
parent 574930a66a
commit e48908bf4c
2 changed files with 47 additions and 4 deletions

View File

@ -32,18 +32,18 @@ type {{$srvIdent}} struct {
// {{$reqType}} is the XML structure for the input arguments for action {{.Name}}. // {{$reqType}} is the XML structure for the input arguments for action {{.Name}}.
type {{$reqType}} struct {{"{"}}{{range .Arguments}}{{if .IsInput}} type {{$reqType}} struct {{"{"}}{{range .Arguments}}{{if .IsInput}}
{{.Name}} string {{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}}
{{end}}{{end}}} {{end}}{{end}}}
// {{$respType}} is the XML structure for the output arguments for action {{.Name}}. // {{$respType}} is the XML structure for the output arguments for action {{.Name}}.
type {{$respType}} struct {{"{"}}{{range .Arguments}}{{if .IsOutput}} type {{$respType}} struct {{"{"}}{{range .Arguments}}{{if .IsOutput}}
{{.Name}} string {{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}}
{{end}}{{end}}} {{end}}{{end}}}
func (client *{{$srvIdent}}) {{.Name}}({{range .Arguments}}{{if .IsInput}} func (client *{{$srvIdent}}) {{.Name}}({{range .Arguments}}{{if .IsInput}}
{{.Name}} string, {{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}},
{{end}}{{end}}) ({{range .Arguments}}{{if .IsOutput}} {{end}}{{end}}) ({{range .Arguments}}{{if .IsOutput}}
{{.Name}} string, {{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}},
{{end}}{{end}} err error) { {{end}}{{end}} err error) {
request := {{$reqType}}{ request := {{$reqType}}{
{{range .Arguments}}{{if .IsInput}} {{range .Arguments}}{{if .IsInput}}

View File

@ -37,6 +37,49 @@ func (scpd *SCPD) Clean() {
} }
} }
var dataTypeToGoKindName = map[string]string{
"ui1": "byte",
"ui2": "uint16",
"ui4": "uint32",
"i1": "int8",
"i2": "int16",
"i4": "int32",
"int": "int64",
"float": "float32",
"r4": "float32",
"r8": "float64",
// "fixed.14.4" ~ "float64"
"number": "float64",
"char": "string",
"string": "string",
// "date"
// "dateTime"
// "dateTime.tz"
// "boolean"
// "bin.base64"
// "bin.hex"
// "uri"
// "uuid"
}
// Returns the name of the Go "kind" of type for the named state variable. If
// the state variable is unknown, returns default_.
func (scpd *SCPD) GoKindNameForVariable(variable string, default_ string) string {
for i := range scpd.StateVariables {
v := &scpd.StateVariables[i]
if v.Name != variable {
continue
}
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
return kindName
} else {
return default_
}
}
return default_
}
// SpecVersion is part of a SCPD document, describes the version of the // SpecVersion is part of a SCPD document, describes the version of the
// specification that the data adheres to. // specification that the data adheres to.
type SpecVersion struct { type SpecVersion struct {