From 35a64d950e4516d062eb5c5744948e0588bce6d0 Mon Sep 17 00:00:00 2001 From: Reda Laanait Date: Fri, 12 Jan 2024 10:40:11 +0100 Subject: [PATCH] fix: bytes to string converter --- converter.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/converter.go b/converter.go index 0cc0bcd5..0a100a35 100644 --- a/converter.go +++ b/converter.go @@ -2,6 +2,7 @@ package avro import ( "fmt" + "unsafe" "github.com/modern-go/reflect2" ) @@ -71,10 +72,10 @@ func createStringConverter(typ Type) (func(*Reader) string, error) { case Bytes: return func(r *Reader) string { b := r.ReadBytes() - // TBD: update go.mod version to go 1.20 minimum - // runtime.KeepAlive(b) - // return unsafe.String(unsafe.SliceData(b), len(b)) - return string(b) + if len(b) == 0 { + return "" + } + return *(*string)(unsafe.Pointer(&b)) }, nil case String: return func(r *Reader) string { return r.ReadString() }, nil