(v any)
| 81 | } |
| 82 | |
| 83 | func (d *Decoder) DecodeRootCompound(v any) (rootName string, err error) { |
| 84 | val := reflect.ValueOf(v) |
| 85 | if val.Kind() != reflect.Pointer { |
| 86 | return "", fmt.Errorf("Decode expects a pointer") |
| 87 | } |
| 88 | val = val.Elem() |
| 89 | |
| 90 | if !d.dontReadRootCompoundName { |
| 91 | rootName, err = d.readString() |
| 92 | if err != nil { |
| 93 | return |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | switch val.Kind() { |
| 98 | case reflect.Struct: |
| 99 | m := generateMap(val) |
| 100 | defer func() { |
| 101 | clear(m) |
| 102 | valueMap.Put(m) |
| 103 | }() |
| 104 | |
| 105 | if err := d.decodeCompoundStruct(m); err != nil { |
| 106 | return "", err |
| 107 | } |
| 108 | case reflect.Map: |
| 109 | if val.IsNil() { |
| 110 | val.Set(reflect.MakeMap(val.Type())) |
| 111 | } |
| 112 | if err := d.decodeCompoundMap(val); err != nil { |
| 113 | return rootName, err |
| 114 | } |
| 115 | default: |
| 116 | return rootName, fmt.Errorf("Decode expects a pointer of struct/map, not %s", val.Type()) |
| 117 | } |
| 118 | |
| 119 | return |
| 120 | } |
| 121 | |
| 122 | // Decode will decode the nbt file into v and return the root name of the file |
| 123 | func (d *Decoder) Decode(v any) (rootName string, err error) { |
nothing calls this directly
no test coverage detected