Created
July 8, 2018 12:27
-
-
Save CapacitorSet/3b6a2bbcd6935b7c9f9d99d79afa7655 to your computer and use it in GitHub Desktop.
Parse OIDs in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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