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

Method DecodeRootCompound

protocol/nbt/decoder.go:83–120  ·  view source on GitHub ↗
(v any)

Source from the content-addressed store, hash-verified

81}
82
83func (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
123func (d *Decoder) Decode(v any) (rootName string, err error) {

Callers

nothing calls this directly

Calls 6

readStringMethod · 0.95
decodeCompoundStructMethod · 0.95
decodeCompoundMapMethod · 0.95
generateMapFunction · 0.85
SetMethod · 0.45
TypeMethod · 0.45

Tested by

no test coverage detected