mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-22 08:54:26 +03:00
a156188b3e
* update dependencies, bump Go version to 1.19 * bump test image Go version * update golangci-lint * update gotosocial-drone-build * sign * linting, go fmt * update swagger docs * update swagger docs * whitespace * update contributing.md * fuckin whoopsie doopsie * linterino, linteroni * fix followrequest test not starting processor * fix other api/client tests not starting processor * fix remaining tests where processor not started * bump go-runners version * don't check last-webfingered-at, processor may have updated this * update swagger command * update bun to latest version * fix embed to work the same as before with new bun Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
package decoder
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/goccy/go-json/internal/runtime"
|
|
)
|
|
|
|
type ptrDecoder struct {
|
|
dec Decoder
|
|
typ *runtime.Type
|
|
structName string
|
|
fieldName string
|
|
}
|
|
|
|
func newPtrDecoder(dec Decoder, typ *runtime.Type, structName, fieldName string) *ptrDecoder {
|
|
return &ptrDecoder{
|
|
dec: dec,
|
|
typ: typ,
|
|
structName: structName,
|
|
fieldName: fieldName,
|
|
}
|
|
}
|
|
|
|
func (d *ptrDecoder) contentDecoder() Decoder {
|
|
dec, ok := d.dec.(*ptrDecoder)
|
|
if !ok {
|
|
return d.dec
|
|
}
|
|
return dec.contentDecoder()
|
|
}
|
|
|
|
//nolint:golint
|
|
//go:linkname unsafe_New reflect.unsafe_New
|
|
func unsafe_New(*runtime.Type) unsafe.Pointer
|
|
|
|
func (d *ptrDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error {
|
|
if s.skipWhiteSpace() == nul {
|
|
s.read()
|
|
}
|
|
if s.char() == 'n' {
|
|
if err := nullBytes(s); err != nil {
|
|
return err
|
|
}
|
|
*(*unsafe.Pointer)(p) = nil
|
|
return nil
|
|
}
|
|
var newptr unsafe.Pointer
|
|
if *(*unsafe.Pointer)(p) == nil {
|
|
newptr = unsafe_New(d.typ)
|
|
*(*unsafe.Pointer)(p) = newptr
|
|
} else {
|
|
newptr = *(*unsafe.Pointer)(p)
|
|
}
|
|
if err := d.dec.DecodeStream(s, depth, newptr); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d *ptrDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) {
|
|
buf := ctx.Buf
|
|
cursor = skipWhiteSpace(buf, cursor)
|
|
if buf[cursor] == 'n' {
|
|
if err := validateNull(buf, cursor); err != nil {
|
|
return 0, err
|
|
}
|
|
if p != nil {
|
|
*(*unsafe.Pointer)(p) = nil
|
|
}
|
|
cursor += 4
|
|
return cursor, nil
|
|
}
|
|
var newptr unsafe.Pointer
|
|
if *(*unsafe.Pointer)(p) == nil {
|
|
newptr = unsafe_New(d.typ)
|
|
*(*unsafe.Pointer)(p) = newptr
|
|
} else {
|
|
newptr = *(*unsafe.Pointer)(p)
|
|
}
|
|
c, err := d.dec.Decode(ctx, cursor, depth, newptr)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
cursor = c
|
|
return cursor, nil
|
|
}
|