MCPcopy Index your code
hub / github.com/ZeppelinMC/Zeppelin / Encode

Method Encode

protocol/nbt/encoder.go:22–40  ·  view source on GitHub ↗
(name string, v any)

Source from the content-addressed store, hash-verified

20}
21
22func (e *Encoder) Encode(name string, v any) error {
23 if err := e.writeByte(Compound); err != nil {
24 return err
25 }
26 if !e.dontWriteRootCompoundName {
27 if err := e.writeString(name); err != nil {
28 return err
29 }
30 }
31 val := reflect.ValueOf(v)
32 switch val.Kind() {
33 case reflect.Struct:
34 return e.encodeCompoundStruct(val)
35 case reflect.Map:
36 return e.encodeCompoundMap(val)
37 default:
38 return fmt.Errorf("Encode expects map/struct, not %s", val.Type())
39 }
40}
41
42func (e *Encoder) WriteRootName(val bool) {
43 e.dontWriteRootCompoundName = !val

Callers 1

NBTMethod · 0.95

Calls 5

writeByteMethod · 0.95
writeStringMethod · 0.95
encodeCompoundStructMethod · 0.95
encodeCompoundMapMethod · 0.95
TypeMethod · 0.45

Tested by

no test coverage detected