format repo with "gofumpt" tool
This commit is contained in:
@ -33,7 +33,7 @@ func (d *Decoder) Decode(v interface{}) (string, error) {
|
||||
if val.Kind() != reflect.Ptr {
|
||||
return "", errors.New("nbt: non-pointer passed to Decode")
|
||||
}
|
||||
//start read NBT
|
||||
// start read NBT
|
||||
tagType, tagName, err := d.readTag()
|
||||
if err != nil {
|
||||
return tagName, fmt.Errorf("nbt: %w", err)
|
||||
@ -246,7 +246,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vt := val.Type() //receiver must be []int or []int32
|
||||
vt := val.Type() // receiver must be []int or []int32
|
||||
if vt.Kind() == reflect.Interface {
|
||||
vt = reflect.TypeOf([]int32{}) // pass
|
||||
} else if vt.Kind() == reflect.Array && vt.Len() != int(aryLen) {
|
||||
@ -277,7 +277,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vt := val.Type() //receiver must be []int or []int64
|
||||
vt := val.Type() // receiver must be []int or []int64
|
||||
if vt.Kind() == reflect.Interface {
|
||||
vt = reflect.TypeOf([]int64{}) // pass
|
||||
} else if vt.Kind() != reflect.Slice {
|
||||
@ -591,7 +591,7 @@ func (d *Decoder) readTag() (tagType byte, tagName string, err error) {
|
||||
c := d.checkCompressed(tagType)
|
||||
err = fmt.Errorf("nbt: unknown Tag %#02x, which seems like %s header and you should uncompress it first", tagType, c)
|
||||
case TagEnd:
|
||||
default: //Read Tag
|
||||
default: // Read Tag
|
||||
tagName, err = d.readString()
|
||||
}
|
||||
return
|
||||
|
@ -11,12 +11,12 @@ import (
|
||||
)
|
||||
|
||||
func TestUnmarshal_string(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09,
|
||||
0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
}
|
||||
|
||||
//Unmarshal to string
|
||||
// Unmarshal to string
|
||||
var Name string
|
||||
if err := Unmarshal(data, &Name); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -26,7 +26,7 @@ func TestUnmarshal_string(t *testing.T) {
|
||||
t.Errorf("Unmarshal NBT fail: get %q, want %q", Name, "Bananrama")
|
||||
}
|
||||
|
||||
//Unmarshal to interface{}
|
||||
// Unmarshal to interface{}
|
||||
var infName interface{}
|
||||
if err := Unmarshal(data, &infName); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -38,7 +38,7 @@ func TestUnmarshal_string(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshal_simple(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x0a, 0x00, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x08, 0x00,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09, 0x42,
|
||||
@ -46,7 +46,7 @@ func TestUnmarshal_simple(t *testing.T) {
|
||||
0x00,
|
||||
}
|
||||
|
||||
//test parse
|
||||
// test parse
|
||||
var value struct {
|
||||
Name string `nbt:"name"`
|
||||
}
|
||||
@ -57,7 +57,7 @@ func TestUnmarshal_simple(t *testing.T) {
|
||||
t.Errorf("Unmarshal NBT fail: get %q, want %q", value.Name, "Bananrama")
|
||||
}
|
||||
|
||||
//test rawRead
|
||||
// test rawRead
|
||||
var empty struct{}
|
||||
if err := Unmarshal(data, &empty); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -184,7 +184,7 @@ func MakeBigTestStruct() BigTestStruct {
|
||||
}
|
||||
|
||||
func TestDecoder_Decode_bigTest(t *testing.T) {
|
||||
//test parse
|
||||
// test parse
|
||||
var value BigTestStruct
|
||||
r, err := gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
||||
if err != nil {
|
||||
@ -199,7 +199,7 @@ func TestDecoder_Decode_bigTest(t *testing.T) {
|
||||
t.Errorf("parse fail, expect %v, get %v", want, value)
|
||||
}
|
||||
|
||||
//test rawRead
|
||||
// test rawRead
|
||||
var empty struct{}
|
||||
r, err = gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
||||
if err != nil {
|
||||
@ -345,7 +345,7 @@ func TestDecoder_Decode_ByteArray(t *testing.T) {
|
||||
want = []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
|
||||
)
|
||||
|
||||
//Unmarshal to []byte
|
||||
// Unmarshal to []byte
|
||||
if err := Unmarshal(data, &value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -354,7 +354,7 @@ func TestDecoder_Decode_ByteArray(t *testing.T) {
|
||||
}
|
||||
// t.Log(value)
|
||||
|
||||
//Unmarshal to interface{}
|
||||
// Unmarshal to interface{}
|
||||
if err := Unmarshal(data, &infValue); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -377,7 +377,7 @@ func TestDecoder_Decode_bool(t *testing.T) {
|
||||
}
|
||||
var value bool
|
||||
for i, v := range data {
|
||||
//Unmarshal to []byte
|
||||
// Unmarshal to []byte
|
||||
if err := Unmarshal(v, &value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -388,12 +388,12 @@ func TestDecoder_Decode_bool(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDecoder_Decode_ErrorString(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0xFF, 0xFE,
|
||||
0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
}
|
||||
|
||||
//Unmarshal to string
|
||||
// Unmarshal to string
|
||||
var Name string
|
||||
err := Unmarshal(data, &Name)
|
||||
|
||||
@ -401,7 +401,6 @@ func TestDecoder_Decode_ErrorString(t *testing.T) {
|
||||
t.Error("should return a error if len < 0")
|
||||
}
|
||||
t.Log(err)
|
||||
|
||||
}
|
||||
|
||||
type TextBool bool
|
||||
@ -409,6 +408,7 @@ type TextBool bool
|
||||
func (b TextBool) MarshalText() (text []byte, err error) {
|
||||
return []byte(strconv.FormatBool(bool(b))), nil
|
||||
}
|
||||
|
||||
func (b *TextBool) UnmarshalText(text []byte) (err error) {
|
||||
*((*bool)(b)), err = strconv.ParseBool(string(text))
|
||||
return
|
||||
|
@ -390,7 +390,8 @@ func (e *Encoder) writeInt32(n int32) error {
|
||||
func (e *Encoder) writeInt64(n int64) error {
|
||||
_, err := e.w.Write([]byte{
|
||||
byte(n >> 56), byte(n >> 48), byte(n >> 40), byte(n >> 32),
|
||||
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
||||
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@ import (
|
||||
func TestEncoder_Encode_intArray(t *testing.T) {
|
||||
// Test marshal pure Int array
|
||||
v := []int32{0, -10, 3}
|
||||
out := []byte{TagIntArray, 0x00, 0x00, 0, 0, 0, 3,
|
||||
out := []byte{
|
||||
TagIntArray, 0x00, 0x00, 0, 0, 0, 3,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xf6,
|
||||
0x00, 0x00, 0x00, 0x03,
|
||||
@ -27,7 +28,8 @@ func TestEncoder_Encode_intArray(t *testing.T) {
|
||||
v2 := struct {
|
||||
Ary []int32 `nbt:"ary"`
|
||||
}{[]int32{0, -10, 3}}
|
||||
out = []byte{TagCompound, 0x00, 0x00,
|
||||
out = []byte{
|
||||
TagCompound, 0x00, 0x00,
|
||||
TagIntArray, 0x00, 0x03, 'a', 'r', 'y', 0, 0, 0, 3,
|
||||
0x00, 0x00, 0x00, 0x00, // 0
|
||||
0xff, 0xff, 0xff, 0xf6, // -10
|
||||
@ -72,7 +74,8 @@ func TestEncoder_encodeBool(t *testing.T) {
|
||||
func TestEncoder_Encode_floatArray(t *testing.T) {
|
||||
// Test marshal pure Int array
|
||||
v := []float32{0.3, -100, float32(math.NaN())}
|
||||
out := []byte{TagList, 0x00, 0x00, TagFloat, 0, 0, 0, 3,
|
||||
out := []byte{
|
||||
TagList, 0x00, 0x00, TagFloat, 0, 0, 0, 3,
|
||||
0x3e, 0x99, 0x99, 0x9a, // 0.3
|
||||
0xc2, 0xc8, 0x00, 0x00, // -100
|
||||
0x7f, 0xc0, 0x00, 0x00, // NaN
|
||||
@ -86,8 +89,10 @@ func TestEncoder_Encode_floatArray(t *testing.T) {
|
||||
|
||||
func TestEncoder_Encode_string(t *testing.T) {
|
||||
v := "Test"
|
||||
out := []byte{TagString, 0x00, 0x00, 0, 4,
|
||||
'T', 'e', 's', 't'}
|
||||
out := []byte{
|
||||
TagString, 0x00, 0x00, 0, 4,
|
||||
'T', 'e', 's', 't',
|
||||
}
|
||||
|
||||
if data, err := Marshal(v); err != nil {
|
||||
t.Error(err)
|
||||
|
@ -62,7 +62,7 @@ func ExampleDecoder_Decode_singleTagString() {
|
||||
}
|
||||
|
||||
func ExampleEncoder_Encode_tagCompound() {
|
||||
var value = struct {
|
||||
value := struct {
|
||||
Name string `nbt:"name"`
|
||||
}{"Tnze"}
|
||||
|
||||
|
@ -398,7 +398,7 @@ func (d *decodeState) scanNext() {
|
||||
d.opcode = d.scan.step(&d.scan, d.data[d.off])
|
||||
d.off++
|
||||
} else {
|
||||
//d.opcode = d.scan.eof()
|
||||
// d.opcode = d.scan.eof()
|
||||
d.off = len(d.data) + 1 // mark processed EOF with len+1
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSNBT_checkScanCode(t *testing.T) {
|
||||
//t.SkipNow()
|
||||
// t.SkipNow()
|
||||
var s scanner
|
||||
s.reset()
|
||||
for _, c := range []byte(`{b:[vanilla],c:0D}`) {
|
||||
@ -66,6 +66,7 @@ func TestSNBT_compound(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSNBT_list(t *testing.T) {
|
||||
goods := []string{
|
||||
`[]`, `[a, 'b', "c", d]`, // List of string
|
||||
|
Reference in New Issue
Block a user