Skip to content

Commit

Permalink
fix: bytes to string converter
Browse files Browse the repository at this point in the history
  • Loading branch information
redaLaanait committed Jan 12, 2024
1 parent f2c19a2 commit 35a64d9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avro

import (
"fmt"
"unsafe"

"github.com/modern-go/reflect2"
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 35a64d9

Please sign in to comment.