go-ethereum/rlp
Felix Lange ac85a6f254
rlp: add back Iterator.Count, with fixes (#33841)
I removed `Iterator.Count` in #33840, because it appeared to be unused
and did not provide the documented invariant: the returned count should
always be an upper bound on the number of iterations allowed by `Next`.

In order to make `Count` work, the semantics of `CountValues` has to
change to return the number of items up and including the invalid one. I
have reviewed all callsites of `CountValues` to assess if changing this
is safe. There aren't that many, and the only call that doesn't check
the error and return is in the trie node parser,
`trie.decodeNodeUnsafe`. There, we distinguish the node type based on
the number of items, and it previously returned an error for item count
zero. In order to avoid any potential issue that could result from this
change, I'm adding an error check in that function, though it isn't
necessary.
2026-02-13 23:53:42 +01:00
..
internal/rlpstruct all: fix docstrings 2022-10-04 09:18:02 +02:00
rlpgen rlp/rlpgen: implement package renaming support (#31148) 2025-08-01 18:30:48 +02:00
decode.go rlp: remove workaround for Value.Bytes (#32433) 2025-08-15 14:08:27 +02:00
decode_tail_test.go all: update license information 2016-04-15 09:48:05 +02:00
decode_test.go rlp: fix typo in decode test message (#32554) 2025-09-09 09:56:53 +08:00
doc.go build: upgrade to go 1.19 (#25726) 2022-09-10 13:25:40 +02:00
encbuffer.go rlp: refactor to use maths.ReadBits (#32432) 2025-08-21 09:37:08 +08:00
encbuffer_example_test.go rlp/rlpgen: RLP encoder code generator (#24251) 2022-02-16 18:14:12 +01:00
encode.go rlp: validate and cache element count in RawList (#33840) 2026-02-13 21:52:47 +01:00
encode_test.go rlp: remove duplicate optionalAndTailField test case (#32614) 2025-09-15 16:16:06 +02:00
encoder_example_test.go rlp/rlpgen: RLP encoder code generator (#24251) 2022-02-16 18:14:12 +01:00
iterator.go rlp: add back Iterator.Count, with fixes (#33841) 2026-02-13 23:53:42 +01:00
iterator_test.go rlp: add back Iterator.Count, with fixes (#33841) 2026-02-13 23:53:42 +01:00
raw.go rlp: add back Iterator.Count, with fixes (#33841) 2026-02-13 23:53:42 +01:00
raw_test.go rlp: add back Iterator.Count, with fixes (#33841) 2026-02-13 23:53:42 +01:00
typecache.go rlp: using maps.Clone (#29434) 2024-04-02 10:47:15 +02:00