(dst any)
| 113 | } |
| 114 | |
| 115 | func (d *Decoder) Decode(dst any) (rootName string, err error) { |
| 116 | id := unsafe2.InterfaceData(dst) |
| 117 | typ := (*unsafe2.Type)(unsafe.Pointer(id.Type)) |
| 118 | |
| 119 | if kindOf(typ) != pointer_k { |
| 120 | return rootName, ErrExpectPointer |
| 121 | } |
| 122 | |
| 123 | typ, v := ptrelem(typ, id.Value) |
| 124 | |
| 125 | rootTagS, err := d.rd.readBytesString(1) |
| 126 | if err != nil { |
| 127 | return rootName, err |
| 128 | } |
| 129 | |
| 130 | if !d.networkNBT { |
| 131 | if err := d.readString(&rootName); err != nil { |
| 132 | return rootName, err |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | switch rootTagS { |
| 137 | case string_t_b: |
| 138 | if k := kindOf(typ); k != string_k { |
| 139 | return rootName, MismatchError{ |
| 140 | expectedKind: "string", |
| 141 | gotKind: kind_name(k), |
| 142 | tag: tagName(rootTagS), |
| 143 | name: "root", |
| 144 | } |
| 145 | } |
| 146 | case compound_t_b: |
| 147 | switch k := kindOf(typ); k { |
| 148 | case struct_k: |
| 149 | typ := (*structType)(unsafe.Pointer(typ)) |
| 150 | s := newStruct(typ, v) |
| 151 | defer structs.Put(s) |
| 152 | |
| 153 | if err := d.decodeStructCompound(s); err != nil { |
| 154 | return rootName, err |
| 155 | } |
| 156 | default: |
| 157 | return rootName, MismatchError{ |
| 158 | expectedKind: "struct", |
| 159 | gotKind: kind_name(k), |
| 160 | tag: tagName(rootTagS), |
| 161 | name: "root", |
| 162 | } |
| 163 | } |
| 164 | default: |
| 165 | return rootName, ErrUnsupported |
| 166 | } |
| 167 | |
| 168 | return rootName, nil |
| 169 | } |
| 170 | |
| 171 | func (d *Decoder) discardCompound() error { |
| 172 | for { |
no test coverage detected