本文整理汇总了Golang中github.com/shiftcurrency/shift/rlp.Stream.List方法的典型用法代码示例。如果您正苦于以下问题:Golang Stream.List方法的具体用法?Golang Stream.List怎么用?Golang Stream.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shiftcurrency/shift/rlp.Stream
的用法示例。
在下文中一共展示了Stream.List方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkDecodeFromJSON
// checkDecodeFromJSON decodes from s guided by exp. exp drives the
// Stream by invoking decoding operations (Uint, Big, List, ...) based
// on the type of each value. The value decoded from the RLP stream
// must match the JSON value.
func checkDecodeFromJSON(s *rlp.Stream, exp interface{}) error {
switch exp := exp.(type) {
case uint64:
i, err := s.Uint()
if err != nil {
return addStack("Uint", exp, err)
}
if i != exp {
return addStack("Uint", exp, fmt.Errorf("result mismatch: got %d", i))
}
case *big.Int:
big := new(big.Int)
if err := s.Decode(&big); err != nil {
return addStack("Big", exp, err)
}
if big.Cmp(exp) != 0 {
return addStack("Big", exp, fmt.Errorf("result mismatch: got %d", big))
}
case []byte:
b, err := s.Bytes()
if err != nil {
return addStack("Bytes", exp, err)
}
if !bytes.Equal(b, exp) {
return addStack("Bytes", exp, fmt.Errorf("result mismatch: got %x", b))
}
case []interface{}:
if _, err := s.List(); err != nil {
return addStack("List", exp, err)
}
for i, v := range exp {
if err := checkDecodeFromJSON(s, v); err != nil {
return addStack(fmt.Sprintf("[%d]", i), exp, err)
}
}
if err := s.ListEnd(); err != nil {
return addStack("ListEnd", exp, err)
}
default:
panic(fmt.Errorf("unhandled type: %T", exp))
}
return nil
}
示例2: dump
func dump(s *rlp.Stream, depth int) error {
kind, size, err := s.Kind()
if err != nil {
return err
}
switch kind {
case rlp.Byte, rlp.String:
str, err := s.Bytes()
if err != nil {
return err
}
if len(str) == 0 || !*noASCII && isASCII(str) {
fmt.Printf("%s%q", ws(depth), str)
} else {
fmt.Printf("%s%x", ws(depth), str)
}
case rlp.List:
s.List()
defer s.ListEnd()
if size == 0 {
fmt.Print(ws(depth) + "[]")
} else {
fmt.Println(ws(depth) + "[")
for i := 0; ; i++ {
if i > 0 {
fmt.Print(",\n")
}
if err := dump(s, depth+1); err == rlp.EOL {
break
} else if err != nil {
return err
}
}
fmt.Print(ws(depth) + "]")
}
}
return nil
}