Avoid copy, alloc.

This commit is contained in:
Nuno Cruces
2025-05-27 11:35:43 +01:00
parent 2204b96ff6
commit c9b364507e
2 changed files with 12 additions and 7 deletions

View File

@@ -177,12 +177,15 @@ func (ctx Context) ResultPointer(ptr any) {
//
// https://sqlite.org/c3ref/result_blob.html
func (ctx Context) ResultJSON(value any) {
data, err := json.Marshal(value)
err := json.NewEncoder(callbackWriter(func(p []byte) (int, error) {
ctx.ResultRawText(p[:len(p)-1]) // remove the newline
return 0, nil
})).Encode(value)
if err != nil {
ctx.ResultError(err)
return // notest
}
ctx.ResultRawText(data)
}
// ResultValue sets the result of the function to a copy of [Value].