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

Method decodeCompoundStruct

protocol/nbt/decoder.go:436–736  ·  view source on GitHub ↗
(_struct map[string]reflect.Value)

Source from the content-addressed store, hash-verified

434}
435
436func (d *Decoder) decodeCompoundStruct(_struct map[string]reflect.Value) error {
437 var typeId [1]byte
438 for {
439 err := d.readTo(typeId[:])
440 if err != nil {
441 return err
442 }
443 if typeId[0] == End {
444 return nil
445 }
446
447 name, err := d.readString()
448 if err != nil {
449 return err
450 }
451
452 var z, valid = _struct[name]
453
454 switch typeId[0] {
455 case Byte:
456 d, err := d.readByte()
457 if err != nil {
458 return err
459 }
460 if valid {
461 switch z.Kind() {
462 case reflect.Uint8:
463 z.SetUint(uint64(d))
464 case reflect.Int8:
465 z.SetInt(int64(d))
466 case reflect.Bool:
467 z.SetBool(*(*bool)(unsafe.Pointer(&d)))
468 default:
469 if reflect.TypeOf(d).AssignableTo(z.Type()) {
470 z.Set(reflect.ValueOf(d))
471 } else {
472 if reflect.TypeOf(d).ConvertibleTo(z.Type()) {
473 z.Set(reflect.ValueOf(d).Convert(z.Type()))
474 } else {
475 return fmt.Errorf("cannot assign byte to type %s for field %s", z.Type(), name)
476 }
477 }
478 }
479 }
480 case Short:
481 d, err := d.readShort()
482 if err != nil {
483 return err
484 }
485
486 if valid {
487 switch z.Kind() {
488 case reflect.Uint16:
489 z.SetUint(uint64(d))
490 case reflect.Int16:
491 z.SetInt(int64(d))
492 default:
493 if reflect.TypeOf(d).AssignableTo(z.Type()) {

Callers 4

DecodeRootCompoundMethod · 0.95
DecodeMethod · 0.95
decodeCompoundMapMethod · 0.95
decodeListMethod · 0.95

Calls 15

readToMethod · 0.95
readStringMethod · 0.95
readByteMethod · 0.95
readShortMethod · 0.95
readIntMethod · 0.95
readLongMethod · 0.95
readFloatMethod · 0.95
readDoubleMethod · 0.95
readByteArrayMethod · 0.95
readIntArrayMethod · 0.95
readLongArrayMethod · 0.95
decodeListMethod · 0.95

Tested by

no test coverage detected