Skip to content

Commit

Permalink
Merge pull request #63 from UlfBj/datacomp
Browse files Browse the repository at this point in the history
default property in metadata response
  • Loading branch information
UlfBj authored Dec 19, 2024
2 parents 02ae8e1 + b617564 commit 6d06eac
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions server/vissv2server/vissv2server.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,17 @@ func jsonifyTreeNode(nodeHandle *utils.Node_t, jsonBuffer string, depth int, max
nodeName := utils.VSSgetName(nodeHandle)
newJsonBuffer += `"` + nodeName + `":{`
nodeType := int(utils.VSSgetType(nodeHandle))
// utils.Info.Printf("nodeType=%d", nodeType)
newJsonBuffer += `"type":` + `"` + nodeTypesToString(nodeType) + `",`
newJsonBuffer += `"type":"` + nodeTypesToString(nodeType) + `",`
nodeDefault := utils.VSSgetDefault(nodeHandle)
if len(nodeDefault) > 0 {
if nodeDefault[0] == '{' || nodeDefault[0] == '[' {
newJsonBuffer += `"default":` + singleToDoubleQuote(nodeDefault) + `,`
} else {
newJsonBuffer += `"default":"`+ nodeDefault + `",`
}
}
nodeDescr := utils.VSSgetDescr(nodeHandle)
newJsonBuffer += `"description":` + `"` + nodeDescr + `",`
newJsonBuffer += `"description":"` + nodeDescr + `",`
nodeNumofChildren := utils.VSSgetNumOfChildren(nodeHandle)
switch nodeType {
case 4: // branch
Expand All @@ -290,14 +297,14 @@ func jsonifyTreeNode(nodeHandle *utils.Node_t, jsonBuffer string, depth int, max
case 3: // attribute
// TODO Look for other metadata, unit, enum, ...
nodeDatatype := utils.VSSgetDatatype(nodeHandle)
newJsonBuffer += `"datatype":` + `"` + nodeDatatype + `",`
newJsonBuffer += `"datatype":"` + nodeDatatype + `",`
default:
return ""

}
if depth < maxDepth {
if nodeNumofChildren > 0 {
newJsonBuffer += `"children":` + "{"
newJsonBuffer += `"children":{`
}
for i := 0; i < nodeNumofChildren; i++ {
childNode := utils.VSSgetChild(nodeHandle, i)
Expand All @@ -315,6 +322,15 @@ func jsonifyTreeNode(nodeHandle *utils.Node_t, jsonBuffer string, depth int, max
return jsonBuffer + newJsonBuffer
}

func singleToDoubleQuote(jsonObject string) string {
for i := 0; i < len(jsonObject); i++ {
if jsonObject[i] == '\'' {
jsonObject = jsonObject[:i] + `"` + jsonObject[i+1:]
}
}
return jsonObject
}

func countPathSegments(path string) int {
return strings.Count(path, ".") + 1
}
Expand Down

0 comments on commit 6d06eac

Please sign in to comment.