goccy / go-json

Fast JSON encoder/decoder compatible with encoding/json for Go
MIT License
3.11k stars 148 forks source link

Issue with using go-json and TinyGo due to deprecated reflect.SliceHeader #487

Open hariso opened 11 months ago

hariso commented 11 months ago

Hello!

Before I come to the issue, thanks for all maintainer and contributors for building this great project! Fantastic work by everyone.

My team started using go-json in a project, which is compiled into WASM using TinyGo. However, that doesn't work well. When compiling the code, we're getting

cannot use len(s) / 8 (value of type int) as uintptr value in struct literal

The offending lines are these.

TinyGo's documentation points that StringHeader and SliceHeader, according to the Go docs, cannot be used safely and portably (they are marked as deprecated).

What do you think about making the above mentioned change in go-json? I know that making it work for TinyGo itself isn't a huge argument, but if we add that the StringHeader and SliceHeader are deprecated and not fully portable it might make the case.:)

Example code

package main

import (
    "fmt"

    "github.com/conduitio/conduit-commons/opencdc"
)

func main() {
    fmt.Println("Hello, WebAssembly!")
    fmt.Printf(
        "%v\n",
        opencdc.Record{
            Position: opencdc.Position("abc"),
            Payload: opencdc.Change{
                Before: opencdc.RawData("before"),
                After:  opencdc.RawData("after"),
            },
        },
    )
}