gogen-avro
gogen-avro copied to clipboard
Example of using an Avro big.Rat as a value to produce the Avro Decimal
HI, It would be super cool if you give some examples of working properly for serialization/deserialization the Logical data types with gogen avro structs. I am in stack with the situation where I need to read the bytes from Avro Native like:
var codecDecimal, err= goavro.NewCodec({"type": ["null", {"type": "bytes", "logicalType": "decimal", "precision": 6, "scale": 4}]}) bytesDecimalBinary, err := codecDecimal.BinaryFromNative(nil, map[string]interface{}{"bytes.decimal": big.NewRat(500,4)})
from the Native GoAvro form I can read the value as big.Rat
What need to be done to assign the value to gogen avro struct correctly to produce the correct Decimal number after serialization to binary form ?
type AvroLogical struct { TEST__DECIMAL *UnionNullBytes }
in my case
gogenAvro:= model.NewAvroLogical()
gogenAvro.TEST_DECIMAL=model.NewUnionNullBytes()
gogenAvro.TEST_DECIMAL.Bytes = **NEW_DECIMAL**
gogenAvro.TEST_DECIMAL.UnionType = model.UnionNullBytesTypeEnumBytes
SO how to make a correct NEW_DECIMAL in my code ?
Let's simplify the question. Does gogen-avro support a Avro Logical datatypes as goavro does it OR it doesn't ?
could you answer the question ?
There's currently no support for logical types. You're able to work with these fields as a primitive type (bytes) but you would need to write logic to handle the decimal encoding. I would welcome a PR that added this functionality.