aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-07 18:52:46 +0800
committerGitHub <noreply@github.com>2019-01-07 18:52:46 +0800
commitf37990348a6227e65d3aade41686a5834b064044 (patch)
treee1e6d746649492f4ac15123b9f63e872c9c671d1 /docs
parent016f77f4c3081a473e6cf0f2d8c3477f34540ad7 (diff)
parentac6f80b4e973d793097d49e295a7d4b6d88a8851 (diff)
downloaddexon-solidity-f37990348a6227e65d3aade41686a5834b064044.tar.gz
dexon-solidity-f37990348a6227e65d3aade41686a5834b064044.tar.zst
dexon-solidity-f37990348a6227e65d3aade41686a5834b064044.zip
Merge pull request #5698 from ethereum/chriseth-patch-2
[DOC] More details about packed encoding.
Diffstat (limited to 'docs')
-rw-r--r--docs/abi-spec.rst20
1 files changed, 14 insertions, 6 deletions
diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst
index 0f4a16b6..3c9dfcf9 100644
--- a/docs/abi-spec.rst
+++ b/docs/abi-spec.rst
@@ -609,7 +609,9 @@ Through ``abi.encodePacked()``, Solidity supports a non-standard packed mode whe
- types shorter than 32 bytes are neither zero padded nor sign extended and
- dynamic types are encoded in-place and without the length.
-As an example encoding ``int8, bytes1, uint16, string`` with values ``-1, 0x42, 0x2424, "Hello, world!"`` results in:
+This packed mode is mainly used for indexed event parameters.
+
+As an example, the encoding of ``int8(-1), bytes1(0x42), uint16(0x2424), string("Hello, world!")`` results in:
.. code-block:: none
@@ -619,12 +621,18 @@ As an example encoding ``int8, bytes1, uint16, string`` with values ``-1, 0x42,
^^^^ uint16(0x2424)
^^^^^^^^^^^^^^^^^^^^^^^^^^ string("Hello, world!") without a length field
-More specifically, each statically-sized type takes as many bytes as its range has
-and dynamically-sized types like ``string``, ``bytes`` or ``uint[]`` are encoded without
-their length field. This means that the encoding is ambiguous as soon as there are two
-dynamically-sized elements.
+More specifically:
+ - Each value type takes as many bytes as its range has.
+ - The encoding of a struct or fixed-size array is the concatenation of the
+ encoding of its members/elements without any separator or padding.
+ - Mapping members of structs are ignored as usual.
+ - Dynamically-sized types like ``string``, ``bytes`` or ``uint[]`` are encoded without
+ their length field.
+
+In general, the encoding is ambiguous as soon as there are two dynamically-sized elements,
+because of the missing length field.
If padding is needed, explicit type conversions can be used: ``abi.encodePacked(uint16(0x12)) == hex"0012"``.
Since packed encoding is not used when calling functions, there is no special support
-for prepending a function selector.
+for prepending a function selector. Since the encoding is ambiguous, there is no decoding function.