本文整理汇总了Golang中github.com/runner-mei/snmpclient2.Variable.Uint方法的典型用法代码示例。如果您正苦于以下问题:Golang Variable.Uint方法的具体用法?Golang Variable.Uint怎么用?Golang Variable.Uint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runner-mei/snmpclient2.Variable
的用法示例。
在下文中一共展示了Variable.Uint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exceptedError2
func exceptedError2(t *testing.T, v snmpclient2.Variable) {
defer func() {
if o := recover(); nil == o {
t.Errorf("Failed to call BigInt()")
}
}()
v.Uint()
}
示例2: TestCounter64
func TestCounter64(t *testing.T) {
expInt := uint64(18446744073709551615)
expStr := "18446744073709551615"
expBuf := []byte{0x46, 0x09, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
var v snmpclient2.Variable = snmpclient2.NewCounter64(expInt)
if expInt != v.Uint() {
t.Errorf("BigInt() - expected [%d], actual [%d]", expInt, v.Uint())
}
if expStr != v.ToString() {
t.Errorf("ToString() - expected [%s], actual [%s]", expStr, v.ToString())
}
buf, err := v.Marshal()
if err != nil {
t.Errorf("Marshal(): %v", err)
}
if !bytes.Equal(expBuf, buf) {
t.Errorf("Marshal() - expected [%s], actual [%s]",
snmpclient2.ToHexStr(expBuf, " "), snmpclient2.ToHexStr(buf, " "))
}
var w snmpclient2.Counter64
rest, err := (&w).Unmarshal(buf)
if len(rest) != 0 || err != nil {
t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
}
if expStr != w.ToString() {
t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.ToString())
}
buf = append(buf, 0x00)
rest, err = (&w).Unmarshal(buf)
if len(rest) != 1 || err != nil {
t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
}
if expStr != w.ToString() {
t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.ToString())
}
}
示例3: TestGauge32
func TestGauge32(t *testing.T) {
expInt := uint64(4294967295)
expStr := "4294967295"
expBuf := []byte{0x42, 0x05, 0x00, 0xff, 0xff, 0xff, 0xff}
var v snmpclient2.Variable = snmpclient2.NewGauge32(uint32(expInt))
if expInt != v.Uint() {
t.Errorf("BigInt() - expected [%d], actual [%d]", expInt, v.Uint())
}
if expStr != v.ToString() {
t.Errorf("ToString() - expected [%s], actual [%s]", expStr, v.ToString())
}
buf, err := v.Marshal()
if err != nil {
t.Errorf("Marshal(): %v", err)
}
if !bytes.Equal(expBuf, buf) {
t.Errorf("Marshal() - expected [%s], actual [%s]",
snmpclient2.ToHexStr(expBuf, " "), snmpclient2.ToHexStr(buf, " "))
}
var w snmpclient2.Gauge32
rest, err := (&w).Unmarshal(buf)
if len(rest) != 0 || err != nil {
t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
}
if expStr != w.ToString() {
t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.ToString())
}
buf = append(buf, 0x00)
rest, err = (&w).Unmarshal(buf)
if len(rest) != 1 || err != nil {
t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
}
if expStr != w.ToString() {
t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.ToString())
}
}