aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-06-27 09:45:50 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 00:51:47 +0800
commita0566c10585cd19b12b40127597e310f4b7bfa67 (patch)
tree02c1a1befcbe6b5c1696901fa09201c6bc19fcf9
parent3d0c6a8345b28b33eb0dfc4a53b967461977706a (diff)
downloadgo-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar.gz
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar.bz2
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar.lz
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar.xz
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.tar.zst
go-tangerine-a0566c10585cd19b12b40127597e310f4b7bfa67.zip
rlp: remove Flat
-rw-r--r--rlp/encode.go42
-rw-r--r--rlp/encode_test.go9
2 files changed, 0 insertions, 51 deletions
diff --git a/rlp/encode.go b/rlp/encode.go
index dddde766f..a9f80d448 100644
--- a/rlp/encode.go
+++ b/rlp/encode.go
@@ -29,48 +29,6 @@ type Encoder interface {
EncodeRLP(io.Writer) error
}
-// Flat wraps a value (which must encode as a list) so
-// it encodes as the list's elements.
-//
-// Example: suppose you have defined a type
-//
-// type foo struct { A, B uint }
-//
-// Under normal encoding rules,
-//
-// rlp.Encode(foo{1, 2}) --> 0xC20102
-//
-// This function can help you achieve the following encoding:
-//
-// rlp.Encode(rlp.Flat(foo{1, 2})) --> 0x0102
-func Flat(val interface{}) Encoder {
- return flatenc{val}
-}
-
-type flatenc struct{ val interface{} }
-
-func (e flatenc) EncodeRLP(out io.Writer) error {
- // record current output position
- var (
- eb = out.(*encbuf)
- prevstrsize = len(eb.str)
- prevnheads = len(eb.lheads)
- )
- if err := eb.encode(e.val); err != nil {
- return err
- }
- // check that a new list header has appeared
- if len(eb.lheads) == prevnheads || eb.lheads[prevnheads].offset == prevstrsize-1 {
- return fmt.Errorf("rlp.Flat: %T did not encode as list", e.val)
- }
- // remove the new list header
- newhead := eb.lheads[prevnheads]
- copy(eb.lheads[prevnheads:], eb.lheads[prevnheads+1:])
- eb.lheads = eb.lheads[:len(eb.lheads)-1]
- eb.lhsize -= headsize(uint64(newhead.size))
- return nil
-}
-
// Encode writes the RLP encoding of val to w. Note that Encode may
// perform many small writes in some cases. Consider making w
// buffered.
diff --git a/rlp/encode_test.go b/rlp/encode_test.go
index 6eb930d6c..7b70a0629 100644
--- a/rlp/encode_test.go
+++ b/rlp/encode_test.go
@@ -189,15 +189,6 @@ var encTests = []encTest{
{val: &recstruct{5, nil}, output: "C205C0"},
{val: &recstruct{5, &recstruct{4, &recstruct{3, nil}}}, output: "C605C404C203C0"},
- // flat
- {val: Flat(uint(1)), error: "rlp.Flat: uint did not encode as list"},
- {val: Flat(simplestruct{A: 3, B: "foo"}), output: "0383666F6F"},
- {
- // value generates more list headers after the Flat
- val: []interface{}{"foo", []uint{1, 2}, Flat([]uint{3, 4}), []uint{5, 6}, "bar"},
- output: "D083666F6FC201020304C2050683626172",
- },
-
// nil
{val: (*uint)(nil), output: "80"},
{val: (*string)(nil), output: "80"},