@@ -102,56 +102,60 @@ Signed integers, floating point numbers, maps, channels and functions cannot be
102102
103103Struct Tags
104104
105- As with encoding/json , the "-" tag ignores fields.
105+ As with other encoding packages , the "-" tag ignores fields.
106106
107107 type StructWithIgnoredField struct{
108108 Ignored uint `rlp:"-"`
109109 Field uint
110110 }
111111
112- All other supported struct tags have the purpose of modifying the mapping between
113- RLP lists and Go struct fields.
114-
115- The "tail" tag, which may only be used on the last exported struct field, allows slurping
116- up any excess list elements into a slice.
112+ Go struct values encode/decode as RLP lists. There are two ways of influencing the mapping
113+ of fields to list elements. The "tail" tag, which may only be used on the last exported
114+ struct field, allows slurping up any excess list elements into a slice.
117115
118116 type StructWithTail struct{
119117 Field uint
120118 Tail []string `rlp:"tail"`
121119 }
122120
123121The "optional" tag says that the field may be omitted if it is zero-valued. If this tag is
124- used on a struct field, all subsequent public fields must also be declared optional. When
125- decoding an RLP list into a struct, optional fields may be omitted from the input list.
122+ used on a struct field, all subsequent public fields must also be declared optional.
123+
126124When encoding a struct with optional fields, the output RLP list contains all values up to
127125the last non-zero optional field.
128126
127+ When decoding into a struct, optional fields may be omitted from the end of the input
128+ list. For the example below, this means input lists of one, two, or three elements are
129+ accepted.
130+
129131 type StructWithOptionalFields struct{
130132 Required uint
131133 Optional1 uint `rlp:"optional"`
132134 Optional2 uint `rlp:"optional"`
133135 }
134136
135- The "nil" tag applies to pointer-typed fields and changes the decoding rules for the field
136- such that input values of size zero decode as a nil pointer. This tag can be useful when
137- decoding recursive types.
137+ The "nil", "nilList" and "nilString" tags apply to pointer-typed fields only, and change
138+ the decoding rules for the field type. For regular pointer fields without the "nil" tag,
139+ input values must always match the required input length exactly and the decoder does not
140+ produce nil values. When the "nil" tag is set, input values of size zero decode as a nil
141+ pointer. This is especially useful for recursive types.
138142
139143 type StructWithNilField struct {
140144 Field *[3]byte `rlp:"nil"`
141145 }
142146
143- In the example above, the field allows two possible input sizes. For input 0xC180 (list
147+ In the example above, Field allows two possible input sizes. For input 0xC180 (a list
144148containing an empty string) Field is set to nil after decoding. For input 0xC483000000 (a
145149list containing a 3-byte string), Field is set to a non-nil array pointer.
146150
147151RLP supports two kinds of empty values: empty lists and empty strings. When using the
148- "nil" tag, the kind of empty value allowed for a type is chosen automatically. A struct
149- field whose Go type is a pointer to an unsigned integer, string, boolean or byte
150- array/slice expects an empty RLP string. Any other pointer field type encodes/decodes as
151- an empty RLP list.
152+ "nil" tag, the kind of empty value allowed for a type is chosen automatically. A field
153+ whose Go type is a pointer to an unsigned integer, string, boolean or byte array/slice
154+ expects an empty RLP string. Any other pointer field type encodes/decodes as an empty RLP
155+ list.
152156
153157The choice of null value can be made explicit with the "nilList" and "nilString" struct
154- tags. Using these tags encodes/decodes a Go nil pointer value as the kind of empty
155- RLP value defined by the tag.
158+ tags. Using these tags encodes/decodes a Go nil pointer value as the empty RLP value kind
159+ defined by the tag.
156160*/
157161package rlp
0 commit comments