MCPcopy
hub / github.com/pelletier/go-toml / assignInlineTable

Method assignInlineTable

unmarshaler.go:2048–2086  ·  view source on GitHub ↗
(v reflect.Value, expr *unstable.Node, value *unstable.Node)

Source from the content-addressed store, hash-verified

2046}
2047
2048func (d *decoder) assignInlineTable(v reflect.Value, expr *unstable.Node, value *unstable.Node) (reflect.Value, error) {
2049 switch v.Kind() {
2050 case reflect.Map:
2051 // Inline tables are self-contained: they fully replace the target.
2052 v = reflect.MakeMap(v.Type())
2053 case reflect.Struct:
2054 // fields are set in place
2055 case reflect.Interface:
2056 elem := reflect.ValueOf(map[string]interface{}{})
2057 nv, err := d.assignInlineTable(elem, expr, value)
2058 if err != nil {
2059 return reflect.Value{}, err
2060 }
2061 return boxInto(v, nv)
2062 default:
2063 return reflect.Value{}, d.typeMismatchError("inline table", v.Type(), d.rawValue(expr, value))
2064 }
2065
2066 it := value.Children()
2067 for it.Next() {
2068 kv := it.Node()
2069 // Build the path from the key of this key-value. Keys of inline
2070 // tables rarely have more than a few parts.
2071 var pathBuf [4]pathPart
2072 path := pathBuf[:0]
2073 kit := kv.Key()
2074 for kit.Next() {
2075 path = append(path, pathPart{node: kit.Node()})
2076 }
2077 nv, err := d.descend(v, path, 0, kv, kv.Value())
2078 if err != nil {
2079 return reflect.Value{}, err
2080 }
2081 if nv.IsValid() {
2082 v = nv
2083 }
2084 }
2085 return v, nil
2086}
2087
2088// boxInto returns the value to store in place of the interface value v. The
2089// caller stores the result in the slot v was found in, which performs the

Callers 1

assignValueMethod · 0.95

Calls 9

typeMismatchErrorMethod · 0.95
rawValueMethod · 0.95
descendMethod · 0.95
boxIntoFunction · 0.85
ChildrenMethod · 0.80
NodeMethod · 0.80
ValueMethod · 0.80
NextMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected