rtypeToStructType converts typ to rlpstruct.Type.
(typ reflect.Type, rec map[reflect.Type]*rlpstruct.Type)
| 186 | |
| 187 | // rtypeToStructType converts typ to rlpstruct.Type. |
| 188 | func rtypeToStructType(typ reflect.Type, rec map[reflect.Type]*rlpstruct.Type) *rlpstruct.Type { |
| 189 | k := typ.Kind() |
| 190 | if k == reflect.Invalid { |
| 191 | panic("invalid kind") |
| 192 | } |
| 193 | |
| 194 | if prev := rec[typ]; prev != nil { |
| 195 | return prev // short-circuit for recursive types |
| 196 | } |
| 197 | if rec == nil { |
| 198 | rec = make(map[reflect.Type]*rlpstruct.Type) |
| 199 | } |
| 200 | |
| 201 | t := &rlpstruct.Type{ |
| 202 | Name: typ.String(), |
| 203 | Kind: k, |
| 204 | IsEncoder: typ.Implements(encoderInterface), |
| 205 | IsDecoder: typ.Implements(decoderInterface), |
| 206 | } |
| 207 | rec[typ] = t |
| 208 | if k == reflect.Array || k == reflect.Slice || k == reflect.Ptr { |
| 209 | t.Elem = rtypeToStructType(typ.Elem(), rec) |
| 210 | } |
| 211 | return t |
| 212 | } |
| 213 | |
| 214 | // typeNilKind gives the RLP value kind for nil pointers to 'typ'. |
| 215 | func typeNilKind(typ reflect.Type, tags rlpstruct.Tags) Kind { |
no test coverage detected