-
Notifications
You must be signed in to change notification settings - Fork 229
Open
Description
In current implementation decimal is serilized as simple string.
but in 1.10.2 AVRO spec it must be sterilized as:
The byte array must contain the two's-complement representation of the unscaled integer value in big-endian byte order.
The scale is fixed, and is specified using an attribute.
Example:
package main
import (
"fmt"
"github.com/linkedin/goavro/v2"
)
func main() {
codec, err := goavro.NewCodec(`
{"type":"bytes","logicalType":"decimal","precision":4,"scale":2}`)
if err != nil {
fmt.Println(err)
}
textual := []byte(`"40.20"`)
native, _, err := codec.NativeFromTextual(textual)
if err != nil {
fmt.Println(err)
}
// Here is incorrect result. decimal value must be represented as bytes and not as string.
binary, err := codec.BinaryFromNative(nil, native)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(binary))
}vskliam
Metadata
Metadata
Assignees
Labels
No labels