|
|
@ -113,6 +113,7 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e |
|
|
|
// Read TypeByte prefix
|
|
|
|
if typeInfo.HasTypeByte { |
|
|
|
typeByte := ReadByte(r, n, err) |
|
|
|
log.Debug("Read TypeByte: %X", typeByte) |
|
|
|
if typeByte != typeInfo.TypeByte { |
|
|
|
*err = errors.New(fmt.Sprintf("Expected TypeByte of %X but got %X", typeInfo.TypeByte, typeByte)) |
|
|
|
return |
|
|
@ -125,10 +126,12 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e |
|
|
|
if elemRt.Kind() == reflect.Uint8 { |
|
|
|
// Special case: Byteslices
|
|
|
|
byteslice := ReadByteSlice(r, n, err) |
|
|
|
log.Debug("Read byteslice: %X", byteslice) |
|
|
|
rv.Set(reflect.ValueOf(byteslice)) |
|
|
|
} else { |
|
|
|
// Read length
|
|
|
|
length := int(ReadUvarint(r, n, err)) |
|
|
|
log.Debug("Read length: %v", length) |
|
|
|
sliceRv := reflect.MakeSlice(rt, length, length) |
|
|
|
// Read elems
|
|
|
|
for i := 0; i < length; i++ { |
|
|
@ -151,46 +154,57 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e |
|
|
|
|
|
|
|
case reflect.String: |
|
|
|
str := ReadString(r, n, err) |
|
|
|
log.Debug("Read string: %v", str) |
|
|
|
rv.SetString(str) |
|
|
|
|
|
|
|
case reflect.Int64: |
|
|
|
num := ReadUint64(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetInt(int64(num)) |
|
|
|
|
|
|
|
case reflect.Int32: |
|
|
|
num := ReadUint32(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetInt(int64(num)) |
|
|
|
|
|
|
|
case reflect.Int16: |
|
|
|
num := ReadUint16(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetInt(int64(num)) |
|
|
|
|
|
|
|
case reflect.Int8: |
|
|
|
num := ReadUint8(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetInt(int64(num)) |
|
|
|
|
|
|
|
case reflect.Int: |
|
|
|
num := ReadUvarint(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetInt(int64(num)) |
|
|
|
|
|
|
|
case reflect.Uint64: |
|
|
|
num := ReadUint64(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetUint(uint64(num)) |
|
|
|
|
|
|
|
case reflect.Uint32: |
|
|
|
num := ReadUint32(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetUint(uint64(num)) |
|
|
|
|
|
|
|
case reflect.Uint16: |
|
|
|
num := ReadUint16(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetUint(uint64(num)) |
|
|
|
|
|
|
|
case reflect.Uint8: |
|
|
|
num := ReadUint8(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetUint(uint64(num)) |
|
|
|
|
|
|
|
case reflect.Uint: |
|
|
|
num := ReadUvarint(r, n, err) |
|
|
|
log.Debug("Read num: %v", num) |
|
|
|
rv.SetUint(uint64(num)) |
|
|
|
|
|
|
|
default: |
|
|
|