internal/wasm-tools, internal/cm: udpate to go.bytecodealliance.org@v0.6.1 and cm@v0.2.1

This commit is contained in:
Randy Reddig
2025-03-16 13:35:44 -07:00
committed by Ron Evans
parent 8e009de8a8
commit d63d8e0899
5 changed files with 18 additions and 69 deletions
+11 -6
View File
@@ -1,7 +1,5 @@
package cm
import "errors"
// CaseUnmarshaler returns an function that can unmarshal text into
// [variant] or [enum] case T.
//
@@ -33,8 +31,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
if len(text) == 0 {
return errEmpty
}
s := string(text)
c, ok := m[s]
c, ok := m[string(text)]
if !ok {
return errNoMatchingCase
}
@@ -46,6 +43,14 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
const linearScanThreshold = 16
var (
errEmpty = errors.New("empty text")
errNoMatchingCase = errors.New("no matching case")
errEmpty = &stringError{"empty text"}
errNoMatchingCase = &stringError{"no matching case"}
)
type stringError struct {
err string
}
func (err *stringError) Error() string {
return err.err
}
-56
View File
@@ -1,8 +1,6 @@
package cm
import (
"bytes"
"encoding/json"
"unsafe"
)
@@ -62,57 +60,3 @@ func (l list[T]) Data() *T {
func (l list[T]) Len() uintptr {
return l.len
}
// MarshalJSON implements json.Marshaler.
func (l list[T]) MarshalJSON() ([]byte, error) {
if l.len == 0 {
return []byte("[]"), nil
}
s := l.Slice()
var zero T
if unsafe.Sizeof(zero) == 1 {
// The default Go json.Encoder will marshal []byte as base64.
// We override that behavior so all int types have the same serialization format.
// []uint8{1,2,3} -> [1,2,3]
// []uint32{1,2,3} -> [1,2,3]
return json.Marshal(sliceOf(s))
}
return json.Marshal(s)
}
type slice[T any] []entry[T]
func sliceOf[S ~[]E, E any](s S) slice[E] {
return *(*slice[E])(unsafe.Pointer(&s))
}
type entry[T any] [1]T
func (v entry[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(v[0])
}
// UnmarshalJSON implements json.Unmarshaler.
func (l *list[T]) UnmarshalJSON(data []byte) error {
if bytes.Equal(data, nullLiteral) {
return nil
}
var s []T
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
l.data = unsafe.SliceData([]T(s))
l.len = uintptr(len(s))
return nil
}
// nullLiteral is the JSON representation of a null literal.
// By convention, to approximate the behavior of Unmarshal itself,
// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.
// See https://pkg.go.dev/encoding/json#Unmarshaler for more information.
var nullLiteral = []byte("null")