Skip to content

Commit c610362

Browse files
authored
fix: support go uint type (#28)
1 parent 539a6f1 commit c610362

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

serialize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func Marshal(input interface{}, options *MarshalOptions) ([]byte, error) {
225225
reflect.Int64:
226226
return MarshalInt(value.Int()), nil
227227

228-
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
228+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
229229
return MarshalUint(value.Uint()), nil
230230

231231
case reflect.Float32:

serialize_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var marshalTests = map[string]marshalTest{
6666
"int32: 27": {int32(27), []byte("i:27;"), nil},
6767
"int64: 28": {int64(28), []byte("i:28;"), nil},
6868

69+
"uint: 3": {uint(3), []byte("i:3;"), nil},
6970
"uint8: 4": {uint8(4), []byte("i:4;"), nil},
7071
"uint16: 7": {uint16(7), []byte("i:7;"), nil},
7172
"uint32: 9": {uint32(9), []byte("i:9;"), nil},

unserialize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func Unmarshal(data []byte, v interface{}) error {
134134

135135
value.SetInt(v)
136136

137-
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
137+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
138138
v, err := UnmarshalUint(data)
139139
if err != nil {
140140
return err

unserialize_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ func TestUnmarshalInt(t *testing.T) {
113113
}
114114
})
115115

116+
t.Run("uint", func(t *testing.T) {
117+
var result uint
118+
err := phpserialize.Unmarshal(test.input, &result)
119+
120+
if test.expectedError == nil {
121+
expectErrorToNotHaveOccurred(t, err)
122+
if result != uint(test.output) {
123+
t.Errorf("Expected '%v', got '%v'", result, test.output)
124+
}
125+
} else {
126+
expectErrorToEqual(t, err, test.expectedError)
127+
}
128+
})
129+
116130
t.Run("uint8", func(t *testing.T) {
117131
var result uint8
118132
err := phpserialize.Unmarshal(test.input, &result)

0 commit comments

Comments
 (0)