Skip to content

Instantly share code, notes, and snippets.

@CapacitorSet
Created July 8, 2018 12:27
Show Gist options
  • Save CapacitorSet/3b6a2bbcd6935b7c9f9d99d79afa7655 to your computer and use it in GitHub Desktop.
Save CapacitorSet/3b6a2bbcd6935b7c9f9d99d79afa7655 to your computer and use it in GitHub Desktop.
Parse OIDs in Go
// https://www.snmpsharpnet.com/?p=153
oid := []uint32{
uint32(oidBytes[0]) / 40,
uint32(oidBytes[0]) % 40,
}
for i := 1; i < len(oidBytes); {
bbyte := oidBytes[i]
// Short form
if bbyte & 0x80 == 0 {
oid = append(oid, uint32(bbyte))
i++
continue
}
done := false
tmp := uint32(0)
for !done {
tmp <<= 7
bbyte = oidBytes[i]
done = bbyte & 0x80 == 0
bbyte &= 0x7F
tmp += uint32(bbyte)
i++
}
oid = append(oid, uint32(tmp))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment