MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / Decode

Method Decode

protocol/nbt/qnbt/decode.go:115–169  ·  view source on GitHub ↗
(dst any)

Source from the content-addressed store, hash-verified

113}
114
115func (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
171func (d *Decoder) discardCompound() error {
172 for {

Callers 1

DecodeAndCloseMethod · 0.95

Calls 9

readStringMethod · 0.95
decodeStructCompoundMethod · 0.95
kindOfFunction · 0.85
ptrelemFunction · 0.85
kind_nameFunction · 0.85
tagNameFunction · 0.85
newStructFunction · 0.85
PointerMethod · 0.80
readBytesStringMethod · 0.80

Tested by

no test coverage detected