Skip to content

Commit

Permalink
Fix generic deserialization of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
actgardner committed Sep 12, 2021
1 parent 6fc7168 commit 8a6c391
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions v9/generic/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func (r *enumDatum) Datum() interface{} {
}

func (r *enumDatum) SetBoolean(v bool) { panic("") }
func (r *enumDatum) SetInt(v int32) { panic("") }
func (r *enumDatum) SetLong(v int64) {
func (r *enumDatum) SetInt(v int32) {
r.value = r.symbols[v]
}
func (r *enumDatum) SetLong(v int64) {
panic("")
}
func (r *enumDatum) SetFloat(v float32) { panic("") }
func (r *enumDatum) SetDouble(v float64) { panic("") }
func (r *enumDatum) SetBytes(v []byte) { panic("") }
Expand Down
27 changes: 27 additions & 0 deletions v9/generic/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ func TestUnion(t *testing.T) {
}

func TestEnum(t *testing.T) {
s := []byte(`
{
"type": "enum",
"name": "testenum",
"symbols": [
"ONE",
"TWO",
"THREE"
]
}
`)
codec, err := NewCodecFromSchema(s, s)
assert.NoError(t, err)

for _, f := range []struct {
data []byte
expected interface{}
}{
{data: []byte{2}, expected: "TWO"},
{data: []byte{4}, expected: "THREE"},
} {
r := bytes.NewBuffer(f.data)
datum, err := codec.Deserialize(r)
assert.NoError(t, err)

assert.Equal(t, f.expected, datum)
}
}

func TestLinkedList(t *testing.T) {
Expand Down

0 comments on commit 8a6c391

Please sign in to comment.