MCPcopy
hub / github.com/bnb-chain/bsc / rtypeToStructType

Function rtypeToStructType

rlp/typecache.go:188–212  ·  view source on GitHub ↗

rtypeToStructType converts typ to rlpstruct.Type.

(typ reflect.Type, rec map[reflect.Type]*rlpstruct.Type)

Source from the content-addressed store, hash-verified

186
187// rtypeToStructType converts typ to rlpstruct.Type.
188func 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'.
215func typeNilKind(typ reflect.Type, tags rlpstruct.Tags) Kind {

Callers 2

structFieldsFunction · 0.85
typeNilKindFunction · 0.85

Calls 2

KindMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected