1
1
mirror of https://github.com/wader/fq.git synced 2024-12-29 00:22:38 +03:00
fq/format/avro/decoders/decoders.go
2022-01-19 23:53:33 -06:00

53 lines
1.1 KiB
Go

package decoders
import (
"fmt"
"github.com/wader/fq/format/avro/schema"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)
type DecodeFn func(string, *decode.D) interface{}
func DecodeFnForSchema(s schema.SimplifiedSchema) (DecodeFn, error) {
var sms []scalar.Mapper
mapper := logicalMapperForSchema(s)
if mapper != nil {
sms = append(sms, mapper)
}
switch s.Type {
case schema.ARRAY:
return decodeArrayFn(s)
case schema.BOOLEAN:
return decodeBoolFn(sms...)
case schema.BYTES:
return decodeBytesFn(sms...)
case schema.DOUBLE:
return decodeDoubleFn(sms...)
case schema.ENUM:
return decodeEnumFn(s, sms...)
case schema.FIXED:
return decodeFixedFn(s, sms...)
case schema.FLOAT:
return decodeFloatFn(sms...)
case schema.INT:
return decodeIntFn(sms...)
case schema.LONG:
return decodeLongFn(sms...)
case schema.NULL:
return decodeNullFn(sms...)
case schema.RECORD:
return decodeRecordFn(s)
case schema.STRING:
return decodeStringFn(s, sms...)
case schema.UNION:
return decodeUnionFn(s)
case schema.MAP:
return decodeMapFn(s)
default:
return nil, fmt.Errorf("unknown type: %s", s.Type)
}
}