-
Notifications
You must be signed in to change notification settings - Fork 37
/
render.go
48 lines (44 loc) · 1.08 KB
/
render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package smi
import (
"strconv"
"strings"
"github.com/sleepinggenius2/gosmi/smi/internal"
"github.com/sleepinggenius2/gosmi/types"
)
func RenderNode(smiNodePtr *types.SmiNode, flags types.Render) string {
if smiNodePtr == nil {
if flags&types.RenderUnknown > 0 {
return internal.UnknownLabel
}
return ""
}
modulePtr := GetNodeModule(smiNodePtr)
if flags&types.RenderQualified == 0 || modulePtr == nil || modulePtr.Name == "" {
return smiNodePtr.Name.String()
}
return modulePtr.Name.String() + "::" + smiNodePtr.Name.String()
}
func RenderOID(oid types.Oid, flags types.Render) string {
if len(oid) == 0 {
if flags&types.RenderUnknown > 0 {
return internal.UnknownLabel
}
return ""
}
var i int
var b strings.Builder
if flags&(types.RenderName|types.RenderQualified) > 0 {
nodePtr := GetNodeByOID(oid)
if nodePtr != nil && nodePtr.Name != "" {
i = nodePtr.OidLen
b.WriteString(RenderNode(nodePtr, flags))
}
}
for ; i < len(oid); i++ {
if b.Len() > 0 {
b.WriteRune('.')
}
b.WriteString(strconv.FormatUint(uint64(oid[i]), 10))
}
return b.String()
}