MCPcopy
hub / github.com/TomWright/dasel / UnpackUntilType

Method UnpackUntilType

model/value.go:214–236  ·  view source on GitHub ↗

UnpackUntilType unpacks the reflect value until it matches the given type.

(t reflect.Type)

Source from the content-addressed store, hash-verified

212
213// UnpackUntilType unpacks the reflect value until it matches the given type.
214func (v *Value) UnpackUntilType(t reflect.Type) (*Value, error) {
215 res := v.value
216 var daselValueType = reflect.TypeFor[*Value]()
217 for {
218 if res.Type() == t {
219 return NewValue(res), nil
220 }
221 if t != daselValueType && res.Type() == daselValueType {
222 m, err := v.daselValue()
223 if err != nil {
224 return nil, fmt.Errorf("error getting dasel value: %w", err)
225 }
226 res = m.value
227 continue
228
229 }
230 if res.Kind() == reflect.Interface || res.Kind() == reflect.Pointer && !res.IsNil() {
231 res = res.Elem()
232 continue
233 }
234 return nil, &ErrCouldNotUnpackToType{Type: t}
235 }
236}
237
238// UnpackUntilAddressable unpacks the reflect value until it is addressable.
239func (v *Value) UnpackUntilAddressable() (*Value, error) {

Callers 2

daselValueMethod · 0.95
dencodingMapValueMethod · 0.95

Calls 4

daselValueMethod · 0.95
NewValueFunction · 0.85
TypeMethod · 0.80
KindMethod · 0.80

Tested by

no test coverage detected