diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08cb523 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +go.sum diff --git a/goimpl/go.mod b/goimpl/go.mod new file mode 100644 index 0000000..78b7842 --- /dev/null +++ b/goimpl/go.mod @@ -0,0 +1,13 @@ +module github.com/LioRoger/subscribe_example/goimpl + +go 1.14 + +require ( + github.com/Shopify/sarama v1.27.0 + github.com/actgardner/gogen-avro/v7 v7.1.1 + github.com/bsm/sarama-cluster v2.1.15+incompatible + github.com/linkedin/goavro v2.1.0+incompatible + github.com/mitchellh/mapstructure v1.3.3 + github.com/stretchr/testify v1.6.1 + gopkg.in/linkedin/goavro.v1 v1.0.5 // indirect +) diff --git a/goimpl/lib/dtsavro/array_field.go b/goimpl/lib/dtsavro/array_field.go new file mode 100644 index 0000000..ac3dc94 --- /dev/null +++ b/goimpl/lib/dtsavro/array_field.go @@ -0,0 +1,56 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +func writeArrayField(r []*Field, w io.Writer) error { + err := vm.WriteLong(int64(len(r)), w) + if err != nil || len(r) == 0 { + return err + } + for _, e := range r { + err = writeField(e, w) + if err != nil { + return err + } + } + return vm.WriteLong(0, w) +} + +type ArrayFieldWrapper struct { + Target *[]*Field +} + +func (_ *ArrayFieldWrapper) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetInt(v int32) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetLong(v int64) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetString(v string) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) SetUnionElem(v int64) { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) Get(i int) types.Field { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *ArrayFieldWrapper) Finalize() {} +func (_ *ArrayFieldWrapper) SetDefault(i int) { panic("Unsupported operation") } +func (r *ArrayFieldWrapper) NullField(i int) { + panic("Unsupported operation") +} + +func (r *ArrayFieldWrapper) AppendArray() types.Field { + var v *Field + v = NewField() + + *r.Target = append(*r.Target, v) + + return (*r.Target)[len(*r.Target)-1] +} diff --git a/goimpl/lib/dtsavro/array_long.go b/goimpl/lib/dtsavro/array_long.go new file mode 100644 index 0000000..ab4374a --- /dev/null +++ b/goimpl/lib/dtsavro/array_long.go @@ -0,0 +1,54 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +func writeArrayLong(r []int64, w io.Writer) error { + err := vm.WriteLong(int64(len(r)), w) + if err != nil || len(r) == 0 { + return err + } + for _, e := range r { + err = vm.WriteLong(e, w) + if err != nil { + return err + } + } + return vm.WriteLong(0, w) +} + +type ArrayLongWrapper struct { + Target *[]int64 +} + +func (_ *ArrayLongWrapper) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetInt(v int32) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetLong(v int64) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetString(v string) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) SetUnionElem(v int64) { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) Get(i int) types.Field { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *ArrayLongWrapper) Finalize() {} +func (_ *ArrayLongWrapper) SetDefault(i int) { panic("Unsupported operation") } +func (r *ArrayLongWrapper) NullField(i int) { + panic("Unsupported operation") +} + +func (r *ArrayLongWrapper) AppendArray() types.Field { + var v int64 + + *r.Target = append(*r.Target, v) + return &types.Long{Target: &(*r.Target)[len(*r.Target)-1]} +} diff --git a/goimpl/lib/dtsavro/array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go b/goimpl/lib/dtsavro/array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go new file mode 100644 index 0000000..486145c --- /dev/null +++ b/goimpl/lib/dtsavro/array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go @@ -0,0 +1,79 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +func writeArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r []*UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject, w io.Writer) error { + err := vm.WriteLong(int64(len(r)), w) + if err != nil || len(r) == 0 { + return err + } + for _, e := range r { + err = writeUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(e, w) + if err != nil { + return err + } + } + return vm.WriteLong(0, w) +} + +type ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper struct { + Target *[]*UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject +} + +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetBoolean(v bool) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetInt(v int32) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetLong(v int64) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetFloat(v float32) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetDouble(v float64) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetBytes(v []byte) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetString(v string) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetUnionElem(v int64) { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) Get(i int) types.Field { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) AppendMap(key string) types.Field { + panic("Unsupported operation") +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) Finalize() { +} +func (_ *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) SetDefault(i int) { + panic("Unsupported operation") +} +func (r *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) NullField(i int) { + (*r.Target)[len(*r.Target)-1] = nil +} + +func (r *ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper) AppendArray() types.Field { + var v *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject + v = NewUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject() + + *r.Target = append(*r.Target, v) + + return (*r.Target)[len(*r.Target)-1] +} diff --git a/goimpl/lib/dtsavro/binary_geometry.go b/goimpl/lib/dtsavro/binary_geometry.go new file mode 100644 index 0000000..fe2aeeb --- /dev/null +++ b/goimpl/lib/dtsavro/binary_geometry.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type BinaryGeometry struct { + Type string `json:"type"` + + Value []byte `json:"value"` +} + +const BinaryGeometryAvroCRC64Fingerprint = "\x92\xc6=\xfac$\x8e\x80" + +func NewBinaryGeometry() *BinaryGeometry { + return &BinaryGeometry{} +} + +func DeserializeBinaryGeometry(r io.Reader) (*BinaryGeometry, error) { + t := NewBinaryGeometry() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeBinaryGeometryFromSchema(r io.Reader, schema string) (*BinaryGeometry, error) { + t := NewBinaryGeometry() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeBinaryGeometry(r *BinaryGeometry, w io.Writer) error { + var err error + err = vm.WriteString(r.Type, w) + if err != nil { + return err + } + err = vm.WriteBytes(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *BinaryGeometry) Serialize(w io.Writer) error { + return writeBinaryGeometry(r, w) +} + +func (r *BinaryGeometry) Schema() string { + return "{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"com.alibaba.dts.formats.avro.BinaryGeometry\",\"type\":\"record\"}" +} + +func (r *BinaryGeometry) SchemaName() string { + return "com.alibaba.dts.formats.avro.BinaryGeometry" +} + +func (_ *BinaryGeometry) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetInt(v int32) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetLong(v int64) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetString(v string) { panic("Unsupported operation") } +func (_ *BinaryGeometry) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *BinaryGeometry) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Type} + case 1: + return &types.Bytes{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *BinaryGeometry) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *BinaryGeometry) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *BinaryGeometry) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *BinaryGeometry) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *BinaryGeometry) Finalize() {} + +func (_ *BinaryGeometry) AvroCRC64Fingerprint() []byte { + return []byte(BinaryGeometryAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/binary_object.go b/goimpl/lib/dtsavro/binary_object.go new file mode 100644 index 0000000..f54d645 --- /dev/null +++ b/goimpl/lib/dtsavro/binary_object.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type BinaryObject struct { + Type string `json:"type"` + + Value []byte `json:"value"` +} + +const BinaryObjectAvroCRC64Fingerprint = "\xaf\xbe\xee}\x1b\xe04~" + +func NewBinaryObject() *BinaryObject { + return &BinaryObject{} +} + +func DeserializeBinaryObject(r io.Reader) (*BinaryObject, error) { + t := NewBinaryObject() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeBinaryObjectFromSchema(r io.Reader, schema string) (*BinaryObject, error) { + t := NewBinaryObject() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeBinaryObject(r *BinaryObject, w io.Writer) error { + var err error + err = vm.WriteString(r.Type, w) + if err != nil { + return err + } + err = vm.WriteBytes(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *BinaryObject) Serialize(w io.Writer) error { + return writeBinaryObject(r, w) +} + +func (r *BinaryObject) Schema() string { + return "{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"com.alibaba.dts.formats.avro.BinaryObject\",\"type\":\"record\"}" +} + +func (r *BinaryObject) SchemaName() string { + return "com.alibaba.dts.formats.avro.BinaryObject" +} + +func (_ *BinaryObject) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *BinaryObject) SetInt(v int32) { panic("Unsupported operation") } +func (_ *BinaryObject) SetLong(v int64) { panic("Unsupported operation") } +func (_ *BinaryObject) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *BinaryObject) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *BinaryObject) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *BinaryObject) SetString(v string) { panic("Unsupported operation") } +func (_ *BinaryObject) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *BinaryObject) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Type} + case 1: + return &types.Bytes{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *BinaryObject) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *BinaryObject) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *BinaryObject) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *BinaryObject) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *BinaryObject) Finalize() {} + +func (_ *BinaryObject) AvroCRC64Fingerprint() []byte { + return []byte(BinaryObjectAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/character.go b/goimpl/lib/dtsavro/character.go new file mode 100644 index 0000000..2022cd1 --- /dev/null +++ b/goimpl/lib/dtsavro/character.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Character struct { + Charset string `json:"charset"` + + Value []byte `json:"value"` +} + +const CharacterAvroCRC64Fingerprint = "\xc1a\xeb\xfb\x9e\x97\\\xe7" + +func NewCharacter() *Character { + return &Character{} +} + +func DeserializeCharacter(r io.Reader) (*Character, error) { + t := NewCharacter() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeCharacterFromSchema(r io.Reader, schema string) (*Character, error) { + t := NewCharacter() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeCharacter(r *Character, w io.Writer) error { + var err error + err = vm.WriteString(r.Charset, w) + if err != nil { + return err + } + err = vm.WriteBytes(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *Character) Serialize(w io.Writer) error { + return writeCharacter(r, w) +} + +func (r *Character) Schema() string { + return "{\"fields\":[{\"name\":\"charset\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"com.alibaba.dts.formats.avro.Character\",\"type\":\"record\"}" +} + +func (r *Character) SchemaName() string { + return "com.alibaba.dts.formats.avro.Character" +} + +func (_ *Character) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Character) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Character) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Character) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Character) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Character) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Character) SetString(v string) { panic("Unsupported operation") } +func (_ *Character) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Character) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Charset} + case 1: + return &types.Bytes{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *Character) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Character) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Character) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Character) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Character) Finalize() {} + +func (_ *Character) AvroCRC64Fingerprint() []byte { + return []byte(CharacterAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/date_time.go b/goimpl/lib/dtsavro/date_time.go new file mode 100644 index 0000000..8c219d1 --- /dev/null +++ b/goimpl/lib/dtsavro/date_time.go @@ -0,0 +1,214 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type DateTime struct { + Year *UnionNullInt `json:"year"` + + Month *UnionNullInt `json:"month"` + + Day *UnionNullInt `json:"day"` + + Hour *UnionNullInt `json:"hour"` + + Minute *UnionNullInt `json:"minute"` + + Second *UnionNullInt `json:"second"` + + Millis *UnionNullInt `json:"millis"` +} + +const DateTimeAvroCRC64Fingerprint = "\xef!̾罐\xf1" + +func NewDateTime() *DateTime { + return &DateTime{} +} + +func DeserializeDateTime(r io.Reader) (*DateTime, error) { + t := NewDateTime() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeDateTimeFromSchema(r io.Reader, schema string) (*DateTime, error) { + t := NewDateTime() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeDateTime(r *DateTime, w io.Writer) error { + var err error + err = writeUnionNullInt(r.Year, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Month, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Day, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Hour, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Minute, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Second, w) + if err != nil { + return err + } + err = writeUnionNullInt(r.Millis, w) + if err != nil { + return err + } + return err +} + +func (r *DateTime) Serialize(w io.Writer) error { + return writeDateTime(r, w) +} + +func (r *DateTime) Schema() string { + return "{\"fields\":[{\"default\":null,\"name\":\"year\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"month\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"day\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"hour\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"minute\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"second\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"millis\",\"type\":[\"null\",\"int\"]}],\"name\":\"com.alibaba.dts.formats.avro.DateTime\",\"type\":\"record\"}" +} + +func (r *DateTime) SchemaName() string { + return "com.alibaba.dts.formats.avro.DateTime" +} + +func (_ *DateTime) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *DateTime) SetInt(v int32) { panic("Unsupported operation") } +func (_ *DateTime) SetLong(v int64) { panic("Unsupported operation") } +func (_ *DateTime) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *DateTime) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *DateTime) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *DateTime) SetString(v string) { panic("Unsupported operation") } +func (_ *DateTime) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *DateTime) Get(i int) types.Field { + switch i { + case 0: + r.Year = NewUnionNullInt() + + return r.Year + case 1: + r.Month = NewUnionNullInt() + + return r.Month + case 2: + r.Day = NewUnionNullInt() + + return r.Day + case 3: + r.Hour = NewUnionNullInt() + + return r.Hour + case 4: + r.Minute = NewUnionNullInt() + + return r.Minute + case 5: + r.Second = NewUnionNullInt() + + return r.Second + case 6: + r.Millis = NewUnionNullInt() + + return r.Millis + } + panic("Unknown field index") +} + +func (r *DateTime) SetDefault(i int) { + switch i { + case 0: + r.Year = nil + return + case 1: + r.Month = nil + return + case 2: + r.Day = nil + return + case 3: + r.Hour = nil + return + case 4: + r.Minute = nil + return + case 5: + r.Second = nil + return + case 6: + r.Millis = nil + return + } + panic("Unknown field index") +} + +func (r *DateTime) NullField(i int) { + switch i { + case 0: + r.Year = nil + return + case 1: + r.Month = nil + return + case 2: + r.Day = nil + return + case 3: + r.Hour = nil + return + case 4: + r.Minute = nil + return + case 5: + r.Second = nil + return + case 6: + r.Millis = nil + return + } + panic("Not a nullable field index") +} + +func (_ *DateTime) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *DateTime) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *DateTime) Finalize() {} + +func (_ *DateTime) AvroCRC64Fingerprint() []byte { + return []byte(DateTimeAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/decimal.go b/goimpl/lib/dtsavro/decimal.go new file mode 100644 index 0000000..031169a --- /dev/null +++ b/goimpl/lib/dtsavro/decimal.go @@ -0,0 +1,126 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Decimal struct { + Value string `json:"value"` + + Precision int32 `json:"precision"` + + Scale int32 `json:"scale"` +} + +const DecimalAvroCRC64Fingerprint = "\xf2\x13\xb4\xe6RX\x93\x0f" + +func NewDecimal() *Decimal { + return &Decimal{} +} + +func DeserializeDecimal(r io.Reader) (*Decimal, error) { + t := NewDecimal() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeDecimalFromSchema(r io.Reader, schema string) (*Decimal, error) { + t := NewDecimal() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeDecimal(r *Decimal, w io.Writer) error { + var err error + err = vm.WriteString(r.Value, w) + if err != nil { + return err + } + err = vm.WriteInt(r.Precision, w) + if err != nil { + return err + } + err = vm.WriteInt(r.Scale, w) + if err != nil { + return err + } + return err +} + +func (r *Decimal) Serialize(w io.Writer) error { + return writeDecimal(r, w) +} + +func (r *Decimal) Schema() string { + return "{\"fields\":[{\"name\":\"value\",\"type\":\"string\"},{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"scale\",\"type\":\"int\"}],\"name\":\"com.alibaba.dts.formats.avro.Decimal\",\"type\":\"record\"}" +} + +func (r *Decimal) SchemaName() string { + return "com.alibaba.dts.formats.avro.Decimal" +} + +func (_ *Decimal) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Decimal) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Decimal) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Decimal) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Decimal) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Decimal) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Decimal) SetString(v string) { panic("Unsupported operation") } +func (_ *Decimal) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Decimal) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Value} + case 1: + return &types.Int{Target: &r.Precision} + case 2: + return &types.Int{Target: &r.Scale} + } + panic("Unknown field index") +} + +func (r *Decimal) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Decimal) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Decimal) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Decimal) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Decimal) Finalize() {} + +func (_ *Decimal) AvroCRC64Fingerprint() []byte { + return []byte(DecimalAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/empty_object.go b/goimpl/lib/dtsavro/empty_object.go new file mode 100644 index 0000000..1651c8d --- /dev/null +++ b/goimpl/lib/dtsavro/empty_object.go @@ -0,0 +1,120 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type EmptyObject int32 + +const ( + EmptyObjectNULL EmptyObject = 0 + EmptyObjectNONE EmptyObject = 1 +) + +func (e EmptyObject) String() string { + switch e { + case EmptyObjectNULL: + return "NULL" + case EmptyObjectNONE: + return "NONE" + } + return "unknown" +} + +func writeEmptyObject(r EmptyObject, w io.Writer) error { + return vm.WriteInt(int32(r), w) +} + +func NewEmptyObjectValue(raw string) (r EmptyObject, err error) { + switch raw { + case "NULL": + return EmptyObjectNULL, nil + case "NONE": + return EmptyObjectNONE, nil + } + + return -1, fmt.Errorf("invalid value for EmptyObject: '%s'", raw) +} + +func (b *EmptyObject) MarshalJSON() ([]byte, error) { + return json.Marshal([]byte(b.String())) +} + +func (b *EmptyObject) UnmarshalJSON(data []byte) error { + var stringVal string + err := json.Unmarshal(data, &stringVal) + if err != nil { + return err + } + val, err := NewEmptyObjectValue(stringVal) + *b = val + return err +} + +type EmptyObjectWrapper struct { + Target *EmptyObject +} + +func (b *EmptyObjectWrapper) SetBoolean(v bool) { + panic("Unable to assign boolean to int field") +} + +func (b *EmptyObjectWrapper) SetInt(v int32) { + *(b.Target) = EmptyObject(v) +} + +func (b *EmptyObjectWrapper) SetLong(v int64) { + panic("Unable to assign long to int field") +} + +func (b *EmptyObjectWrapper) SetFloat(v float32) { + panic("Unable to assign float to int field") +} + +func (b *EmptyObjectWrapper) SetUnionElem(v int64) { + panic("Unable to assign union elem to int field") +} + +func (b *EmptyObjectWrapper) SetDouble(v float64) { + panic("Unable to assign double to int field") +} + +func (b *EmptyObjectWrapper) SetBytes(v []byte) { + panic("Unable to assign bytes to int field") +} + +func (b *EmptyObjectWrapper) SetString(v string) { + panic("Unable to assign string to int field") +} + +func (b *EmptyObjectWrapper) Get(i int) types.Field { + panic("Unable to get field from int field") +} + +func (b *EmptyObjectWrapper) SetDefault(i int) { + panic("Unable to set default on int field") +} + +func (b *EmptyObjectWrapper) AppendMap(key string) types.Field { + panic("Unable to append map key to from int field") +} + +func (b *EmptyObjectWrapper) AppendArray() types.Field { + panic("Unable to append array element to from int field") +} + +func (b *EmptyObjectWrapper) NullField(int) { + panic("Unable to null field in int field") +} + +func (b *EmptyObjectWrapper) Finalize() {} diff --git a/goimpl/lib/dtsavro/field.go b/goimpl/lib/dtsavro/field.go new file mode 100644 index 0000000..f1acbea --- /dev/null +++ b/goimpl/lib/dtsavro/field.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Field struct { + Name string `json:"name"` + + DataTypeNumber int32 `json:"dataTypeNumber"` +} + +const FieldAvroCRC64Fingerprint = "\xa4\x82\xda_\x04c\xb1\x00" + +func NewField() *Field { + return &Field{} +} + +func DeserializeField(r io.Reader) (*Field, error) { + t := NewField() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeFieldFromSchema(r io.Reader, schema string) (*Field, error) { + t := NewField() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeField(r *Field, w io.Writer) error { + var err error + err = vm.WriteString(r.Name, w) + if err != nil { + return err + } + err = vm.WriteInt(r.DataTypeNumber, w) + if err != nil { + return err + } + return err +} + +func (r *Field) Serialize(w io.Writer) error { + return writeField(r, w) +} + +func (r *Field) Schema() string { + return "{\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"dataTypeNumber\",\"type\":\"int\"}],\"name\":\"com.alibaba.dts.formats.avro.Field\",\"type\":\"record\"}" +} + +func (r *Field) SchemaName() string { + return "com.alibaba.dts.formats.avro.Field" +} + +func (_ *Field) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Field) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Field) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Field) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Field) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Field) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Field) SetString(v string) { panic("Unsupported operation") } +func (_ *Field) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Field) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Name} + case 1: + return &types.Int{Target: &r.DataTypeNumber} + } + panic("Unknown field index") +} + +func (r *Field) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Field) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Field) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Field) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Field) Finalize() {} + +func (_ *Field) AvroCRC64Fingerprint() []byte { + return []byte(FieldAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/float.go b/goimpl/lib/dtsavro/float.go new file mode 100644 index 0000000..384b235 --- /dev/null +++ b/goimpl/lib/dtsavro/float.go @@ -0,0 +1,126 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Float struct { + Value float64 `json:"value"` + + Precision int32 `json:"precision"` + + Scale int32 `json:"scale"` +} + +const FloatAvroCRC64Fingerprint = "\xf1N6\xa3\x8b#\xad\xe5" + +func NewFloat() *Float { + return &Float{} +} + +func DeserializeFloat(r io.Reader) (*Float, error) { + t := NewFloat() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeFloatFromSchema(r io.Reader, schema string) (*Float, error) { + t := NewFloat() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeFloat(r *Float, w io.Writer) error { + var err error + err = vm.WriteDouble(r.Value, w) + if err != nil { + return err + } + err = vm.WriteInt(r.Precision, w) + if err != nil { + return err + } + err = vm.WriteInt(r.Scale, w) + if err != nil { + return err + } + return err +} + +func (r *Float) Serialize(w io.Writer) error { + return writeFloat(r, w) +} + +func (r *Float) Schema() string { + return "{\"fields\":[{\"name\":\"value\",\"type\":\"double\"},{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"scale\",\"type\":\"int\"}],\"name\":\"com.alibaba.dts.formats.avro.Float\",\"type\":\"record\"}" +} + +func (r *Float) SchemaName() string { + return "com.alibaba.dts.formats.avro.Float" +} + +func (_ *Float) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Float) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Float) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Float) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Float) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Float) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Float) SetString(v string) { panic("Unsupported operation") } +func (_ *Float) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Float) Get(i int) types.Field { + switch i { + case 0: + return &types.Double{Target: &r.Value} + case 1: + return &types.Int{Target: &r.Precision} + case 2: + return &types.Int{Target: &r.Scale} + } + panic("Unknown field index") +} + +func (r *Float) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Float) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Float) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Float) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Float) Finalize() {} + +func (_ *Float) AvroCRC64Fingerprint() []byte { + return []byte(FloatAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/integer.go b/goimpl/lib/dtsavro/integer.go new file mode 100644 index 0000000..a239062 --- /dev/null +++ b/goimpl/lib/dtsavro/integer.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Integer struct { + Precision int32 `json:"precision"` + + Value string `json:"value"` +} + +const IntegerAvroCRC64Fingerprint = "\xbcV\u07bc\x88\xb9hx" + +func NewInteger() *Integer { + return &Integer{} +} + +func DeserializeInteger(r io.Reader) (*Integer, error) { + t := NewInteger() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeIntegerFromSchema(r io.Reader, schema string) (*Integer, error) { + t := NewInteger() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeInteger(r *Integer, w io.Writer) error { + var err error + err = vm.WriteInt(r.Precision, w) + if err != nil { + return err + } + err = vm.WriteString(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *Integer) Serialize(w io.Writer) error { + return writeInteger(r, w) +} + +func (r *Integer) Schema() string { + return "{\"fields\":[{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"com.alibaba.dts.formats.avro.Integer\",\"type\":\"record\"}" +} + +func (r *Integer) SchemaName() string { + return "com.alibaba.dts.formats.avro.Integer" +} + +func (_ *Integer) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Integer) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Integer) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Integer) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Integer) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Integer) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Integer) SetString(v string) { panic("Unsupported operation") } +func (_ *Integer) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Integer) Get(i int) types.Field { + switch i { + case 0: + return &types.Int{Target: &r.Precision} + case 1: + return &types.String{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *Integer) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Integer) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Integer) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Integer) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Integer) Finalize() {} + +func (_ *Integer) AvroCRC64Fingerprint() []byte { + return []byte(IntegerAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/map_string.go b/goimpl/lib/dtsavro/map_string.go new file mode 100644 index 0000000..133cec6 --- /dev/null +++ b/goimpl/lib/dtsavro/map_string.go @@ -0,0 +1,66 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +func writeMapString(r map[string]string, w io.Writer) error { + err := vm.WriteLong(int64(len(r)), w) + if err != nil || len(r) == 0 { + return err + } + for k, e := range r { + err = vm.WriteString(k, w) + if err != nil { + return err + } + err = vm.WriteString(e, w) + if err != nil { + return err + } + } + return vm.WriteLong(0, w) +} + +type MapStringWrapper struct { + Target *map[string]string + keys []string + values []string +} + +func (_ *MapStringWrapper) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetInt(v int32) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetLong(v int64) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetString(v string) { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetUnionElem(v int64) { panic("Unsupported operation") } +func (_ *MapStringWrapper) Get(i int) types.Field { panic("Unsupported operation") } +func (_ *MapStringWrapper) SetDefault(i int) { panic("Unsupported operation") } + +func (r *MapStringWrapper) NullField(_ int) { + panic("Unsupported operation") +} + +func (r *MapStringWrapper) Finalize() { + for i := range r.keys { + (*r.Target)[r.keys[i]] = r.values[i] + } +} + +func (r *MapStringWrapper) AppendMap(key string) types.Field { + r.keys = append(r.keys, key) + var v string + r.values = append(r.values, v) + return &types.String{Target: &r.values[len(r.values)-1]} +} + +func (_ *MapStringWrapper) AppendArray() types.Field { panic("Unsupported operation") } diff --git a/goimpl/lib/dtsavro/operation.go b/goimpl/lib/dtsavro/operation.go new file mode 100644 index 0000000..cfb747b --- /dev/null +++ b/goimpl/lib/dtsavro/operation.go @@ -0,0 +1,195 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type Operation int32 + +const ( + OperationINSERT Operation = 0 + OperationUPDATE Operation = 1 + OperationDELETE Operation = 2 + OperationDDL Operation = 3 + OperationBEGIN Operation = 4 + OperationCOMMIT Operation = 5 + OperationROLLBACK Operation = 6 + OperationABORT Operation = 7 + OperationHEARTBEAT Operation = 8 + OperationCHECKPOINT Operation = 9 + OperationCOMMAND Operation = 10 + OperationFILL Operation = 11 + OperationFINISH Operation = 12 + OperationCONTROL Operation = 13 + OperationRDB Operation = 14 + OperationNOOP Operation = 15 + OperationINIT Operation = 16 +) + +func (e Operation) String() string { + switch e { + case OperationINSERT: + return "INSERT" + case OperationUPDATE: + return "UPDATE" + case OperationDELETE: + return "DELETE" + case OperationDDL: + return "DDL" + case OperationBEGIN: + return "BEGIN" + case OperationCOMMIT: + return "COMMIT" + case OperationROLLBACK: + return "ROLLBACK" + case OperationABORT: + return "ABORT" + case OperationHEARTBEAT: + return "HEARTBEAT" + case OperationCHECKPOINT: + return "CHECKPOINT" + case OperationCOMMAND: + return "COMMAND" + case OperationFILL: + return "FILL" + case OperationFINISH: + return "FINISH" + case OperationCONTROL: + return "CONTROL" + case OperationRDB: + return "RDB" + case OperationNOOP: + return "NOOP" + case OperationINIT: + return "INIT" + } + return "unknown" +} + +func writeOperation(r Operation, w io.Writer) error { + return vm.WriteInt(int32(r), w) +} + +func NewOperationValue(raw string) (r Operation, err error) { + switch raw { + case "INSERT": + return OperationINSERT, nil + case "UPDATE": + return OperationUPDATE, nil + case "DELETE": + return OperationDELETE, nil + case "DDL": + return OperationDDL, nil + case "BEGIN": + return OperationBEGIN, nil + case "COMMIT": + return OperationCOMMIT, nil + case "ROLLBACK": + return OperationROLLBACK, nil + case "ABORT": + return OperationABORT, nil + case "HEARTBEAT": + return OperationHEARTBEAT, nil + case "CHECKPOINT": + return OperationCHECKPOINT, nil + case "COMMAND": + return OperationCOMMAND, nil + case "FILL": + return OperationFILL, nil + case "FINISH": + return OperationFINISH, nil + case "CONTROL": + return OperationCONTROL, nil + case "RDB": + return OperationRDB, nil + case "NOOP": + return OperationNOOP, nil + case "INIT": + return OperationINIT, nil + } + + return -1, fmt.Errorf("invalid value for Operation: '%s'", raw) +} + +func (b *Operation) MarshalJSON() ([]byte, error) { + return json.Marshal([]byte(b.String())) +} + +func (b *Operation) UnmarshalJSON(data []byte) error { + var stringVal string + err := json.Unmarshal(data, &stringVal) + if err != nil { + return err + } + val, err := NewOperationValue(stringVal) + *b = val + return err +} + +type OperationWrapper struct { + Target *Operation +} + +func (b *OperationWrapper) SetBoolean(v bool) { + panic("Unable to assign boolean to int field") +} + +func (b *OperationWrapper) SetInt(v int32) { + *(b.Target) = Operation(v) +} + +func (b *OperationWrapper) SetLong(v int64) { + panic("Unable to assign long to int field") +} + +func (b *OperationWrapper) SetFloat(v float32) { + panic("Unable to assign float to int field") +} + +func (b *OperationWrapper) SetUnionElem(v int64) { + panic("Unable to assign union elem to int field") +} + +func (b *OperationWrapper) SetDouble(v float64) { + panic("Unable to assign double to int field") +} + +func (b *OperationWrapper) SetBytes(v []byte) { + panic("Unable to assign bytes to int field") +} + +func (b *OperationWrapper) SetString(v string) { + panic("Unable to assign string to int field") +} + +func (b *OperationWrapper) Get(i int) types.Field { + panic("Unable to get field from int field") +} + +func (b *OperationWrapper) SetDefault(i int) { + panic("Unable to set default on int field") +} + +func (b *OperationWrapper) AppendMap(key string) types.Field { + panic("Unable to append map key to from int field") +} + +func (b *OperationWrapper) AppendArray() types.Field { + panic("Unable to append array element to from int field") +} + +func (b *OperationWrapper) NullField(int) { + panic("Unable to null field in int field") +} + +func (b *OperationWrapper) Finalize() {} diff --git a/goimpl/lib/dtsavro/record.go b/goimpl/lib/dtsavro/record.go new file mode 100644 index 0000000..c06fa9b --- /dev/null +++ b/goimpl/lib/dtsavro/record.go @@ -0,0 +1,279 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Record struct { + // version infomation + Version int32 `json:"version"` + // unique id of this record in the whole stream + Id int64 `json:"id"` + // record log timestamp + SourceTimestamp int64 `json:"sourceTimestamp"` + // record source location information + SourcePosition string `json:"sourcePosition"` + // safe record source location information, use to recovery. + SafeSourcePosition string `json:"safeSourcePosition"` + // record transation id + SourceTxid string `json:"sourceTxid"` + // source dataource + Source *Source `json:"source"` + + Operation Operation `json:"operation"` + + ObjectName *UnionNullString `json:"objectName"` + // time when this record is processed along the stream dataflow + ProcessTimestamps *UnionNullArrayLong `json:"processTimestamps"` + // tags to identify properties of this record + Tags map[string]string `json:"tags"` + + Fields *UnionNullStringArrayField `json:"fields"` + + BeforeImages *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject `json:"beforeImages"` + + AfterImages *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject `json:"afterImages"` + // the timestamp in unit of millisecond that record is born in source + BornTimestamp int64 `json:"bornTimestamp"` +} + +const RecordAvroCRC64Fingerprint = "x\xc4\xc4yg\x16\xeb\xae" + +func NewRecord() *Record { + return &Record{} +} + +func DeserializeRecord(r io.Reader) (*Record, error) { + t := NewRecord() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeRecordFromSchema(r io.Reader, schema string) (*Record, error) { + t := NewRecord() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeRecord(r *Record, w io.Writer) error { + var err error + err = vm.WriteInt(r.Version, w) + if err != nil { + return err + } + err = vm.WriteLong(r.Id, w) + if err != nil { + return err + } + err = vm.WriteLong(r.SourceTimestamp, w) + if err != nil { + return err + } + err = vm.WriteString(r.SourcePosition, w) + if err != nil { + return err + } + err = vm.WriteString(r.SafeSourcePosition, w) + if err != nil { + return err + } + err = vm.WriteString(r.SourceTxid, w) + if err != nil { + return err + } + err = writeSource(r.Source, w) + if err != nil { + return err + } + err = writeOperation(r.Operation, w) + if err != nil { + return err + } + err = writeUnionNullString(r.ObjectName, w) + if err != nil { + return err + } + err = writeUnionNullArrayLong(r.ProcessTimestamps, w) + if err != nil { + return err + } + err = writeMapString(r.Tags, w) + if err != nil { + return err + } + err = writeUnionNullStringArrayField(r.Fields, w) + if err != nil { + return err + } + err = writeUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r.BeforeImages, w) + if err != nil { + return err + } + err = writeUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r.AfterImages, w) + if err != nil { + return err + } + err = vm.WriteLong(r.BornTimestamp, w) + if err != nil { + return err + } + return err +} + +func (r *Record) Serialize(w io.Writer) error { + return writeRecord(r, w) +} + +func (r *Record) Schema() string { + return "{\"fields\":[{\"doc\":\"version infomation\",\"name\":\"version\",\"type\":\"int\"},{\"doc\":\"unique id of this record in the whole stream\",\"name\":\"id\",\"type\":\"long\"},{\"doc\":\"record log timestamp\",\"name\":\"sourceTimestamp\",\"type\":\"long\"},{\"doc\":\"record source location information\",\"name\":\"sourcePosition\",\"type\":\"string\"},{\"default\":\"\",\"doc\":\"safe record source location information, use to recovery.\",\"name\":\"safeSourcePosition\",\"type\":\"string\"},{\"default\":\"\",\"doc\":\"record transation id\",\"name\":\"sourceTxid\",\"type\":\"string\"},{\"doc\":\"source dataource\",\"name\":\"source\",\"type\":{\"fields\":[{\"name\":\"sourceType\",\"type\":{\"name\":\"SourceType\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"symbols\":[\"MySQL\",\"Oracle\",\"SQLServer\",\"PostgreSQL\",\"MongoDB\",\"Redis\",\"DB2\",\"PPAS\",\"DRDS\",\"HBASE\",\"HDFS\",\"FILE\",\"OTHER\"],\"type\":\"enum\"}},{\"doc\":\"source datasource version information\",\"name\":\"version\",\"type\":\"string\"}],\"name\":\"Source\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"}},{\"name\":\"operation\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":{\"name\":\"Operation\",\"symbols\":[\"INSERT\",\"UPDATE\",\"DELETE\",\"DDL\",\"BEGIN\",\"COMMIT\",\"ROLLBACK\",\"ABORT\",\"HEARTBEAT\",\"CHECKPOINT\",\"COMMAND\",\"FILL\",\"FINISH\",\"CONTROL\",\"RDB\",\"NOOP\",\"INIT\"],\"type\":\"enum\"}},{\"default\":null,\"name\":\"objectName\",\"type\":[\"null\",\"string\"]},{\"default\":null,\"doc\":\"time when this record is processed along the stream dataflow\",\"name\":\"processTimestamps\",\"type\":[\"null\",{\"items\":\"long\",\"type\":\"array\"}]},{\"default\":{},\"doc\":\"tags to identify properties of this record\",\"name\":\"tags\",\"type\":{\"type\":\"map\",\"values\":\"string\"}},{\"default\":null,\"name\":\"fields\",\"type\":[\"null\",\"string\",{\"items\":{\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"dataTypeNumber\",\"type\":\"int\"}],\"name\":\"Field\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},\"type\":\"array\"}]},{\"default\":null,\"name\":\"beforeImages\",\"type\":[\"null\",\"string\",{\"items\":[\"null\",{\"fields\":[{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"Integer\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"charset\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"Character\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"value\",\"type\":\"string\"},{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"scale\",\"type\":\"int\"}],\"name\":\"Decimal\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"value\",\"type\":\"double\"},{\"name\":\"precision\",\"type\":\"int\"},{\"name\":\"scale\",\"type\":\"int\"}],\"name\":\"Float\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"timestamp\",\"type\":\"long\"},{\"name\":\"millis\",\"type\":\"int\"}],\"name\":\"Timestamp\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"default\":null,\"name\":\"year\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"month\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"day\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"hour\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"minute\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"second\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"millis\",\"type\":[\"null\",\"int\"]}],\"name\":\"DateTime\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"value\",\"type\":\"com.alibaba.dts.formats.avro.DateTime\"},{\"name\":\"timezone\",\"type\":\"string\"}],\"name\":\"TimestampWithTimeZone\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"BinaryGeometry\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"TextGeometry\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"bytes\"}],\"name\":\"BinaryObject\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"TextObject\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"},{\"name\":\"EmptyObject\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"symbols\":[\"NULL\",\"NONE\"],\"type\":\"enum\"}],\"type\":\"array\"}]},{\"default\":null,\"name\":\"afterImages\",\"type\":[\"null\",\"string\",{\"items\":[\"null\",\"com.alibaba.dts.formats.avro.Integer\",\"com.alibaba.dts.formats.avro.Character\",\"com.alibaba.dts.formats.avro.Decimal\",\"com.alibaba.dts.formats.avro.Float\",\"com.alibaba.dts.formats.avro.Timestamp\",\"com.alibaba.dts.formats.avro.DateTime\",\"com.alibaba.dts.formats.avro.TimestampWithTimeZone\",\"com.alibaba.dts.formats.avro.BinaryGeometry\",\"com.alibaba.dts.formats.avro.TextGeometry\",\"com.alibaba.dts.formats.avro.BinaryObject\",\"com.alibaba.dts.formats.avro.TextObject\",\"com.alibaba.dts.formats.avro.EmptyObject\"],\"type\":\"array\"}]},{\"default\":0,\"doc\":\"the timestamp in unit of millisecond that record is born in source\",\"name\":\"bornTimestamp\",\"type\":\"long\"}],\"name\":\"com.alibaba.dts.formats.avro.Record\",\"type\":\"record\"}" +} + +func (r *Record) SchemaName() string { + return "com.alibaba.dts.formats.avro.Record" +} + +func (_ *Record) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Record) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Record) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Record) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Record) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Record) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Record) SetString(v string) { panic("Unsupported operation") } +func (_ *Record) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Record) Get(i int) types.Field { + switch i { + case 0: + return &types.Int{Target: &r.Version} + case 1: + return &types.Long{Target: &r.Id} + case 2: + return &types.Long{Target: &r.SourceTimestamp} + case 3: + return &types.String{Target: &r.SourcePosition} + case 4: + return &types.String{Target: &r.SafeSourcePosition} + case 5: + return &types.String{Target: &r.SourceTxid} + case 6: + r.Source = NewSource() + + return r.Source + case 7: + return &OperationWrapper{Target: &r.Operation} + case 8: + r.ObjectName = NewUnionNullString() + + return r.ObjectName + case 9: + r.ProcessTimestamps = NewUnionNullArrayLong() + + return r.ProcessTimestamps + case 10: + r.Tags = make(map[string]string) + + return &MapStringWrapper{Target: &r.Tags} + case 11: + r.Fields = NewUnionNullStringArrayField() + + return r.Fields + case 12: + r.BeforeImages = NewUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject() + + return r.BeforeImages + case 13: + r.AfterImages = NewUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject() + + return r.AfterImages + case 14: + return &types.Long{Target: &r.BornTimestamp} + } + panic("Unknown field index") +} + +func (r *Record) SetDefault(i int) { + switch i { + case 4: + r.SafeSourcePosition = "" + return + case 5: + r.SourceTxid = "" + return + case 8: + r.ObjectName = nil + return + case 9: + r.ProcessTimestamps = nil + return + case 10: + + return + case 11: + r.Fields = nil + return + case 12: + r.BeforeImages = nil + return + case 13: + r.AfterImages = nil + return + case 14: + r.BornTimestamp = 0 + return + } + panic("Unknown field index") +} + +func (r *Record) NullField(i int) { + switch i { + case 8: + r.ObjectName = nil + return + case 9: + r.ProcessTimestamps = nil + return + case 11: + r.Fields = nil + return + case 12: + r.BeforeImages = nil + return + case 13: + r.AfterImages = nil + return + } + panic("Not a nullable field index") +} + +func (_ *Record) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Record) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Record) Finalize() {} + +func (_ *Record) AvroCRC64Fingerprint() []byte { + return []byte(RecordAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/source.go b/goimpl/lib/dtsavro/source.go new file mode 100644 index 0000000..ede11be --- /dev/null +++ b/goimpl/lib/dtsavro/source.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Source struct { + SourceType SourceType `json:"sourceType"` + // source datasource version information + Version string `json:"version"` +} + +const SourceAvroCRC64Fingerprint = "Z\xe3G\xb0O\u007f\xb4z" + +func NewSource() *Source { + return &Source{} +} + +func DeserializeSource(r io.Reader) (*Source, error) { + t := NewSource() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeSourceFromSchema(r io.Reader, schema string) (*Source, error) { + t := NewSource() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeSource(r *Source, w io.Writer) error { + var err error + err = writeSourceType(r.SourceType, w) + if err != nil { + return err + } + err = vm.WriteString(r.Version, w) + if err != nil { + return err + } + return err +} + +func (r *Source) Serialize(w io.Writer) error { + return writeSource(r, w) +} + +func (r *Source) Schema() string { + return "{\"fields\":[{\"name\":\"sourceType\",\"type\":{\"name\":\"SourceType\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"symbols\":[\"MySQL\",\"Oracle\",\"SQLServer\",\"PostgreSQL\",\"MongoDB\",\"Redis\",\"DB2\",\"PPAS\",\"DRDS\",\"HBASE\",\"HDFS\",\"FILE\",\"OTHER\"],\"type\":\"enum\"}},{\"doc\":\"source datasource version information\",\"name\":\"version\",\"type\":\"string\"}],\"name\":\"com.alibaba.dts.formats.avro.Source\",\"type\":\"record\"}" +} + +func (r *Source) SchemaName() string { + return "com.alibaba.dts.formats.avro.Source" +} + +func (_ *Source) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Source) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Source) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Source) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Source) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Source) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Source) SetString(v string) { panic("Unsupported operation") } +func (_ *Source) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Source) Get(i int) types.Field { + switch i { + case 0: + return &SourceTypeWrapper{Target: &r.SourceType} + case 1: + return &types.String{Target: &r.Version} + } + panic("Unknown field index") +} + +func (r *Source) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Source) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Source) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Source) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Source) Finalize() {} + +func (_ *Source) AvroCRC64Fingerprint() []byte { + return []byte(SourceAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/source_type.go b/goimpl/lib/dtsavro/source_type.go new file mode 100644 index 0000000..827e645 --- /dev/null +++ b/goimpl/lib/dtsavro/source_type.go @@ -0,0 +1,175 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type SourceType int32 + +const ( + SourceTypeMySQL SourceType = 0 + SourceTypeOracle SourceType = 1 + SourceTypeSQLServer SourceType = 2 + SourceTypePostgreSQL SourceType = 3 + SourceTypeMongoDB SourceType = 4 + SourceTypeRedis SourceType = 5 + SourceTypeDB2 SourceType = 6 + SourceTypePPAS SourceType = 7 + SourceTypeDRDS SourceType = 8 + SourceTypeHBASE SourceType = 9 + SourceTypeHDFS SourceType = 10 + SourceTypeFILE SourceType = 11 + SourceTypeOTHER SourceType = 12 +) + +func (e SourceType) String() string { + switch e { + case SourceTypeMySQL: + return "MySQL" + case SourceTypeOracle: + return "Oracle" + case SourceTypeSQLServer: + return "SQLServer" + case SourceTypePostgreSQL: + return "PostgreSQL" + case SourceTypeMongoDB: + return "MongoDB" + case SourceTypeRedis: + return "Redis" + case SourceTypeDB2: + return "DB2" + case SourceTypePPAS: + return "PPAS" + case SourceTypeDRDS: + return "DRDS" + case SourceTypeHBASE: + return "HBASE" + case SourceTypeHDFS: + return "HDFS" + case SourceTypeFILE: + return "FILE" + case SourceTypeOTHER: + return "OTHER" + } + return "unknown" +} + +func writeSourceType(r SourceType, w io.Writer) error { + return vm.WriteInt(int32(r), w) +} + +func NewSourceTypeValue(raw string) (r SourceType, err error) { + switch raw { + case "MySQL": + return SourceTypeMySQL, nil + case "Oracle": + return SourceTypeOracle, nil + case "SQLServer": + return SourceTypeSQLServer, nil + case "PostgreSQL": + return SourceTypePostgreSQL, nil + case "MongoDB": + return SourceTypeMongoDB, nil + case "Redis": + return SourceTypeRedis, nil + case "DB2": + return SourceTypeDB2, nil + case "PPAS": + return SourceTypePPAS, nil + case "DRDS": + return SourceTypeDRDS, nil + case "HBASE": + return SourceTypeHBASE, nil + case "HDFS": + return SourceTypeHDFS, nil + case "FILE": + return SourceTypeFILE, nil + case "OTHER": + return SourceTypeOTHER, nil + } + + return -1, fmt.Errorf("invalid value for SourceType: '%s'", raw) +} + +func (b *SourceType) MarshalJSON() ([]byte, error) { + return json.Marshal([]byte(b.String())) +} + +func (b *SourceType) UnmarshalJSON(data []byte) error { + var stringVal string + err := json.Unmarshal(data, &stringVal) + if err != nil { + return err + } + val, err := NewSourceTypeValue(stringVal) + *b = val + return err +} + +type SourceTypeWrapper struct { + Target *SourceType +} + +func (b *SourceTypeWrapper) SetBoolean(v bool) { + panic("Unable to assign boolean to int field") +} + +func (b *SourceTypeWrapper) SetInt(v int32) { + *(b.Target) = SourceType(v) +} + +func (b *SourceTypeWrapper) SetLong(v int64) { + panic("Unable to assign long to int field") +} + +func (b *SourceTypeWrapper) SetFloat(v float32) { + panic("Unable to assign float to int field") +} + +func (b *SourceTypeWrapper) SetUnionElem(v int64) { + panic("Unable to assign union elem to int field") +} + +func (b *SourceTypeWrapper) SetDouble(v float64) { + panic("Unable to assign double to int field") +} + +func (b *SourceTypeWrapper) SetBytes(v []byte) { + panic("Unable to assign bytes to int field") +} + +func (b *SourceTypeWrapper) SetString(v string) { + panic("Unable to assign string to int field") +} + +func (b *SourceTypeWrapper) Get(i int) types.Field { + panic("Unable to get field from int field") +} + +func (b *SourceTypeWrapper) SetDefault(i int) { + panic("Unable to set default on int field") +} + +func (b *SourceTypeWrapper) AppendMap(key string) types.Field { + panic("Unable to append map key to from int field") +} + +func (b *SourceTypeWrapper) AppendArray() types.Field { + panic("Unable to append array element to from int field") +} + +func (b *SourceTypeWrapper) NullField(int) { + panic("Unable to null field in int field") +} + +func (b *SourceTypeWrapper) Finalize() {} diff --git a/goimpl/lib/dtsavro/text_geometry.go b/goimpl/lib/dtsavro/text_geometry.go new file mode 100644 index 0000000..48ff71d --- /dev/null +++ b/goimpl/lib/dtsavro/text_geometry.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type TextGeometry struct { + Type string `json:"type"` + + Value string `json:"value"` +} + +const TextGeometryAvroCRC64Fingerprint = "\xa0e\x94\x95=\xfb\xb2r" + +func NewTextGeometry() *TextGeometry { + return &TextGeometry{} +} + +func DeserializeTextGeometry(r io.Reader) (*TextGeometry, error) { + t := NewTextGeometry() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeTextGeometryFromSchema(r io.Reader, schema string) (*TextGeometry, error) { + t := NewTextGeometry() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeTextGeometry(r *TextGeometry, w io.Writer) error { + var err error + err = vm.WriteString(r.Type, w) + if err != nil { + return err + } + err = vm.WriteString(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *TextGeometry) Serialize(w io.Writer) error { + return writeTextGeometry(r, w) +} + +func (r *TextGeometry) Schema() string { + return "{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"com.alibaba.dts.formats.avro.TextGeometry\",\"type\":\"record\"}" +} + +func (r *TextGeometry) SchemaName() string { + return "com.alibaba.dts.formats.avro.TextGeometry" +} + +func (_ *TextGeometry) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *TextGeometry) SetInt(v int32) { panic("Unsupported operation") } +func (_ *TextGeometry) SetLong(v int64) { panic("Unsupported operation") } +func (_ *TextGeometry) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *TextGeometry) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *TextGeometry) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *TextGeometry) SetString(v string) { panic("Unsupported operation") } +func (_ *TextGeometry) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *TextGeometry) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Type} + case 1: + return &types.String{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *TextGeometry) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *TextGeometry) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *TextGeometry) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *TextGeometry) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *TextGeometry) Finalize() {} + +func (_ *TextGeometry) AvroCRC64Fingerprint() []byte { + return []byte(TextGeometryAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/text_object.go b/goimpl/lib/dtsavro/text_object.go new file mode 100644 index 0000000..0d2ca6c --- /dev/null +++ b/goimpl/lib/dtsavro/text_object.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type TextObject struct { + Type string `json:"type"` + + Value string `json:"value"` +} + +const TextObjectAvroCRC64Fingerprint = "\x84\xe7\f|\xb0m\xb5\xbe" + +func NewTextObject() *TextObject { + return &TextObject{} +} + +func DeserializeTextObject(r io.Reader) (*TextObject, error) { + t := NewTextObject() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeTextObjectFromSchema(r io.Reader, schema string) (*TextObject, error) { + t := NewTextObject() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeTextObject(r *TextObject, w io.Writer) error { + var err error + err = vm.WriteString(r.Type, w) + if err != nil { + return err + } + err = vm.WriteString(r.Value, w) + if err != nil { + return err + } + return err +} + +func (r *TextObject) Serialize(w io.Writer) error { + return writeTextObject(r, w) +} + +func (r *TextObject) Schema() string { + return "{\"fields\":[{\"name\":\"type\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"com.alibaba.dts.formats.avro.TextObject\",\"type\":\"record\"}" +} + +func (r *TextObject) SchemaName() string { + return "com.alibaba.dts.formats.avro.TextObject" +} + +func (_ *TextObject) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *TextObject) SetInt(v int32) { panic("Unsupported operation") } +func (_ *TextObject) SetLong(v int64) { panic("Unsupported operation") } +func (_ *TextObject) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *TextObject) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *TextObject) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *TextObject) SetString(v string) { panic("Unsupported operation") } +func (_ *TextObject) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *TextObject) Get(i int) types.Field { + switch i { + case 0: + return &types.String{Target: &r.Type} + case 1: + return &types.String{Target: &r.Value} + } + panic("Unknown field index") +} + +func (r *TextObject) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *TextObject) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *TextObject) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *TextObject) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *TextObject) Finalize() {} + +func (_ *TextObject) AvroCRC64Fingerprint() []byte { + return []byte(TextObjectAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/timestamp.go b/goimpl/lib/dtsavro/timestamp.go new file mode 100644 index 0000000..a95cabd --- /dev/null +++ b/goimpl/lib/dtsavro/timestamp.go @@ -0,0 +1,118 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type Timestamp struct { + Timestamp int64 `json:"timestamp"` + + Millis int32 `json:"millis"` +} + +const TimestampAvroCRC64Fingerprint = "\x8e\xdd@\fBJ[~" + +func NewTimestamp() *Timestamp { + return &Timestamp{} +} + +func DeserializeTimestamp(r io.Reader) (*Timestamp, error) { + t := NewTimestamp() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeTimestampFromSchema(r io.Reader, schema string) (*Timestamp, error) { + t := NewTimestamp() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeTimestamp(r *Timestamp, w io.Writer) error { + var err error + err = vm.WriteLong(r.Timestamp, w) + if err != nil { + return err + } + err = vm.WriteInt(r.Millis, w) + if err != nil { + return err + } + return err +} + +func (r *Timestamp) Serialize(w io.Writer) error { + return writeTimestamp(r, w) +} + +func (r *Timestamp) Schema() string { + return "{\"fields\":[{\"name\":\"timestamp\",\"type\":\"long\"},{\"name\":\"millis\",\"type\":\"int\"}],\"name\":\"com.alibaba.dts.formats.avro.Timestamp\",\"type\":\"record\"}" +} + +func (r *Timestamp) SchemaName() string { + return "com.alibaba.dts.formats.avro.Timestamp" +} + +func (_ *Timestamp) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *Timestamp) SetInt(v int32) { panic("Unsupported operation") } +func (_ *Timestamp) SetLong(v int64) { panic("Unsupported operation") } +func (_ *Timestamp) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *Timestamp) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *Timestamp) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *Timestamp) SetString(v string) { panic("Unsupported operation") } +func (_ *Timestamp) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *Timestamp) Get(i int) types.Field { + switch i { + case 0: + return &types.Long{Target: &r.Timestamp} + case 1: + return &types.Int{Target: &r.Millis} + } + panic("Unknown field index") +} + +func (r *Timestamp) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *Timestamp) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *Timestamp) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *Timestamp) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *Timestamp) Finalize() {} + +func (_ *Timestamp) AvroCRC64Fingerprint() []byte { + return []byte(TimestampAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/timestamp_with_time_zone.go b/goimpl/lib/dtsavro/timestamp_with_time_zone.go new file mode 100644 index 0000000..f9d3f24 --- /dev/null +++ b/goimpl/lib/dtsavro/timestamp_with_time_zone.go @@ -0,0 +1,120 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "github.com/actgardner/gogen-avro/v7/compiler" + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" + "io" +) + +type TimestampWithTimeZone struct { + Value *DateTime `json:"value"` + + Timezone string `json:"timezone"` +} + +const TimestampWithTimeZoneAvroCRC64Fingerprint = "2T\x1b\x8c=\x01_\xb9" + +func NewTimestampWithTimeZone() *TimestampWithTimeZone { + return &TimestampWithTimeZone{} +} + +func DeserializeTimestampWithTimeZone(r io.Reader) (*TimestampWithTimeZone, error) { + t := NewTimestampWithTimeZone() + deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func DeserializeTimestampWithTimeZoneFromSchema(r io.Reader, schema string) (*TimestampWithTimeZone, error) { + t := NewTimestampWithTimeZone() + + deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema())) + if err != nil { + return nil, err + } + + err = vm.Eval(r, deser, t) + if err != nil { + return nil, err + } + return t, err +} + +func writeTimestampWithTimeZone(r *TimestampWithTimeZone, w io.Writer) error { + var err error + err = writeDateTime(r.Value, w) + if err != nil { + return err + } + err = vm.WriteString(r.Timezone, w) + if err != nil { + return err + } + return err +} + +func (r *TimestampWithTimeZone) Serialize(w io.Writer) error { + return writeTimestampWithTimeZone(r, w) +} + +func (r *TimestampWithTimeZone) Schema() string { + return "{\"fields\":[{\"name\":\"value\",\"type\":{\"fields\":[{\"default\":null,\"name\":\"year\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"month\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"day\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"hour\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"minute\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"second\",\"type\":[\"null\",\"int\"]},{\"default\":null,\"name\":\"millis\",\"type\":[\"null\",\"int\"]}],\"name\":\"DateTime\",\"namespace\":\"com.alibaba.dts.formats.avro\",\"type\":\"record\"}},{\"name\":\"timezone\",\"type\":\"string\"}],\"name\":\"com.alibaba.dts.formats.avro.TimestampWithTimeZone\",\"type\":\"record\"}" +} + +func (r *TimestampWithTimeZone) SchemaName() string { + return "com.alibaba.dts.formats.avro.TimestampWithTimeZone" +} + +func (_ *TimestampWithTimeZone) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetInt(v int32) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetLong(v int64) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetString(v string) { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) SetUnionElem(v int64) { panic("Unsupported operation") } + +func (r *TimestampWithTimeZone) Get(i int) types.Field { + switch i { + case 0: + r.Value = NewDateTime() + + return r.Value + case 1: + return &types.String{Target: &r.Timezone} + } + panic("Unknown field index") +} + +func (r *TimestampWithTimeZone) SetDefault(i int) { + switch i { + } + panic("Unknown field index") +} + +func (r *TimestampWithTimeZone) NullField(i int) { + switch i { + } + panic("Not a nullable field index") +} + +func (_ *TimestampWithTimeZone) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *TimestampWithTimeZone) Finalize() {} + +func (_ *TimestampWithTimeZone) AvroCRC64Fingerprint() []byte { + return []byte(TimestampWithTimeZoneAvroCRC64Fingerprint) +} diff --git a/goimpl/lib/dtsavro/union_field_integer_character_float_decimal_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object_record.go b/goimpl/lib/dtsavro/union_field_integer_character_float_decimal_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object_record.go new file mode 100644 index 0000000..5e4c832 --- /dev/null +++ b/goimpl/lib/dtsavro/union_field_integer_character_float_decimal_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object_record.go @@ -0,0 +1,291 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum int + +const ( + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumField UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 0 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumInteger UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 1 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumCharacter UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 2 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumFloat UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 3 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDecimal UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 4 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestamp UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 5 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDateTime UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 6 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestampWithTimeZone UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 7 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryGeometry UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 8 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextGeometry UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 9 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryObject UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 10 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextObject UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 11 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumEmptyObject UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 12 + + UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumRecord UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum = 13 +) + +type UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord struct { + Field *Field + Integer *Integer + Character *Character + Float *Float + Decimal *Decimal + Timestamp *Timestamp + DateTime *DateTime + TimestampWithTimeZone *TimestampWithTimeZone + BinaryGeometry *BinaryGeometry + TextGeometry *TextGeometry + BinaryObject *BinaryObject + TextObject *TextObject + EmptyObject EmptyObject + Record *Record + UnionType UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum +} + +func writeUnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord(r *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord, w io.Writer) error { + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumField: + return writeField(r.Field, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumInteger: + return writeInteger(r.Integer, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumCharacter: + return writeCharacter(r.Character, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumFloat: + return writeFloat(r.Float, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDecimal: + return writeDecimal(r.Decimal, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestamp: + return writeTimestamp(r.Timestamp, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDateTime: + return writeDateTime(r.DateTime, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestampWithTimeZone: + return writeTimestampWithTimeZone(r.TimestampWithTimeZone, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryGeometry: + return writeBinaryGeometry(r.BinaryGeometry, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextGeometry: + return writeTextGeometry(r.TextGeometry, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryObject: + return writeBinaryObject(r.BinaryObject, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextObject: + return writeTextObject(r.TextObject, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumEmptyObject: + return writeEmptyObject(r.EmptyObject, w) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumRecord: + return writeRecord(r.Record, w) + } + return fmt.Errorf("invalid value for *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord") +} + +func NewUnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord() *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord { + return &UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord{} +} + +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetBoolean(v bool) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetInt(v int32) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetFloat(v float32) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetDouble(v float64) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetBytes(v []byte) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetString(v string) { + panic("Unsupported operation") +} +func (r *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetLong(v int64) { + r.UnionType = (UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnum)(v) +} +func (r *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) Get(i int) types.Field { + switch i { + case 0: + r.Field = NewField() + return r.Field + case 1: + r.Integer = NewInteger() + return r.Integer + case 2: + r.Character = NewCharacter() + return r.Character + case 3: + r.Float = NewFloat() + return r.Float + case 4: + r.Decimal = NewDecimal() + return r.Decimal + case 5: + r.Timestamp = NewTimestamp() + return r.Timestamp + case 6: + r.DateTime = NewDateTime() + return r.DateTime + case 7: + r.TimestampWithTimeZone = NewTimestampWithTimeZone() + return r.TimestampWithTimeZone + case 8: + r.BinaryGeometry = NewBinaryGeometry() + return r.BinaryGeometry + case 9: + r.TextGeometry = NewTextGeometry() + return r.TextGeometry + case 10: + r.BinaryObject = NewBinaryObject() + return r.BinaryObject + case 11: + r.TextObject = NewTextObject() + return r.TextObject + case 12: + return &EmptyObjectWrapper{Target: (&r.EmptyObject)} + case 13: + r.Record = NewRecord() + return r.Record + } + panic("Unknown field index") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) NullField(i int) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) SetDefault(i int) { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) AppendMap(key string) types.Field { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) AppendArray() types.Field { + panic("Unsupported operation") +} +func (_ *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) Finalize() { +} + +func (r *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumField: + return json.Marshal(map[string]interface{}{"Field": r.Field}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumInteger: + return json.Marshal(map[string]interface{}{"Integer": r.Integer}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumCharacter: + return json.Marshal(map[string]interface{}{"Character": r.Character}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumFloat: + return json.Marshal(map[string]interface{}{"Float": r.Float}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDecimal: + return json.Marshal(map[string]interface{}{"Decimal": r.Decimal}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestamp: + return json.Marshal(map[string]interface{}{"Timestamp": r.Timestamp}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumDateTime: + return json.Marshal(map[string]interface{}{"DateTime": r.DateTime}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTimestampWithTimeZone: + return json.Marshal(map[string]interface{}{"TimestampWithTimeZone": r.TimestampWithTimeZone}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryGeometry: + return json.Marshal(map[string]interface{}{"BinaryGeometry": r.BinaryGeometry}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextGeometry: + return json.Marshal(map[string]interface{}{"TextGeometry": r.TextGeometry}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumBinaryObject: + return json.Marshal(map[string]interface{}{"BinaryObject": r.BinaryObject}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumTextObject: + return json.Marshal(map[string]interface{}{"TextObject": r.TextObject}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumEmptyObject: + return json.Marshal(map[string]interface{}{"EmptyObject": r.EmptyObject}) + case UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecordTypeEnumRecord: + return json.Marshal(map[string]interface{}{"Record": r.Record}) + } + return nil, fmt.Errorf("invalid value for *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord") +} + +func (r *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["Field"]; ok { + r.UnionType = 0 + return json.Unmarshal([]byte(value), &r.Field) + } + if value, ok := fields["Integer"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.Integer) + } + if value, ok := fields["Character"]; ok { + r.UnionType = 2 + return json.Unmarshal([]byte(value), &r.Character) + } + if value, ok := fields["Float"]; ok { + r.UnionType = 3 + return json.Unmarshal([]byte(value), &r.Float) + } + if value, ok := fields["Decimal"]; ok { + r.UnionType = 4 + return json.Unmarshal([]byte(value), &r.Decimal) + } + if value, ok := fields["Timestamp"]; ok { + r.UnionType = 5 + return json.Unmarshal([]byte(value), &r.Timestamp) + } + if value, ok := fields["DateTime"]; ok { + r.UnionType = 6 + return json.Unmarshal([]byte(value), &r.DateTime) + } + if value, ok := fields["TimestampWithTimeZone"]; ok { + r.UnionType = 7 + return json.Unmarshal([]byte(value), &r.TimestampWithTimeZone) + } + if value, ok := fields["BinaryGeometry"]; ok { + r.UnionType = 8 + return json.Unmarshal([]byte(value), &r.BinaryGeometry) + } + if value, ok := fields["TextGeometry"]; ok { + r.UnionType = 9 + return json.Unmarshal([]byte(value), &r.TextGeometry) + } + if value, ok := fields["BinaryObject"]; ok { + r.UnionType = 10 + return json.Unmarshal([]byte(value), &r.BinaryObject) + } + if value, ok := fields["TextObject"]; ok { + r.UnionType = 11 + return json.Unmarshal([]byte(value), &r.TextObject) + } + if value, ok := fields["EmptyObject"]; ok { + r.UnionType = 12 + return json.Unmarshal([]byte(value), &r.EmptyObject) + } + if value, ok := fields["Record"]; ok { + r.UnionType = 13 + return json.Unmarshal([]byte(value), &r.Record) + } + return fmt.Errorf("invalid value for *UnionFieldIntegerCharacterFloatDecimalTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectRecord") +} diff --git a/goimpl/lib/dtsavro/union_null_array_long.go b/goimpl/lib/dtsavro/union_null_array_long.go new file mode 100644 index 0000000..c38c713 --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_array_long.go @@ -0,0 +1,97 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullArrayLongTypeEnum int + +const ( + UnionNullArrayLongTypeEnumArrayLong UnionNullArrayLongTypeEnum = 1 +) + +type UnionNullArrayLong struct { + Null *types.NullVal + ArrayLong []int64 + UnionType UnionNullArrayLongTypeEnum +} + +func writeUnionNullArrayLong(r *UnionNullArrayLong, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullArrayLongTypeEnumArrayLong: + return writeArrayLong(r.ArrayLong, w) + } + return fmt.Errorf("invalid value for *UnionNullArrayLong") +} + +func NewUnionNullArrayLong() *UnionNullArrayLong { + return &UnionNullArrayLong{} +} + +func (_ *UnionNullArrayLong) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetInt(v int32) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetString(v string) { panic("Unsupported operation") } +func (r *UnionNullArrayLong) SetLong(v int64) { + r.UnionType = (UnionNullArrayLongTypeEnum)(v) +} +func (r *UnionNullArrayLong) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + r.ArrayLong = make([]int64, 0) + return &ArrayLongWrapper{Target: (&r.ArrayLong)} + } + panic("Unknown field index") +} +func (_ *UnionNullArrayLong) NullField(i int) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) SetDefault(i int) { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *UnionNullArrayLong) Finalize() {} + +func (r *UnionNullArrayLong) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullArrayLongTypeEnumArrayLong: + return json.Marshal(map[string]interface{}{"array": r.ArrayLong}) + } + return nil, fmt.Errorf("invalid value for *UnionNullArrayLong") +} + +func (r *UnionNullArrayLong) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["array"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.ArrayLong) + } + return fmt.Errorf("invalid value for *UnionNullArrayLong") +} diff --git a/goimpl/lib/dtsavro/union_null_int.go b/goimpl/lib/dtsavro/union_null_int.go new file mode 100644 index 0000000..e356085 --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_int.go @@ -0,0 +1,96 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullIntTypeEnum int + +const ( + UnionNullIntTypeEnumInt UnionNullIntTypeEnum = 1 +) + +type UnionNullInt struct { + Null *types.NullVal + Int int32 + UnionType UnionNullIntTypeEnum +} + +func writeUnionNullInt(r *UnionNullInt, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullIntTypeEnumInt: + return vm.WriteInt(r.Int, w) + } + return fmt.Errorf("invalid value for *UnionNullInt") +} + +func NewUnionNullInt() *UnionNullInt { + return &UnionNullInt{} +} + +func (_ *UnionNullInt) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetInt(v int32) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetString(v string) { panic("Unsupported operation") } +func (r *UnionNullInt) SetLong(v int64) { + r.UnionType = (UnionNullIntTypeEnum)(v) +} +func (r *UnionNullInt) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + return &types.Int{Target: (&r.Int)} + } + panic("Unknown field index") +} +func (_ *UnionNullInt) NullField(i int) { panic("Unsupported operation") } +func (_ *UnionNullInt) SetDefault(i int) { panic("Unsupported operation") } +func (_ *UnionNullInt) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *UnionNullInt) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *UnionNullInt) Finalize() {} + +func (r *UnionNullInt) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullIntTypeEnumInt: + return json.Marshal(map[string]interface{}{"int": r.Int}) + } + return nil, fmt.Errorf("invalid value for *UnionNullInt") +} + +func (r *UnionNullInt) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["int"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.Int) + } + return fmt.Errorf("invalid value for *UnionNullInt") +} diff --git a/goimpl/lib/dtsavro/union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go b/goimpl/lib/dtsavro/union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go new file mode 100644 index 0000000..c5d06ce --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go @@ -0,0 +1,271 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum int + +const ( + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumInteger UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 1 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumCharacter UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 2 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDecimal UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 3 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumFloat UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 4 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestamp UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 5 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDateTime UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 6 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestampWithTimeZone UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 7 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryGeometry UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 8 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextGeometry UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 9 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryObject UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 10 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextObject UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 11 + + UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumEmptyObject UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 12 +) + +type UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject struct { + Null *types.NullVal + Integer *Integer + Character *Character + Decimal *Decimal + Float *Float + Timestamp *Timestamp + DateTime *DateTime + TimestampWithTimeZone *TimestampWithTimeZone + BinaryGeometry *BinaryGeometry + TextGeometry *TextGeometry + BinaryObject *BinaryObject + TextObject *TextObject + EmptyObject EmptyObject + UnionType UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum +} + +func writeUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumInteger: + return writeInteger(r.Integer, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumCharacter: + return writeCharacter(r.Character, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDecimal: + return writeDecimal(r.Decimal, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumFloat: + return writeFloat(r.Float, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestamp: + return writeTimestamp(r.Timestamp, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDateTime: + return writeDateTime(r.DateTime, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestampWithTimeZone: + return writeTimestampWithTimeZone(r.TimestampWithTimeZone, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryGeometry: + return writeBinaryGeometry(r.BinaryGeometry, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextGeometry: + return writeTextGeometry(r.TextGeometry, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryObject: + return writeBinaryObject(r.BinaryObject, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextObject: + return writeTextObject(r.TextObject, w) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumEmptyObject: + return writeEmptyObject(r.EmptyObject, w) + } + return fmt.Errorf("invalid value for *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} + +func NewUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject() *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject { + return &UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject{} +} + +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetBoolean(v bool) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetInt(v int32) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetFloat(v float32) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetDouble(v float64) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetBytes(v []byte) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetString(v string) { + panic("Unsupported operation") +} +func (r *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetLong(v int64) { + r.UnionType = (UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum)(v) +} +func (r *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + r.Integer = NewInteger() + return r.Integer + case 2: + r.Character = NewCharacter() + return r.Character + case 3: + r.Decimal = NewDecimal() + return r.Decimal + case 4: + r.Float = NewFloat() + return r.Float + case 5: + r.Timestamp = NewTimestamp() + return r.Timestamp + case 6: + r.DateTime = NewDateTime() + return r.DateTime + case 7: + r.TimestampWithTimeZone = NewTimestampWithTimeZone() + return r.TimestampWithTimeZone + case 8: + r.BinaryGeometry = NewBinaryGeometry() + return r.BinaryGeometry + case 9: + r.TextGeometry = NewTextGeometry() + return r.TextGeometry + case 10: + r.BinaryObject = NewBinaryObject() + return r.BinaryObject + case 11: + r.TextObject = NewTextObject() + return r.TextObject + case 12: + return &EmptyObjectWrapper{Target: (&r.EmptyObject)} + } + panic("Unknown field index") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) NullField(i int) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetDefault(i int) { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) AppendMap(key string) types.Field { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) AppendArray() types.Field { + panic("Unsupported operation") +} +func (_ *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) Finalize() { +} + +func (r *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumInteger: + return json.Marshal(map[string]interface{}{"Integer": r.Integer}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumCharacter: + return json.Marshal(map[string]interface{}{"Character": r.Character}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDecimal: + return json.Marshal(map[string]interface{}{"Decimal": r.Decimal}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumFloat: + return json.Marshal(map[string]interface{}{"Float": r.Float}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestamp: + return json.Marshal(map[string]interface{}{"Timestamp": r.Timestamp}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumDateTime: + return json.Marshal(map[string]interface{}{"DateTime": r.DateTime}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTimestampWithTimeZone: + return json.Marshal(map[string]interface{}{"TimestampWithTimeZone": r.TimestampWithTimeZone}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryGeometry: + return json.Marshal(map[string]interface{}{"BinaryGeometry": r.BinaryGeometry}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextGeometry: + return json.Marshal(map[string]interface{}{"TextGeometry": r.TextGeometry}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumBinaryObject: + return json.Marshal(map[string]interface{}{"BinaryObject": r.BinaryObject}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumTextObject: + return json.Marshal(map[string]interface{}{"TextObject": r.TextObject}) + case UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumEmptyObject: + return json.Marshal(map[string]interface{}{"EmptyObject": r.EmptyObject}) + } + return nil, fmt.Errorf("invalid value for *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} + +func (r *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["Integer"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.Integer) + } + if value, ok := fields["Character"]; ok { + r.UnionType = 2 + return json.Unmarshal([]byte(value), &r.Character) + } + if value, ok := fields["Decimal"]; ok { + r.UnionType = 3 + return json.Unmarshal([]byte(value), &r.Decimal) + } + if value, ok := fields["Float"]; ok { + r.UnionType = 4 + return json.Unmarshal([]byte(value), &r.Float) + } + if value, ok := fields["Timestamp"]; ok { + r.UnionType = 5 + return json.Unmarshal([]byte(value), &r.Timestamp) + } + if value, ok := fields["DateTime"]; ok { + r.UnionType = 6 + return json.Unmarshal([]byte(value), &r.DateTime) + } + if value, ok := fields["TimestampWithTimeZone"]; ok { + r.UnionType = 7 + return json.Unmarshal([]byte(value), &r.TimestampWithTimeZone) + } + if value, ok := fields["BinaryGeometry"]; ok { + r.UnionType = 8 + return json.Unmarshal([]byte(value), &r.BinaryGeometry) + } + if value, ok := fields["TextGeometry"]; ok { + r.UnionType = 9 + return json.Unmarshal([]byte(value), &r.TextGeometry) + } + if value, ok := fields["BinaryObject"]; ok { + r.UnionType = 10 + return json.Unmarshal([]byte(value), &r.BinaryObject) + } + if value, ok := fields["TextObject"]; ok { + r.UnionType = 11 + return json.Unmarshal([]byte(value), &r.TextObject) + } + if value, ok := fields["EmptyObject"]; ok { + r.UnionType = 12 + return json.Unmarshal([]byte(value), &r.EmptyObject) + } + return fmt.Errorf("invalid value for *UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} diff --git a/goimpl/lib/dtsavro/union_null_string.go b/goimpl/lib/dtsavro/union_null_string.go new file mode 100644 index 0000000..b0aab66 --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_string.go @@ -0,0 +1,96 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullStringTypeEnum int + +const ( + UnionNullStringTypeEnumString UnionNullStringTypeEnum = 1 +) + +type UnionNullString struct { + Null *types.NullVal + String string + UnionType UnionNullStringTypeEnum +} + +func writeUnionNullString(r *UnionNullString, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullStringTypeEnumString: + return vm.WriteString(r.String, w) + } + return fmt.Errorf("invalid value for *UnionNullString") +} + +func NewUnionNullString() *UnionNullString { + return &UnionNullString{} +} + +func (_ *UnionNullString) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *UnionNullString) SetInt(v int32) { panic("Unsupported operation") } +func (_ *UnionNullString) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *UnionNullString) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *UnionNullString) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *UnionNullString) SetString(v string) { panic("Unsupported operation") } +func (r *UnionNullString) SetLong(v int64) { + r.UnionType = (UnionNullStringTypeEnum)(v) +} +func (r *UnionNullString) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + return &types.String{Target: (&r.String)} + } + panic("Unknown field index") +} +func (_ *UnionNullString) NullField(i int) { panic("Unsupported operation") } +func (_ *UnionNullString) SetDefault(i int) { panic("Unsupported operation") } +func (_ *UnionNullString) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *UnionNullString) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *UnionNullString) Finalize() {} + +func (r *UnionNullString) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullStringTypeEnumString: + return json.Marshal(map[string]interface{}{"string": r.String}) + } + return nil, fmt.Errorf("invalid value for *UnionNullString") +} + +func (r *UnionNullString) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["string"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.String) + } + return fmt.Errorf("invalid value for *UnionNullString") +} diff --git a/goimpl/lib/dtsavro/union_null_string_array_field.go b/goimpl/lib/dtsavro/union_null_string_array_field.go new file mode 100644 index 0000000..9efd485 --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_string_array_field.go @@ -0,0 +1,110 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullStringArrayFieldTypeEnum int + +const ( + UnionNullStringArrayFieldTypeEnumString UnionNullStringArrayFieldTypeEnum = 1 + + UnionNullStringArrayFieldTypeEnumArrayField UnionNullStringArrayFieldTypeEnum = 2 +) + +type UnionNullStringArrayField struct { + Null *types.NullVal + String string + ArrayField []*Field + UnionType UnionNullStringArrayFieldTypeEnum +} + +func writeUnionNullStringArrayField(r *UnionNullStringArrayField, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullStringArrayFieldTypeEnumString: + return vm.WriteString(r.String, w) + case UnionNullStringArrayFieldTypeEnumArrayField: + return writeArrayField(r.ArrayField, w) + } + return fmt.Errorf("invalid value for *UnionNullStringArrayField") +} + +func NewUnionNullStringArrayField() *UnionNullStringArrayField { + return &UnionNullStringArrayField{} +} + +func (_ *UnionNullStringArrayField) SetBoolean(v bool) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetInt(v int32) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetFloat(v float32) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetDouble(v float64) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetBytes(v []byte) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetString(v string) { panic("Unsupported operation") } +func (r *UnionNullStringArrayField) SetLong(v int64) { + r.UnionType = (UnionNullStringArrayFieldTypeEnum)(v) +} +func (r *UnionNullStringArrayField) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + return &types.String{Target: (&r.String)} + case 2: + r.ArrayField = make([]*Field, 0) + return &ArrayFieldWrapper{Target: (&r.ArrayField)} + } + panic("Unknown field index") +} +func (_ *UnionNullStringArrayField) NullField(i int) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) SetDefault(i int) { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) AppendMap(key string) types.Field { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) AppendArray() types.Field { panic("Unsupported operation") } +func (_ *UnionNullStringArrayField) Finalize() {} + +func (r *UnionNullStringArrayField) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullStringArrayFieldTypeEnumString: + return json.Marshal(map[string]interface{}{"string": r.String}) + case UnionNullStringArrayFieldTypeEnumArrayField: + return json.Marshal(map[string]interface{}{"array": r.ArrayField}) + } + return nil, fmt.Errorf("invalid value for *UnionNullStringArrayField") +} + +func (r *UnionNullStringArrayField) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["string"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.String) + } + if value, ok := fields["array"]; ok { + r.UnionType = 2 + return json.Unmarshal([]byte(value), &r.ArrayField) + } + return fmt.Errorf("invalid value for *UnionNullStringArrayField") +} diff --git a/goimpl/lib/dtsavro/union_null_string_array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go b/goimpl/lib/dtsavro/union_null_string_array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go new file mode 100644 index 0000000..41d1a0e --- /dev/null +++ b/goimpl/lib/dtsavro/union_null_string_array_union_null_integer_character_decimal_float_timestamp_date_time_timestamp_with_time_zone_binary_geometry_text_geometry_binary_object_text_object_empty_object.go @@ -0,0 +1,131 @@ +// Code generated by github.com/actgardner/gogen-avro/v7. DO NOT EDIT. +/* + * SOURCE: + * record.avsc + */ +package dtsavro + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/actgardner/gogen-avro/v7/vm" + "github.com/actgardner/gogen-avro/v7/vm/types" +) + +type UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum int + +const ( + UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumString UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 1 + + UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum = 2 +) + +type UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject struct { + Null *types.NullVal + String string + ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject []*UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject + UnionType UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum +} + +func writeUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject, w io.Writer) error { + + if r == nil { + err := vm.WriteLong(0, w) + return err + } + + err := vm.WriteLong(int64(r.UnionType), w) + if err != nil { + return err + } + switch r.UnionType { + case UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumString: + return vm.WriteString(r.String, w) + case UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject: + return writeArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject(r.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject, w) + } + return fmt.Errorf("invalid value for *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} + +func NewUnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject() *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject { + return &UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject{} +} + +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetBoolean(v bool) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetInt(v int32) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetFloat(v float32) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetDouble(v float64) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetBytes(v []byte) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetString(v string) { + panic("Unsupported operation") +} +func (r *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetLong(v int64) { + r.UnionType = (UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnum)(v) +} +func (r *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) Get(i int) types.Field { + switch i { + case 0: + return r.Null + case 1: + return &types.String{Target: (&r.String)} + case 2: + r.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject = make([]*UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject, 0) + return &ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectWrapper{Target: (&r.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject)} + } + panic("Unknown field index") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) NullField(i int) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) SetDefault(i int) { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) AppendMap(key string) types.Field { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) AppendArray() types.Field { + panic("Unsupported operation") +} +func (_ *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) Finalize() { +} + +func (r *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) MarshalJSON() ([]byte, error) { + if r == nil { + return []byte("null"), nil + } + switch r.UnionType { + case UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumString: + return json.Marshal(map[string]interface{}{"string": r.String}) + case UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObjectTypeEnumArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject: + return json.Marshal(map[string]interface{}{"array": r.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject}) + } + return nil, fmt.Errorf("invalid value for *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} + +func (r *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) UnmarshalJSON(data []byte) error { + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil { + return err + } + if value, ok := fields["string"]; ok { + r.UnionType = 1 + return json.Unmarshal([]byte(value), &r.String) + } + if value, ok := fields["array"]; ok { + r.UnionType = 2 + return json.Unmarshal([]byte(value), &r.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) + } + return fmt.Errorf("invalid value for *UnionNullStringArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject") +} diff --git a/goimpl/lib/img/1.png b/goimpl/lib/img/1.png new file mode 100644 index 0000000..3895d86 Binary files /dev/null and b/goimpl/lib/img/1.png differ diff --git a/goimpl/lib/kfkdts/config.go b/goimpl/lib/kfkdts/config.go new file mode 100644 index 0000000..142bf67 --- /dev/null +++ b/goimpl/lib/kfkdts/config.go @@ -0,0 +1,24 @@ +package kfkdts + +// Config ... +type Config struct { + IsAliyunDTS bool + User string + Passwd string + Hosts []string + Topic string + GroupID string + Partition int32 + Offset int64 // -1:OffsetNewest -2:OffsetOldest +} + +// NewConfig ... +//func NewConfig() (config *Config, err error) { +// var cfg struct { +// Client *Config +// } +// if err = toml.DecodeFile("kafka.toml", &cfg); err != nil { +// return nil, err +// } +// return cfg.Client, nil +//} diff --git a/goimpl/lib/kfkdts/consumer.go b/goimpl/lib/kfkdts/consumer.go new file mode 100644 index 0000000..fa9e40b --- /dev/null +++ b/goimpl/lib/kfkdts/consumer.go @@ -0,0 +1,96 @@ +package kfkdts + +import ( + "time" + + "github.com/LioRoger/subscribe_example/goimpl/lib/dtsavro" +) + +// Consumer 消费者接口 +type Consumer interface { + Consume() <-chan *Message + Close() error + Error() <-chan error +} + +// NewConsumer ... +func NewConsumer(config *Config) (Consumer, error) { + if config.IsAliyunDTS { + return NewDts(config) + } + return NewKfk(config) +} + +// Message 消息定义 +// 阿里云DTS或Kafka过来的消息统一解析成Message +type Message struct { + Type dtsavro.Operation + Offset int64 + Timestamp time.Time + Event *Event +} + +// Event 事件消息结构 +// 示例: +//{ +// "data": [ +// { +// "id": "47", +// "created_at": "2020-07-14 13:09:19", +// "updated_at": null, +// "deleted_at": null, +// "type_id": "2", +// "subscribed": "1", +// "test_user_id": "2" +// } +// ], +// "database": "test", +// "es": 1596102215000, +// "id": 3, +// "isDdl": false, +// "mysqlType": { +// "id": "int(10) unsigned", +// "created_at": "datetime", +// "updated_at": "datetime", +// "deleted_at": "datetime", +// "type_id": "int(11)", +// "subscribed": "tinyint(1)", +// "test_user_id": "int(11)" +// }, +// "old": [ +// { +// "subscribed": null +// } +// ], +// "pkNames": [ +// "id" +// ], +// "sql": "", +// "sqlType": { +// "id": 4, +// "created_at": 93, +// "updated_at": 93, +// "deleted_at": 93, +// "type_id": 4, +// "subscribed": -7, +// "test_user_id": 4 +// }, +// "table": "test_emails", +// "ts": 1596102215214, +// "type": "UPDATE" +//} +type Event struct { + Type string `json:"type"` + Database string `json:"database"` + Table string `json:"table"` + Data []map[string]string `json:"data"` + Old []map[string]string `json:"old"` + //Es int64 `json:"es"` + //ID int `json:"id"` + //IsDdl bool `json:"isDdl"` + //MysqlType map[string]string `json:"mysqlType"` + //PkNames []string `json:"pkNames"` + //SQL string `json:"sql"` + //SQLType map[string]int32 `json:"sqlType"` + //Ts int64 `json:"ts"` +} diff --git a/goimpl/lib/kfkdts/consumer_test.go b/goimpl/lib/kfkdts/consumer_test.go new file mode 100644 index 0000000..88f29dc --- /dev/null +++ b/goimpl/lib/kfkdts/consumer_test.go @@ -0,0 +1,74 @@ +package kfkdts + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestKfk(t *testing.T) { + config := &Config{ + IsAliyunDTS: false, + User: "", + Passwd: "", + Hosts: []string{"127.0.0.1:9092"}, + Topic: "topic", + GroupID: "", + Partition: 0, + Offset: -2, // -1:OffsetNewest -2:OffsetOldest + } + consumer, err := NewConsumer(config) + if err != nil { + assert.Equal(t, err, nil) + } + for { + select { + case msg := <-consumer.Consume(): + fmt.Printf("recv msg type[%s] timestamp[%s] offset[%d] database[%s] table[[%s]", + msg.Type.String(), msg.Timestamp.String(), msg.Offset, msg.Event.Database, msg.Event.Table) + if msg.Event.Database == "test" && msg.Event.Table == "test_emails" { + for _, data := range msg.Event.Data { + for k, v := range data { + fmt.Printf("colomn[%s,%s]", k, v) + } + } + } + case err := <-consumer.Error(): + break + } + } + consumer.Close() +} + +func TestDts(t *testing.T) { + config := &Config{ + IsAliyunDTS: true, + User: "username", + Passwd: "passwd", + Hosts: []string{"brokerUrl:port"}, + Topic: "topicName", + GroupID: "groupid", + Partition: 0, + Offset: -2, // -1:OffsetNewest -2:OffsetOldest + } + consumer, err := NewConsumer(config) + if err != nil { + assert.Equal(t, err, nil) + } + for { + select { + case msg := <-consumer.Consume(): + fmt.Printf("recv msg type[%s] timestamp[%s] offset[%d] database[%s] table[[%s]", + msg.Type.String(), msg.Timestamp.String(), msg.Offset, msg.Event.Database, msg.Event.Table) + for _, data := range msg.Event.Data { + for k, v := range data { + fmt.Printf("colomn[%s,%s]", k, v) + } + } + case err := <-consumer.Error(): + break + } + } + consumer.Close() +} diff --git a/goimpl/lib/kfkdts/data_type_number.go b/goimpl/lib/kfkdts/data_type_number.go new file mode 100644 index 0000000..45178ad --- /dev/null +++ b/goimpl/lib/kfkdts/data_type_number.go @@ -0,0 +1,118 @@ +package kfkdts + +import ( + "fmt" +) + +// 定义参考: https://www.alibabacloud.com/help/zh/doc-detail/121239.html +const ( + MysqlTypeDecimal = 0 + MysqlTypeInt8 = 1 + MysqlTypeInt16 = 2 + MysqlTypeInt32 = 3 + MysqlTypeFloat = 4 + MysqlTypeDouble = 5 + MysqlTypeNull = 6 + MysqlTypeTimestamp = 7 + MysqlTypeInt64 = 8 + MysqlTypeInt24 = 9 + MysqlTypeDate = 10 + MysqlTypeTime = 11 + MysqlTypeDatetime = 12 + MysqlTypeYear = 13 + MysqlTypeDateNew = 14 + MysqlTypeVarchar = 15 + MysqlTypeBit = 16 + MysqlTypeTimestampNew = 17 + MysqlTypeDatetimeNew = 18 + MysqlTypeTimeNew = 19 + MysqlTypeJSON = 245 + MysqlTypeDecimalNew = 246 + MysqlTypeEnum = 247 + MysqlTypeSet = 248 + MysqlTypeTinyBlob = 249 + MysqlTypeMediumBlob = 250 + MysqlTypeLongBlob = 251 + MysqlTypeBlob = 252 + MysqlTypeVarString = 253 + MysqlTypeString = 254 + MysqlTypeGeometry = 255 +) + +// GetSqlValue ... +// 目前没有全部解析,需要拿到全部样式后完成 2020/08/12 +func GetSqlValue(mysqlType int, data map[string]map[string]interface{}) string { + for _, value := range data { + switch mysqlType { + case MysqlTypeDecimal: + // dtsavro.Decimal + return value["value"].(string) + case MysqlTypeInt8: + fallthrough + case MysqlTypeInt16: + fallthrough + case MysqlTypeInt24: + fallthrough + case MysqlTypeInt32: + fallthrough + case MysqlTypeInt64: + //dtsavro.Integer + return value["value"].(string) + case MysqlTypeFloat: + fallthrough + case MysqlTypeDouble: + // dtsavro.Float + return fmt.Sprintf("%f", value["value"].(float64)) + case MysqlTypeNull: + return "" + case MysqlTypeTimestamp: + // dtsavro.Timestamp + return fmt.Sprintf("%d", value["timestamp"].(int64)) + case MysqlTypeDate: + case MysqlTypeTime: + case MysqlTypeDatetime: + case MysqlTypeYear: + case MysqlTypeDateNew: + case MysqlTypeVarchar: + case MysqlTypeBit: + case MysqlTypeTimestampNew: + case MysqlTypeDatetimeNew: + case MysqlTypeTimeNew: + case MysqlTypeJSON: + // dtsavro.TextObject + return value["value"].(string) + case MysqlTypeDecimalNew: + // dtsavro.Decimal + return value["value"].(string) + case MysqlTypeEnum: + case MysqlTypeSet: + case MysqlTypeTinyBlob: + fallthrough + case MysqlTypeMediumBlob: + fallthrough + case MysqlTypeLongBlob: + fallthrough + case MysqlTypeBlob: + fallthrough + case MysqlTypeVarString: + // dtsavro.Character + return B2S(value["value"].([]uint8)) + case MysqlTypeString: + // dtsavro.Character + return B2S(value["value"].([]uint8)) + case MysqlTypeGeometry: + // dtsavro.TextEgometry + return value["value"].(string) + default: + } + } + return "" +} + +func B2S(bs []uint8) string { + ba := []byte{} + for _, b := range bs { + ba = append(ba, byte(b)) + } + return string(ba) +} diff --git a/goimpl/lib/kfkdts/dts.go b/goimpl/lib/kfkdts/dts.go new file mode 100644 index 0000000..88cb7de --- /dev/null +++ b/goimpl/lib/kfkdts/dts.go @@ -0,0 +1,122 @@ +package kfkdts + +import ( + "time" + + "github.com/Shopify/sarama" + cluster "github.com/bsm/sarama-cluster" +) + +var _ Consumer = &Dts{} + +// Dts 阿里云DTS客户端 +type Dts struct { + config *Config + closer chan struct{} + MsgChan chan *Message + ErrChan chan error + Consumer *cluster.Consumer +} + +// NewDts ... +func NewDts(config *Config) (*Dts, error) { + clusterConfig := ClusterConfig(config) + consumer, err := cluster.NewConsumer(config.Hosts, config.GroupID, []string{config.Topic}, clusterConfig) + if err != nil { + return nil, err + } + dts := &Dts{ + config: config, + Consumer: consumer, + closer: make(chan struct{}), + MsgChan: make(chan *Message), + ErrChan: make(chan error), + } + go DtsError(dts) + go DtsNotify(dts) + go DtsHandler(dts) + return dts, nil +} + +// ClusterConfig ... +func ClusterConfig(config *Config) *cluster.Config { + cc := cluster.NewConfig() + cc.Consumer.Return.Errors = true + cc.Group.Return.Notifications = true + cc.Net.MaxOpenRequests = 100 + cc.Consumer.Offsets.CommitInterval = 1 * time.Second + cc.Consumer.Offsets.Initial = config.Offset + cc.Net.SASL.Enable = true + cc.Net.SASL.User = config.User + "-" + config.GroupID + cc.Net.SASL.Password = config.Passwd + cc.Version = sarama.V0_11_0_0 + return cc +} + +// DtsError ... +func DtsError(dts *Dts) { + for { + select { + case err := <-dts.Consumer.Errors(): + dts.ErrChan <- err + case <-dts.closer: + return + } + } +} + +// DtsNotify ... +func DtsNotify(dts *Dts) { + for { + select { + case ntf := <-dts.Consumer.Notifications(): + case <-dts.closer: + return + } + } +} + +// DtsHandler ... +func DtsHandler(dts *Dts) { + for { + select { + case msg, ok := <-dts.Consumer.Messages(): + if ok { + dts.DispatchMessage(msg) + } + case <-dts.closer: + return + } + } +} + +// DispatchMessage ... +func (d *Dts) DispatchMessage(msg *sarama.ConsumerMessage) { + newMsg := &Message{ + Timestamp: msg.Timestamp, + Offset: msg.Offset, + } + err := DtsDecode(msg.Value, newMsg) + if err != nil { + return + } + d.MsgChan <- newMsg +} + +// Consume ... +func (d *Dts) Consume() <-chan *Message { + return d.MsgChan +} + +// Error ... +func (d *Dts) Error() <-chan error { + return d.ErrChan +} + +func (d *Dts) Close() error { + close(d.closer) + close(d.MsgChan) + close(d.ErrChan) + d.Consumer.Close() + return nil +} diff --git a/goimpl/lib/kfkdts/dts_decode.go b/goimpl/lib/kfkdts/dts_decode.go new file mode 100644 index 0000000..82b9c26 --- /dev/null +++ b/goimpl/lib/kfkdts/dts_decode.go @@ -0,0 +1,113 @@ +package kfkdts + +import ( + "bytes" + "errors" + "strings" + + "github.com/LioRoger/subscribe_example/goimpl/lib/dtsavro" + "github.com/linkedin/goavro" + "github.com/mitchellh/mapstructure" +) + +func DtsDecode(value []byte, message *Message) error { + if message.Event == nil { + message.Event = &Event{ + Data: make([]map[string]string, 0), + } + } + r := bytes.NewReader(value) + t, err := dtsavro.DeserializeRecord(r) + if err != nil { + return err + } + message.Type = t.Operation + if message.Type != dtsavro.OperationINSERT && + message.Type != dtsavro.OperationUPDATE && + message.Type != dtsavro.OperationDELETE { + return errors.New("type [" + t.Operation.String() + "] not supported") + } + if err = getTableName(t.ObjectName.String, message); err != nil { + return err + } + codec, err := goavro.NewCodec(t.Schema()) + if err != nil { + return err + } + native, _, err := codec.NativeFromBinary(value) + if err != nil { + return err + } + record := &Record{} + if err := mapstructure.Decode(native, record); err != nil { + return err + } + afterData := make([]map[string]string, 0) + beforeData := make([]map[string]string, 0) + afterColomns := make(map[string]string) + beforeColomns := make(map[string]string) + // 解析表的每列 + for i, v := range record.Fields.Array { + if record.BeforeImages != nil { + value := GetSqlValue(v.DataTypeNumber, record.BeforeImages.Array[i]) + beforeColomns[v.Name] = value + } + if record.AfterImages != nil { + value := GetSqlValue(v.DataTypeNumber, record.AfterImages.Array[i]) + afterColomns[v.Name] = value + } + } + afterData = append(afterData, afterColomns) + message.Event.Data = afterData + beforeData = append(beforeData, beforeColomns) + message.Event.Old = beforeData + return nil +} + +func getTableName(objectName string, message *Message) error { + table := strings.Split(objectName, ".") + if len(table) == 2 { + message.Event.Database = table[0] + message.Event.Table = table[1] + return nil + } else if len(table) == 3 { + message.Event.Database = table[0] + message.Event.Table = table[2] + return nil + } else if len(table) == 1 { + message.Event.Database = table[0] + message.Event.Table = "" + return nil + } + return errors.New("get table name failed") +} + +type Record struct { + Version int32 `json:"version"` + Id int64 `json:"id"` + SourceTimestamp int64 `json:"sourceTimestamp"` + SourcePosition string `json:"sourcePosition"` + SafeSourcePosition string `json:"safeSourcePosition"` + SourceTxid string `json:"sourceTxid"` + Source map[string]string `json:"source"` + Operation string `json:"operation"` + ObjectName map[string]string `json:"objectName"` + ProcessTimestamps int64 `json:"processTimestamps"` + Tags map[string]string `json:"tags"` + Fields *Fields `json:"fields"` + BeforeImages *Images `json:"beforeImages"` + AfterImages *Images `json:"afterImages"` + BornTimestamp int64 `json:"bornTimestamp"` +} + +type FArray struct { + DataTypeNumber int `json:"dataTypeNumber"` + Name string `json:"name"` +} +type Fields struct { + Array []FArray `json:"array"` +} + +type Images struct { + Array []map[string]map[string]interface{} `json:"array"` +} diff --git a/goimpl/lib/kfkdts/kfk.go b/goimpl/lib/kfkdts/kfk.go new file mode 100644 index 0000000..c0dbe67 --- /dev/null +++ b/goimpl/lib/kfkdts/kfk.go @@ -0,0 +1,111 @@ +package kfkdts + +import ( + "encoding/json" + + "github.com/LioRoger/subscribe_example/goimpl/lib/dtsavro" + "github.com/Shopify/sarama" +) + +var _ Consumer = &Kfk{} + +// Kfk 卡夫卡客户端定义 +type Kfk struct { + config *Config + consumer sarama.Consumer + Pconsumer sarama.PartitionConsumer + closer chan struct{} + MsgChan chan *Message + ErrChan chan error +} + +// NewKfk ... +func NewKfk(config *Config) (*Kfk, error) { + kconfig := sarama.NewConfig() + kconfig.Consumer.Return.Errors = true + kconfig.Version = sarama.V0_11_0_0 + c, err := sarama.NewConsumer(config.Hosts, kconfig) + if err != nil { + return nil, err + } + pConsumer, err := c.ConsumePartition(config.Topic, config.Partition, config.Offset) + if err != nil { + return nil, err + } + kfk := &Kfk{ + config: config, + consumer: c, + Pconsumer: pConsumer, + closer: make(chan struct{}), + MsgChan: make(chan *Message), + ErrChan: make(chan error), + } + go KfkHandler(kfk) + return kfk, nil +} + +// KfkHandler ... +func KfkHandler(kfk *Kfk) { + for { + select { + case msg := <-kfk.Pconsumer.Messages(): + kfk.DispatchMessage(msg) + case err := <-kfk.Pconsumer.Errors(): + kfk.ErrChan <- err + case <-kfk.closer: + return + } + } +} + +// DisaptchMessage 解析kafka过来的消息成Message并放入channel +func (k *Kfk) DispatchMessage(msg *sarama.ConsumerMessage) { + e := &Event{} + if err := json.Unmarshal(msg.Value, e); err != nil { + return + } + if e.Type == dtsavro.OperationUPDATE.String() { + k.MsgChan <- &Message{ + Type: dtsavro.OperationUPDATE, + Timestamp: msg.Timestamp, + Offset: msg.Offset, + Event: e, + } + } + if e.Type == dtsavro.OperationINSERT.String() { + k.MsgChan <- &Message{ + Type: dtsavro.OperationINSERT, + Timestamp: msg.Timestamp, + Offset: msg.Offset, + Event: e, + } + } + if e.Type == dtsavro.OperationDELETE.String() { + k.MsgChan <- &Message{ + Type: dtsavro.OperationDELETE, + Timestamp: msg.Timestamp, + Offset: msg.Offset, + Event: e, + } + } +} + +// Consume ... +func (k *Kfk) Consume() <-chan *Message { + return k.MsgChan +} + +// Error ... +func (k *Kfk) Error() <-chan error { + return k.ErrChan +} + +// Close ... +func (k *Kfk) Close() error { + close(k.closer) + close(k.MsgChan) + close(k.ErrChan) + k.consumer.Close() + k.Pconsumer.Close() + return nil +} diff --git a/goimpl/lib/kfkdts/kfk_decode.go b/goimpl/lib/kfkdts/kfk_decode.go new file mode 100644 index 0000000..2d6f8ee --- /dev/null +++ b/goimpl/lib/kfkdts/kfk_decode.go @@ -0,0 +1 @@ +package kfkdts diff --git a/goimpl/lib/readme.md b/goimpl/lib/readme.md new file mode 100644 index 0000000..0b672cb --- /dev/null +++ b/goimpl/lib/readme.md @@ -0,0 +1,18 @@ + +# 如果需要更新`dtsavro`目录,方式如下: + +- 1. 安装解析工具 +`go install github.com/actgardner/gogen-avro/v7/cmd/...` + +到下载目录`$GOPATH/bin/gogen-avro`可以看到安装结果 + +- 2. 运行下面命令生成`avro`序列化/反序列化代码: +`./gogen-avro --package=dtsavro ./dtsavro ../avro/Record.avsc` + +这个命令意思是我们使用`Record.asvc`文件,生成`package` 为 `dtsavro` 的文件,生成到`./dtsavro`目录下 + +# `kfkdts`包 + +![](./img/1.png) + +`kfkdts`包目前只实现1与2流程解析