Skip to content

Commit 841a251

Browse files
authored
Merge pull request #33 from UlfBj/master
Allowed support
2 parents 91b367e + 944345a commit 841a251

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

tools/himTools.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func getNode(scanner *bufio.Scanner, nextNodeName string) (string, PropertyData,
9999
thisNode.Datatype = value
100100
case "allowed":
101101
thisNode.Allowed, nextLine, continueScan = getAllowedValues(scanner)
102+
//fmt.Printf("getAllowedValues: len(thisNode.Allowed)=%d\n", len(thisNode.Allowed))
102103
case "min":
103104
thisNode.Min = value
104105
case "max":
@@ -184,7 +185,10 @@ func exportYaml(ctx VspecContext, node PropertyData) {
184185
ctx.ExporterFp.Write([]byte(string(indent) + ` datatype: ` + node.Datatype + "\n"))
185186
}
186187
if len(node.Allowed) > 0 {
187-
ctx.ExporterFp.Write([]byte(string(indent) + ` allowed: [` + node.Allowed[0] + "]\n"))
188+
ctx.ExporterFp.Write([]byte(string(indent) + ` allowed:` + "\n"))
189+
for i := 0; i < len(node.Allowed); i++ {
190+
ctx.ExporterFp.Write([]byte(string(indent) + node.Allowed[i] + "\n"))
191+
}
188192
}
189193
if len(node.Min) > 0 {
190194
ctx.ExporterFp.Write([]byte(string(indent) + ` min: ` + node.Min + "\n"))
@@ -243,7 +247,7 @@ func exportBinary(ctx VspecContext, thisNode PropertyData) {
243247
ctx.ExporterFp.Write(serializeUInt((uint16)(allowedStrLen)))
244248
if len(thisNode.Allowed) > 0 {
245249
for i := 0; i < len(thisNode.Allowed); i++ {
246-
allowedWrite(ctx.ExporterFp, thisNode.Allowed[i])
250+
allowedBinaryWrite(ctx.ExporterFp, thisNode.Allowed[i])
247251
}
248252
}
249253

@@ -309,7 +313,7 @@ func calculatAllowedStrLen(allowed []string) int {
309313
return strLen
310314
}
311315

312-
func allowedWrite(fp *os.File, allowed string) {
316+
func allowedBinaryWrite(fp *os.File, allowed string) {
313317
fp.Write(intToHex(len(allowed)))
314318
//fmt.Printf("allowedHexLen: %s\n", string(intToHex(len(allowed))))
315319
fp.Write([]byte(allowed))
@@ -507,14 +511,21 @@ func mapToExporterL1(ctx VspecContext, nodeName string, exporterMapL1 map[string
507511
// fmt.Println(k,": ", vvv)
508512
setNodeData(&nodeData, k ,vvv)
509513
case interface{}:
510-
mapToExporterL1(ctx, k, vvv.(map[string]interface{}))
511-
nodeData.Children++
514+
switch vvvv := vvv.(type) {
515+
case map[string]interface{}:
516+
mapToExporterL1(ctx, k, vvvv)
517+
nodeData.Children++
518+
case []interface{}:
519+
for i := 0; i < len(vvvv); i++ {
520+
setNodeData(&nodeData, k ,vvvv[i].(string))
521+
}
522+
nodeData.Children++
523+
}
512524
}
513525
default:
514526
fmt.Println(vv, "is of an unknown type")
515527
}
516528
}
517-
//fmt.Printf("Node=%s, Children=%d\n", nodeData.Name, nodeData.Children)
518529
if len(nodeName) > 0 {
519530
ctx.Exporter(ctx, nodeData)
520531
}
@@ -527,7 +538,7 @@ func setNodeData(nodeData *PropertyData, key string,value string) {
527538
case "datatype":
528539
nodeData.Datatype = value
529540
case "allowed":
530-
nodeData.Allowed[0] = value
541+
nodeData.Allowed = append(nodeData.Allowed, value)
531542
case "min":
532543
nodeData.Min = value
533544
case "max":

0 commit comments

Comments
 (0)