mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
* experiment: reject bad peer info messages * v2.1.0.18 preview * add tagged sync * Add missing hypergraph changes * small tweaks to sync * allow local sync, use it for provers with workers * missing file * resolve build error * resolve sync issue, remove raw sync * resolve deletion promotion bug * resolve sync abstraction leak from tree deletion changes * rearrange prover sync * remove pruning from sync * restore removed sync flag * fix: sync, event stream deadlock, heuristic scoring of better shards * resolve hanging shutdown + pubsub proxy issue * further bugfixes: sync (restore old leaf sync), pubsub shutdown, merge events * fix: clean up rust ffi, background coverage events, and sync tweaks * fix: linking issue for channel, connectivity test aggression, sync regression, join tests * fix: disjoint sync, improper application of filter * resolve sync/reel/validation deadlock * adjust sync to handle no leaf edge cases, multi-path segment traversal * use simpler sync * faster, simpler sync with some debug extras * migration to recalculate * don't use batch * square up the roots * fix nil pointer * fix: seniority calculation, sync race condition, migration * make sync dumber * fix: tree deletion issue * fix: missing seniority merge request canonical serialization * address issues from previous commit test * stale workers should be cleared * remove missing gap check * rearrange collect, reduce sync logging noise * fix: the disjoint leaf/branch sync case * nuclear option on sync failures * v2.1.0.18, finalized
1463 lines
45 KiB
Go
1463 lines
45 KiB
Go
package ferret
|
|
|
|
// #include <ferret.h>
|
|
import "C"
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"fmt"
|
|
"io"
|
|
"math"
|
|
"runtime"
|
|
"sync/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
// This is needed, because as of go 1.24
|
|
// type RustBuffer C.RustBuffer cannot have methods,
|
|
// RustBuffer is treated as non-local type
|
|
type GoRustBuffer struct {
|
|
inner C.RustBuffer
|
|
}
|
|
|
|
type RustBufferI interface {
|
|
AsReader() *bytes.Reader
|
|
Free()
|
|
ToGoBytes() []byte
|
|
Data() unsafe.Pointer
|
|
Len() uint64
|
|
Capacity() uint64
|
|
}
|
|
|
|
func RustBufferFromExternal(b RustBufferI) GoRustBuffer {
|
|
return GoRustBuffer{
|
|
inner: C.RustBuffer{
|
|
capacity: C.uint64_t(b.Capacity()),
|
|
len: C.uint64_t(b.Len()),
|
|
data: (*C.uchar)(b.Data()),
|
|
},
|
|
}
|
|
}
|
|
|
|
func (cb GoRustBuffer) Capacity() uint64 {
|
|
return uint64(cb.inner.capacity)
|
|
}
|
|
|
|
func (cb GoRustBuffer) Len() uint64 {
|
|
return uint64(cb.inner.len)
|
|
}
|
|
|
|
func (cb GoRustBuffer) Data() unsafe.Pointer {
|
|
return unsafe.Pointer(cb.inner.data)
|
|
}
|
|
|
|
func (cb GoRustBuffer) AsReader() *bytes.Reader {
|
|
b := unsafe.Slice((*byte)(cb.inner.data), C.uint64_t(cb.inner.len))
|
|
return bytes.NewReader(b)
|
|
}
|
|
|
|
func (cb GoRustBuffer) Free() {
|
|
rustCall(func(status *C.RustCallStatus) bool {
|
|
C.ffi_ferret_rustbuffer_free(cb.inner, status)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (cb GoRustBuffer) ToGoBytes() []byte {
|
|
return C.GoBytes(unsafe.Pointer(cb.inner.data), C.int(cb.inner.len))
|
|
}
|
|
|
|
func stringToRustBuffer(str string) C.RustBuffer {
|
|
return bytesToRustBuffer([]byte(str))
|
|
}
|
|
|
|
func bytesToRustBuffer(b []byte) C.RustBuffer {
|
|
if len(b) == 0 {
|
|
return C.RustBuffer{}
|
|
}
|
|
// We can pass the pointer along here, as it is pinned
|
|
// for the duration of this call
|
|
foreign := C.ForeignBytes{
|
|
len: C.int(len(b)),
|
|
data: (*C.uchar)(unsafe.Pointer(&b[0])),
|
|
}
|
|
|
|
return rustCall(func(status *C.RustCallStatus) C.RustBuffer {
|
|
return C.ffi_ferret_rustbuffer_from_bytes(foreign, status)
|
|
})
|
|
}
|
|
|
|
type BufLifter[GoType any] interface {
|
|
Lift(value RustBufferI) GoType
|
|
}
|
|
|
|
type BufLowerer[GoType any] interface {
|
|
Lower(value GoType) C.RustBuffer
|
|
}
|
|
|
|
type BufReader[GoType any] interface {
|
|
Read(reader io.Reader) GoType
|
|
}
|
|
|
|
type BufWriter[GoType any] interface {
|
|
Write(writer io.Writer, value GoType)
|
|
}
|
|
|
|
func LowerIntoRustBuffer[GoType any](bufWriter BufWriter[GoType], value GoType) C.RustBuffer {
|
|
// This might be not the most efficient way but it does not require knowing allocation size
|
|
// beforehand
|
|
var buffer bytes.Buffer
|
|
bufWriter.Write(&buffer, value)
|
|
|
|
bytes, err := io.ReadAll(&buffer)
|
|
if err != nil {
|
|
panic(fmt.Errorf("reading written data: %w", err))
|
|
}
|
|
return bytesToRustBuffer(bytes)
|
|
}
|
|
|
|
func LiftFromRustBuffer[GoType any](bufReader BufReader[GoType], rbuf RustBufferI) GoType {
|
|
defer rbuf.Free()
|
|
reader := rbuf.AsReader()
|
|
item := bufReader.Read(reader)
|
|
if reader.Len() > 0 {
|
|
// TODO: Remove this
|
|
leftover, _ := io.ReadAll(reader)
|
|
panic(fmt.Errorf("Junk remaining in buffer after lifting: %s", string(leftover)))
|
|
}
|
|
return item
|
|
}
|
|
|
|
func rustCallWithError[E any, U any](converter BufReader[*E], callback func(*C.RustCallStatus) U) (U, *E) {
|
|
var status C.RustCallStatus
|
|
returnValue := callback(&status)
|
|
err := checkCallStatus(converter, status)
|
|
return returnValue, err
|
|
}
|
|
|
|
func checkCallStatus[E any](converter BufReader[*E], status C.RustCallStatus) *E {
|
|
switch status.code {
|
|
case 0:
|
|
return nil
|
|
case 1:
|
|
return LiftFromRustBuffer(converter, GoRustBuffer{inner: status.errorBuf})
|
|
case 2:
|
|
// when the rust code sees a panic, it tries to construct a rustBuffer
|
|
// with the message. but if that code panics, then it just sends back
|
|
// an empty buffer.
|
|
if status.errorBuf.len > 0 {
|
|
panic(fmt.Errorf("%s", FfiConverterStringINSTANCE.Lift(GoRustBuffer{inner: status.errorBuf})))
|
|
} else {
|
|
panic(fmt.Errorf("Rust panicked while handling Rust panic"))
|
|
}
|
|
default:
|
|
panic(fmt.Errorf("unknown status code: %d", status.code))
|
|
}
|
|
}
|
|
|
|
func checkCallStatusUnknown(status C.RustCallStatus) error {
|
|
switch status.code {
|
|
case 0:
|
|
return nil
|
|
case 1:
|
|
panic(fmt.Errorf("function not returning an error returned an error"))
|
|
case 2:
|
|
// when the rust code sees a panic, it tries to construct a C.RustBuffer
|
|
// with the message. but if that code panics, then it just sends back
|
|
// an empty buffer.
|
|
if status.errorBuf.len > 0 {
|
|
panic(fmt.Errorf("%s", FfiConverterStringINSTANCE.Lift(GoRustBuffer{
|
|
inner: status.errorBuf,
|
|
})))
|
|
} else {
|
|
panic(fmt.Errorf("Rust panicked while handling Rust panic"))
|
|
}
|
|
default:
|
|
return fmt.Errorf("unknown status code: %d", status.code)
|
|
}
|
|
}
|
|
|
|
func rustCall[U any](callback func(*C.RustCallStatus) U) U {
|
|
returnValue, err := rustCallWithError[error](nil, callback)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return returnValue
|
|
}
|
|
|
|
type NativeError interface {
|
|
AsError() error
|
|
}
|
|
|
|
func writeInt8(writer io.Writer, value int8) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeUint8(writer io.Writer, value uint8) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeInt16(writer io.Writer, value int16) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeUint16(writer io.Writer, value uint16) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeInt32(writer io.Writer, value int32) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeUint32(writer io.Writer, value uint32) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeInt64(writer io.Writer, value int64) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeUint64(writer io.Writer, value uint64) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeFloat32(writer io.Writer, value float32) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func writeFloat64(writer io.Writer, value float64) {
|
|
if err := binary.Write(writer, binary.BigEndian, value); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func readInt8(reader io.Reader) int8 {
|
|
var result int8
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readUint8(reader io.Reader) uint8 {
|
|
var result uint8
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readInt16(reader io.Reader) int16 {
|
|
var result int16
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readUint16(reader io.Reader) uint16 {
|
|
var result uint16
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readInt32(reader io.Reader) int32 {
|
|
var result int32
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readUint32(reader io.Reader) uint32 {
|
|
var result uint32
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readInt64(reader io.Reader) int64 {
|
|
var result int64
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readUint64(reader io.Reader) uint64 {
|
|
var result uint64
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readFloat32(reader io.Reader) float32 {
|
|
var result float32
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func readFloat64(reader io.Reader) float64 {
|
|
var result float64
|
|
if err := binary.Read(reader, binary.BigEndian, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func init() {
|
|
|
|
uniffiCheckChecksums()
|
|
}
|
|
|
|
func uniffiCheckChecksums() {
|
|
// Get the bindings contract version from our ComponentInterface
|
|
bindingsContractVersion := 26
|
|
// Get the scaffolding contract version by calling the into the dylib
|
|
scaffoldingContractVersion := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint32_t {
|
|
return C.ffi_ferret_uniffi_contract_version()
|
|
})
|
|
if bindingsContractVersion != int(scaffoldingContractVersion) {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: UniFFI contract version mismatch")
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_func_create_buffer_io_manager()
|
|
})
|
|
if checksum != 31310 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_func_create_buffer_io_manager: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_func_create_ferret_cot_buffer_manager()
|
|
})
|
|
if checksum != 17020 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_func_create_ferret_cot_buffer_manager: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_func_create_ferret_cot_manager()
|
|
})
|
|
if checksum != 49338 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_func_create_ferret_cot_manager: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_func_create_netio_manager()
|
|
})
|
|
if checksum != 37785 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_func_create_netio_manager: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_clear()
|
|
})
|
|
if checksum != 46028 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_clear: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_drain_send()
|
|
})
|
|
if checksum != 42377 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_drain_send: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_fill_recv()
|
|
})
|
|
if checksum != 47991 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_fill_recv: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_recv_available()
|
|
})
|
|
if checksum != 30236 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_recv_available: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_send_size()
|
|
})
|
|
if checksum != 7700 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_send_size: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_set_error()
|
|
})
|
|
if checksum != 26761 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_set_error: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_bufferiomanager_set_timeout()
|
|
})
|
|
if checksum != 18359 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_bufferiomanager_set_timeout: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_assemble_state()
|
|
})
|
|
if checksum != 6363 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_assemble_state: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_disassemble_state()
|
|
})
|
|
if checksum != 47188 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_disassemble_state: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_get_block_data()
|
|
})
|
|
if checksum != 34398 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_get_block_data: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_is_setup()
|
|
})
|
|
if checksum != 1717 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_is_setup: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_recv_cot()
|
|
})
|
|
if checksum != 8122 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_recv_cot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_recv_rot()
|
|
})
|
|
if checksum != 15345 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_recv_rot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_send_cot()
|
|
})
|
|
if checksum != 13639 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_send_cot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_send_rot()
|
|
})
|
|
if checksum != 3052 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_send_rot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_set_block_data()
|
|
})
|
|
if checksum != 37344 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_set_block_data: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_setup()
|
|
})
|
|
if checksum != 11907 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_setup: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotbuffermanager_state_size()
|
|
})
|
|
if checksum != 3205 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotbuffermanager_state_size: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_get_block_data()
|
|
})
|
|
if checksum != 54850 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_get_block_data: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_recv_cot()
|
|
})
|
|
if checksum != 47983 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_recv_cot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_recv_rot()
|
|
})
|
|
if checksum != 38722 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_recv_rot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_send_cot()
|
|
})
|
|
if checksum != 25816 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_send_cot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_send_rot()
|
|
})
|
|
if checksum != 51835 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_send_rot: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
{
|
|
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
|
|
return C.uniffi_ferret_checksum_method_ferretcotmanager_set_block_data()
|
|
})
|
|
if checksum != 39823 {
|
|
// If this happens try cleaning and rebuilding your project
|
|
panic("ferret: uniffi_ferret_checksum_method_ferretcotmanager_set_block_data: UniFFI API checksum mismatch")
|
|
}
|
|
}
|
|
}
|
|
|
|
type FfiConverterUint8 struct{}
|
|
|
|
var FfiConverterUint8INSTANCE = FfiConverterUint8{}
|
|
|
|
func (FfiConverterUint8) Lower(value uint8) C.uint8_t {
|
|
return C.uint8_t(value)
|
|
}
|
|
|
|
func (FfiConverterUint8) Write(writer io.Writer, value uint8) {
|
|
writeUint8(writer, value)
|
|
}
|
|
|
|
func (FfiConverterUint8) Lift(value C.uint8_t) uint8 {
|
|
return uint8(value)
|
|
}
|
|
|
|
func (FfiConverterUint8) Read(reader io.Reader) uint8 {
|
|
return readUint8(reader)
|
|
}
|
|
|
|
type FfiDestroyerUint8 struct{}
|
|
|
|
func (FfiDestroyerUint8) Destroy(_ uint8) {}
|
|
|
|
type FfiConverterInt32 struct{}
|
|
|
|
var FfiConverterInt32INSTANCE = FfiConverterInt32{}
|
|
|
|
func (FfiConverterInt32) Lower(value int32) C.int32_t {
|
|
return C.int32_t(value)
|
|
}
|
|
|
|
func (FfiConverterInt32) Write(writer io.Writer, value int32) {
|
|
writeInt32(writer, value)
|
|
}
|
|
|
|
func (FfiConverterInt32) Lift(value C.int32_t) int32 {
|
|
return int32(value)
|
|
}
|
|
|
|
func (FfiConverterInt32) Read(reader io.Reader) int32 {
|
|
return readInt32(reader)
|
|
}
|
|
|
|
type FfiDestroyerInt32 struct{}
|
|
|
|
func (FfiDestroyerInt32) Destroy(_ int32) {}
|
|
|
|
type FfiConverterUint64 struct{}
|
|
|
|
var FfiConverterUint64INSTANCE = FfiConverterUint64{}
|
|
|
|
func (FfiConverterUint64) Lower(value uint64) C.uint64_t {
|
|
return C.uint64_t(value)
|
|
}
|
|
|
|
func (FfiConverterUint64) Write(writer io.Writer, value uint64) {
|
|
writeUint64(writer, value)
|
|
}
|
|
|
|
func (FfiConverterUint64) Lift(value C.uint64_t) uint64 {
|
|
return uint64(value)
|
|
}
|
|
|
|
func (FfiConverterUint64) Read(reader io.Reader) uint64 {
|
|
return readUint64(reader)
|
|
}
|
|
|
|
type FfiDestroyerUint64 struct{}
|
|
|
|
func (FfiDestroyerUint64) Destroy(_ uint64) {}
|
|
|
|
type FfiConverterInt64 struct{}
|
|
|
|
var FfiConverterInt64INSTANCE = FfiConverterInt64{}
|
|
|
|
func (FfiConverterInt64) Lower(value int64) C.int64_t {
|
|
return C.int64_t(value)
|
|
}
|
|
|
|
func (FfiConverterInt64) Write(writer io.Writer, value int64) {
|
|
writeInt64(writer, value)
|
|
}
|
|
|
|
func (FfiConverterInt64) Lift(value C.int64_t) int64 {
|
|
return int64(value)
|
|
}
|
|
|
|
func (FfiConverterInt64) Read(reader io.Reader) int64 {
|
|
return readInt64(reader)
|
|
}
|
|
|
|
type FfiDestroyerInt64 struct{}
|
|
|
|
func (FfiDestroyerInt64) Destroy(_ int64) {}
|
|
|
|
type FfiConverterBool struct{}
|
|
|
|
var FfiConverterBoolINSTANCE = FfiConverterBool{}
|
|
|
|
func (FfiConverterBool) Lower(value bool) C.int8_t {
|
|
if value {
|
|
return C.int8_t(1)
|
|
}
|
|
return C.int8_t(0)
|
|
}
|
|
|
|
func (FfiConverterBool) Write(writer io.Writer, value bool) {
|
|
if value {
|
|
writeInt8(writer, 1)
|
|
} else {
|
|
writeInt8(writer, 0)
|
|
}
|
|
}
|
|
|
|
func (FfiConverterBool) Lift(value C.int8_t) bool {
|
|
return value != 0
|
|
}
|
|
|
|
func (FfiConverterBool) Read(reader io.Reader) bool {
|
|
return readInt8(reader) != 0
|
|
}
|
|
|
|
type FfiDestroyerBool struct{}
|
|
|
|
func (FfiDestroyerBool) Destroy(_ bool) {}
|
|
|
|
type FfiConverterString struct{}
|
|
|
|
var FfiConverterStringINSTANCE = FfiConverterString{}
|
|
|
|
func (FfiConverterString) Lift(rb RustBufferI) string {
|
|
defer rb.Free()
|
|
reader := rb.AsReader()
|
|
b, err := io.ReadAll(reader)
|
|
if err != nil {
|
|
panic(fmt.Errorf("reading reader: %w", err))
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func (FfiConverterString) Read(reader io.Reader) string {
|
|
length := readInt32(reader)
|
|
buffer := make([]byte, length)
|
|
read_length, err := reader.Read(buffer)
|
|
if err != nil && err != io.EOF {
|
|
panic(err)
|
|
}
|
|
if read_length != int(length) {
|
|
panic(fmt.Errorf("bad read length when reading string, expected %d, read %d", length, read_length))
|
|
}
|
|
return string(buffer)
|
|
}
|
|
|
|
func (FfiConverterString) Lower(value string) C.RustBuffer {
|
|
return stringToRustBuffer(value)
|
|
}
|
|
|
|
func (FfiConverterString) Write(writer io.Writer, value string) {
|
|
if len(value) > math.MaxInt32 {
|
|
panic("String is too large to fit into Int32")
|
|
}
|
|
|
|
writeInt32(writer, int32(len(value)))
|
|
write_length, err := io.WriteString(writer, value)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if write_length != len(value) {
|
|
panic(fmt.Errorf("bad write length when writing string, expected %d, written %d", len(value), write_length))
|
|
}
|
|
}
|
|
|
|
type FfiDestroyerString struct{}
|
|
|
|
func (FfiDestroyerString) Destroy(_ string) {}
|
|
|
|
// Below is an implementation of synchronization requirements outlined in the link.
|
|
// https://github.com/mozilla/uniffi-rs/blob/0dc031132d9493ca812c3af6e7dd60ad2ea95bf0/uniffi_bindgen/src/bindings/kotlin/templates/ObjectRuntime.kt#L31
|
|
|
|
type FfiObject struct {
|
|
pointer unsafe.Pointer
|
|
callCounter atomic.Int64
|
|
cloneFunction func(unsafe.Pointer, *C.RustCallStatus) unsafe.Pointer
|
|
freeFunction func(unsafe.Pointer, *C.RustCallStatus)
|
|
destroyed atomic.Bool
|
|
}
|
|
|
|
func newFfiObject(
|
|
pointer unsafe.Pointer,
|
|
cloneFunction func(unsafe.Pointer, *C.RustCallStatus) unsafe.Pointer,
|
|
freeFunction func(unsafe.Pointer, *C.RustCallStatus),
|
|
) FfiObject {
|
|
return FfiObject{
|
|
pointer: pointer,
|
|
cloneFunction: cloneFunction,
|
|
freeFunction: freeFunction,
|
|
}
|
|
}
|
|
|
|
func (ffiObject *FfiObject) incrementPointer(debugName string) unsafe.Pointer {
|
|
for {
|
|
counter := ffiObject.callCounter.Load()
|
|
if counter <= -1 {
|
|
panic(fmt.Errorf("%v object has already been destroyed", debugName))
|
|
}
|
|
if counter == math.MaxInt64 {
|
|
panic(fmt.Errorf("%v object call counter would overflow", debugName))
|
|
}
|
|
if ffiObject.callCounter.CompareAndSwap(counter, counter+1) {
|
|
break
|
|
}
|
|
}
|
|
|
|
return rustCall(func(status *C.RustCallStatus) unsafe.Pointer {
|
|
return ffiObject.cloneFunction(ffiObject.pointer, status)
|
|
})
|
|
}
|
|
|
|
func (ffiObject *FfiObject) decrementPointer() {
|
|
if ffiObject.callCounter.Add(-1) == -1 {
|
|
ffiObject.freeRustArcPtr()
|
|
}
|
|
}
|
|
|
|
func (ffiObject *FfiObject) destroy() {
|
|
if ffiObject.destroyed.CompareAndSwap(false, true) {
|
|
if ffiObject.callCounter.Add(-1) == -1 {
|
|
ffiObject.freeRustArcPtr()
|
|
}
|
|
}
|
|
}
|
|
|
|
func (ffiObject *FfiObject) freeRustArcPtr() {
|
|
rustCall(func(status *C.RustCallStatus) int32 {
|
|
ffiObject.freeFunction(ffiObject.pointer, status)
|
|
return 0
|
|
})
|
|
}
|
|
|
|
type BufferIoManagerInterface interface {
|
|
Clear()
|
|
DrainSend(maxLen uint64) []uint8
|
|
FillRecv(data []uint8) bool
|
|
RecvAvailable() uint64
|
|
SendSize() uint64
|
|
SetError(message string)
|
|
SetTimeout(timeoutMs int64)
|
|
}
|
|
type BufferIoManager struct {
|
|
ffiObject FfiObject
|
|
}
|
|
|
|
func (_self *BufferIoManager) Clear() {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_bufferiomanager_clear(
|
|
_pointer, _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *BufferIoManager) DrainSend(maxLen uint64) []uint8 {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterSequenceUint8INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
|
|
return GoRustBuffer{
|
|
inner: C.uniffi_ferret_fn_method_bufferiomanager_drain_send(
|
|
_pointer, FfiConverterUint64INSTANCE.Lower(maxLen), _uniffiStatus),
|
|
}
|
|
}))
|
|
}
|
|
|
|
func (_self *BufferIoManager) FillRecv(data []uint8) bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_bufferiomanager_fill_recv(
|
|
_pointer, FfiConverterSequenceUint8INSTANCE.Lower(data), _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *BufferIoManager) RecvAvailable() uint64 {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterUint64INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint64_t {
|
|
return C.uniffi_ferret_fn_method_bufferiomanager_recv_available(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *BufferIoManager) SendSize() uint64 {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterUint64INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint64_t {
|
|
return C.uniffi_ferret_fn_method_bufferiomanager_send_size(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *BufferIoManager) SetError(message string) {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_bufferiomanager_set_error(
|
|
_pointer, FfiConverterStringINSTANCE.Lower(message), _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *BufferIoManager) SetTimeout(timeoutMs int64) {
|
|
_pointer := _self.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_bufferiomanager_set_timeout(
|
|
_pointer, FfiConverterInt64INSTANCE.Lower(timeoutMs), _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
func (object *BufferIoManager) Destroy() {
|
|
runtime.SetFinalizer(object, nil)
|
|
object.ffiObject.destroy()
|
|
}
|
|
|
|
type FfiConverterBufferIoManager struct{}
|
|
|
|
var FfiConverterBufferIoManagerINSTANCE = FfiConverterBufferIoManager{}
|
|
|
|
func (c FfiConverterBufferIoManager) Lift(pointer unsafe.Pointer) *BufferIoManager {
|
|
result := &BufferIoManager{
|
|
newFfiObject(
|
|
pointer,
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_clone_bufferiomanager(pointer, status)
|
|
},
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
|
|
C.uniffi_ferret_fn_free_bufferiomanager(pointer, status)
|
|
},
|
|
),
|
|
}
|
|
runtime.SetFinalizer(result, (*BufferIoManager).Destroy)
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterBufferIoManager) Read(reader io.Reader) *BufferIoManager {
|
|
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
|
|
}
|
|
|
|
func (c FfiConverterBufferIoManager) Lower(value *BufferIoManager) unsafe.Pointer {
|
|
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
|
|
// because the pointer will be decremented immediately after this function returns,
|
|
// and someone will be left holding onto a non-locked pointer.
|
|
pointer := value.ffiObject.incrementPointer("*BufferIoManager")
|
|
defer value.ffiObject.decrementPointer()
|
|
return pointer
|
|
|
|
}
|
|
|
|
func (c FfiConverterBufferIoManager) Write(writer io.Writer, value *BufferIoManager) {
|
|
writeUint64(writer, uint64(uintptr(c.Lower(value))))
|
|
}
|
|
|
|
type FfiDestroyerBufferIoManager struct{}
|
|
|
|
func (_ FfiDestroyerBufferIoManager) Destroy(value *BufferIoManager) {
|
|
value.Destroy()
|
|
}
|
|
|
|
type FerretCotBufferManagerInterface interface {
|
|
AssembleState() []uint8
|
|
DisassembleState(data []uint8) bool
|
|
GetBlockData(blockChoice uint8, index uint64) []uint8
|
|
IsSetup() bool
|
|
RecvCot() bool
|
|
RecvRot() bool
|
|
SendCot() bool
|
|
SendRot() bool
|
|
SetBlockData(blockChoice uint8, index uint64, data []uint8)
|
|
Setup() bool
|
|
StateSize() int64
|
|
}
|
|
type FerretCotBufferManager struct {
|
|
ffiObject FfiObject
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) AssembleState() []uint8 {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterSequenceUint8INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
|
|
return GoRustBuffer{
|
|
inner: C.uniffi_ferret_fn_method_ferretcotbuffermanager_assemble_state(
|
|
_pointer, _uniffiStatus),
|
|
}
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) DisassembleState(data []uint8) bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_disassemble_state(
|
|
_pointer, FfiConverterSequenceUint8INSTANCE.Lower(data), _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) GetBlockData(blockChoice uint8, index uint64) []uint8 {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterSequenceUint8INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
|
|
return GoRustBuffer{
|
|
inner: C.uniffi_ferret_fn_method_ferretcotbuffermanager_get_block_data(
|
|
_pointer, FfiConverterUint8INSTANCE.Lower(blockChoice), FfiConverterUint64INSTANCE.Lower(index), _uniffiStatus),
|
|
}
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) IsSetup() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_is_setup(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) RecvCot() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_recv_cot(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) RecvRot() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_recv_rot(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) SendCot() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_send_cot(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) SendRot() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_send_rot(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) SetBlockData(blockChoice uint8, index uint64, data []uint8) {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotbuffermanager_set_block_data(
|
|
_pointer, FfiConverterUint8INSTANCE.Lower(blockChoice), FfiConverterUint64INSTANCE.Lower(index), FfiConverterSequenceUint8INSTANCE.Lower(data), _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) Setup() bool {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterBoolINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int8_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_setup(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotBufferManager) StateSize() int64 {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterInt64INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) C.int64_t {
|
|
return C.uniffi_ferret_fn_method_ferretcotbuffermanager_state_size(
|
|
_pointer, _uniffiStatus)
|
|
}))
|
|
}
|
|
func (object *FerretCotBufferManager) Destroy() {
|
|
runtime.SetFinalizer(object, nil)
|
|
object.ffiObject.destroy()
|
|
}
|
|
|
|
type FfiConverterFerretCotBufferManager struct{}
|
|
|
|
var FfiConverterFerretCotBufferManagerINSTANCE = FfiConverterFerretCotBufferManager{}
|
|
|
|
func (c FfiConverterFerretCotBufferManager) Lift(pointer unsafe.Pointer) *FerretCotBufferManager {
|
|
result := &FerretCotBufferManager{
|
|
newFfiObject(
|
|
pointer,
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_clone_ferretcotbuffermanager(pointer, status)
|
|
},
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
|
|
C.uniffi_ferret_fn_free_ferretcotbuffermanager(pointer, status)
|
|
},
|
|
),
|
|
}
|
|
runtime.SetFinalizer(result, (*FerretCotBufferManager).Destroy)
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterFerretCotBufferManager) Read(reader io.Reader) *FerretCotBufferManager {
|
|
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
|
|
}
|
|
|
|
func (c FfiConverterFerretCotBufferManager) Lower(value *FerretCotBufferManager) unsafe.Pointer {
|
|
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
|
|
// because the pointer will be decremented immediately after this function returns,
|
|
// and someone will be left holding onto a non-locked pointer.
|
|
pointer := value.ffiObject.incrementPointer("*FerretCotBufferManager")
|
|
defer value.ffiObject.decrementPointer()
|
|
return pointer
|
|
|
|
}
|
|
|
|
func (c FfiConverterFerretCotBufferManager) Write(writer io.Writer, value *FerretCotBufferManager) {
|
|
writeUint64(writer, uint64(uintptr(c.Lower(value))))
|
|
}
|
|
|
|
type FfiDestroyerFerretCotBufferManager struct{}
|
|
|
|
func (_ FfiDestroyerFerretCotBufferManager) Destroy(value *FerretCotBufferManager) {
|
|
value.Destroy()
|
|
}
|
|
|
|
type FerretCotManagerInterface interface {
|
|
GetBlockData(blockChoice uint8, index uint64) []uint8
|
|
RecvCot()
|
|
RecvRot()
|
|
SendCot()
|
|
SendRot()
|
|
SetBlockData(blockChoice uint8, index uint64, data []uint8)
|
|
}
|
|
type FerretCotManager struct {
|
|
ffiObject FfiObject
|
|
}
|
|
|
|
func (_self *FerretCotManager) GetBlockData(blockChoice uint8, index uint64) []uint8 {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
return FfiConverterSequenceUint8INSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
|
|
return GoRustBuffer{
|
|
inner: C.uniffi_ferret_fn_method_ferretcotmanager_get_block_data(
|
|
_pointer, FfiConverterUint8INSTANCE.Lower(blockChoice), FfiConverterUint64INSTANCE.Lower(index), _uniffiStatus),
|
|
}
|
|
}))
|
|
}
|
|
|
|
func (_self *FerretCotManager) RecvCot() {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotmanager_recv_cot(
|
|
_pointer, _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *FerretCotManager) RecvRot() {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotmanager_recv_rot(
|
|
_pointer, _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *FerretCotManager) SendCot() {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotmanager_send_cot(
|
|
_pointer, _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *FerretCotManager) SendRot() {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotmanager_send_rot(
|
|
_pointer, _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func (_self *FerretCotManager) SetBlockData(blockChoice uint8, index uint64, data []uint8) {
|
|
_pointer := _self.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer _self.ffiObject.decrementPointer()
|
|
rustCall(func(_uniffiStatus *C.RustCallStatus) bool {
|
|
C.uniffi_ferret_fn_method_ferretcotmanager_set_block_data(
|
|
_pointer, FfiConverterUint8INSTANCE.Lower(blockChoice), FfiConverterUint64INSTANCE.Lower(index), FfiConverterSequenceUint8INSTANCE.Lower(data), _uniffiStatus)
|
|
return false
|
|
})
|
|
}
|
|
func (object *FerretCotManager) Destroy() {
|
|
runtime.SetFinalizer(object, nil)
|
|
object.ffiObject.destroy()
|
|
}
|
|
|
|
type FfiConverterFerretCotManager struct{}
|
|
|
|
var FfiConverterFerretCotManagerINSTANCE = FfiConverterFerretCotManager{}
|
|
|
|
func (c FfiConverterFerretCotManager) Lift(pointer unsafe.Pointer) *FerretCotManager {
|
|
result := &FerretCotManager{
|
|
newFfiObject(
|
|
pointer,
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_clone_ferretcotmanager(pointer, status)
|
|
},
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
|
|
C.uniffi_ferret_fn_free_ferretcotmanager(pointer, status)
|
|
},
|
|
),
|
|
}
|
|
runtime.SetFinalizer(result, (*FerretCotManager).Destroy)
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterFerretCotManager) Read(reader io.Reader) *FerretCotManager {
|
|
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
|
|
}
|
|
|
|
func (c FfiConverterFerretCotManager) Lower(value *FerretCotManager) unsafe.Pointer {
|
|
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
|
|
// because the pointer will be decremented immediately after this function returns,
|
|
// and someone will be left holding onto a non-locked pointer.
|
|
pointer := value.ffiObject.incrementPointer("*FerretCotManager")
|
|
defer value.ffiObject.decrementPointer()
|
|
return pointer
|
|
|
|
}
|
|
|
|
func (c FfiConverterFerretCotManager) Write(writer io.Writer, value *FerretCotManager) {
|
|
writeUint64(writer, uint64(uintptr(c.Lower(value))))
|
|
}
|
|
|
|
type FfiDestroyerFerretCotManager struct{}
|
|
|
|
func (_ FfiDestroyerFerretCotManager) Destroy(value *FerretCotManager) {
|
|
value.Destroy()
|
|
}
|
|
|
|
type NetIoManagerInterface interface {
|
|
}
|
|
type NetIoManager struct {
|
|
ffiObject FfiObject
|
|
}
|
|
|
|
func (object *NetIoManager) Destroy() {
|
|
runtime.SetFinalizer(object, nil)
|
|
object.ffiObject.destroy()
|
|
}
|
|
|
|
type FfiConverterNetIoManager struct{}
|
|
|
|
var FfiConverterNetIoManagerINSTANCE = FfiConverterNetIoManager{}
|
|
|
|
func (c FfiConverterNetIoManager) Lift(pointer unsafe.Pointer) *NetIoManager {
|
|
result := &NetIoManager{
|
|
newFfiObject(
|
|
pointer,
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_clone_netiomanager(pointer, status)
|
|
},
|
|
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
|
|
C.uniffi_ferret_fn_free_netiomanager(pointer, status)
|
|
},
|
|
),
|
|
}
|
|
runtime.SetFinalizer(result, (*NetIoManager).Destroy)
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterNetIoManager) Read(reader io.Reader) *NetIoManager {
|
|
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
|
|
}
|
|
|
|
func (c FfiConverterNetIoManager) Lower(value *NetIoManager) unsafe.Pointer {
|
|
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
|
|
// because the pointer will be decremented immediately after this function returns,
|
|
// and someone will be left holding onto a non-locked pointer.
|
|
pointer := value.ffiObject.incrementPointer("*NetIoManager")
|
|
defer value.ffiObject.decrementPointer()
|
|
return pointer
|
|
|
|
}
|
|
|
|
func (c FfiConverterNetIoManager) Write(writer io.Writer, value *NetIoManager) {
|
|
writeUint64(writer, uint64(uintptr(c.Lower(value))))
|
|
}
|
|
|
|
type FfiDestroyerNetIoManager struct{}
|
|
|
|
func (_ FfiDestroyerNetIoManager) Destroy(value *NetIoManager) {
|
|
value.Destroy()
|
|
}
|
|
|
|
type FfiConverterOptionalString struct{}
|
|
|
|
var FfiConverterOptionalStringINSTANCE = FfiConverterOptionalString{}
|
|
|
|
func (c FfiConverterOptionalString) Lift(rb RustBufferI) *string {
|
|
return LiftFromRustBuffer[*string](c, rb)
|
|
}
|
|
|
|
func (_ FfiConverterOptionalString) Read(reader io.Reader) *string {
|
|
if readInt8(reader) == 0 {
|
|
return nil
|
|
}
|
|
temp := FfiConverterStringINSTANCE.Read(reader)
|
|
return &temp
|
|
}
|
|
|
|
func (c FfiConverterOptionalString) Lower(value *string) C.RustBuffer {
|
|
return LowerIntoRustBuffer[*string](c, value)
|
|
}
|
|
|
|
func (_ FfiConverterOptionalString) Write(writer io.Writer, value *string) {
|
|
if value == nil {
|
|
writeInt8(writer, 0)
|
|
} else {
|
|
writeInt8(writer, 1)
|
|
FfiConverterStringINSTANCE.Write(writer, *value)
|
|
}
|
|
}
|
|
|
|
type FfiDestroyerOptionalString struct{}
|
|
|
|
func (_ FfiDestroyerOptionalString) Destroy(value *string) {
|
|
if value != nil {
|
|
FfiDestroyerString{}.Destroy(*value)
|
|
}
|
|
}
|
|
|
|
type FfiConverterSequenceUint8 struct{}
|
|
|
|
var FfiConverterSequenceUint8INSTANCE = FfiConverterSequenceUint8{}
|
|
|
|
func (c FfiConverterSequenceUint8) Lift(rb RustBufferI) []uint8 {
|
|
return LiftFromRustBuffer[[]uint8](c, rb)
|
|
}
|
|
|
|
func (c FfiConverterSequenceUint8) Read(reader io.Reader) []uint8 {
|
|
length := readInt32(reader)
|
|
if length == 0 {
|
|
return nil
|
|
}
|
|
result := make([]uint8, 0, length)
|
|
for i := int32(0); i < length; i++ {
|
|
result = append(result, FfiConverterUint8INSTANCE.Read(reader))
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterSequenceUint8) Lower(value []uint8) C.RustBuffer {
|
|
return LowerIntoRustBuffer[[]uint8](c, value)
|
|
}
|
|
|
|
func (c FfiConverterSequenceUint8) Write(writer io.Writer, value []uint8) {
|
|
if len(value) > math.MaxInt32 {
|
|
panic("[]uint8 is too large to fit into Int32")
|
|
}
|
|
|
|
writeInt32(writer, int32(len(value)))
|
|
for _, item := range value {
|
|
FfiConverterUint8INSTANCE.Write(writer, item)
|
|
}
|
|
}
|
|
|
|
type FfiDestroyerSequenceUint8 struct{}
|
|
|
|
func (FfiDestroyerSequenceUint8) Destroy(sequence []uint8) {
|
|
for _, value := range sequence {
|
|
FfiDestroyerUint8{}.Destroy(value)
|
|
}
|
|
}
|
|
|
|
type FfiConverterSequenceBool struct{}
|
|
|
|
var FfiConverterSequenceBoolINSTANCE = FfiConverterSequenceBool{}
|
|
|
|
func (c FfiConverterSequenceBool) Lift(rb RustBufferI) []bool {
|
|
return LiftFromRustBuffer[[]bool](c, rb)
|
|
}
|
|
|
|
func (c FfiConverterSequenceBool) Read(reader io.Reader) []bool {
|
|
length := readInt32(reader)
|
|
if length == 0 {
|
|
return nil
|
|
}
|
|
result := make([]bool, 0, length)
|
|
for i := int32(0); i < length; i++ {
|
|
result = append(result, FfiConverterBoolINSTANCE.Read(reader))
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (c FfiConverterSequenceBool) Lower(value []bool) C.RustBuffer {
|
|
return LowerIntoRustBuffer[[]bool](c, value)
|
|
}
|
|
|
|
func (c FfiConverterSequenceBool) Write(writer io.Writer, value []bool) {
|
|
if len(value) > math.MaxInt32 {
|
|
panic("[]bool is too large to fit into Int32")
|
|
}
|
|
|
|
writeInt32(writer, int32(len(value)))
|
|
for _, item := range value {
|
|
FfiConverterBoolINSTANCE.Write(writer, item)
|
|
}
|
|
}
|
|
|
|
type FfiDestroyerSequenceBool struct{}
|
|
|
|
func (FfiDestroyerSequenceBool) Destroy(sequence []bool) {
|
|
for _, value := range sequence {
|
|
FfiDestroyerBool{}.Destroy(value)
|
|
}
|
|
}
|
|
|
|
func CreateBufferIoManager(initialCap int64) *BufferIoManager {
|
|
return FfiConverterBufferIoManagerINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_func_create_buffer_io_manager(FfiConverterInt64INSTANCE.Lower(initialCap), _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func CreateFerretCotBufferManager(party int32, threads int32, length uint64, choices []bool, bufferio *BufferIoManager, malicious bool) *FerretCotBufferManager {
|
|
return FfiConverterFerretCotBufferManagerINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_func_create_ferret_cot_buffer_manager(FfiConverterInt32INSTANCE.Lower(party), FfiConverterInt32INSTANCE.Lower(threads), FfiConverterUint64INSTANCE.Lower(length), FfiConverterSequenceBoolINSTANCE.Lower(choices), FfiConverterBufferIoManagerINSTANCE.Lower(bufferio), FfiConverterBoolINSTANCE.Lower(malicious), _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func CreateFerretCotManager(party int32, threads int32, length uint64, choices []bool, netio *NetIoManager, malicious bool) *FerretCotManager {
|
|
return FfiConverterFerretCotManagerINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_func_create_ferret_cot_manager(FfiConverterInt32INSTANCE.Lower(party), FfiConverterInt32INSTANCE.Lower(threads), FfiConverterUint64INSTANCE.Lower(length), FfiConverterSequenceBoolINSTANCE.Lower(choices), FfiConverterNetIoManagerINSTANCE.Lower(netio), FfiConverterBoolINSTANCE.Lower(malicious), _uniffiStatus)
|
|
}))
|
|
}
|
|
|
|
func CreateNetioManager(party int32, address *string, port int32) *NetIoManager {
|
|
return FfiConverterNetIoManagerINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
|
|
return C.uniffi_ferret_fn_func_create_netio_manager(FfiConverterInt32INSTANCE.Lower(party), FfiConverterOptionalStringINSTANCE.Lower(address), FfiConverterInt32INSTANCE.Lower(port), _uniffiStatus)
|
|
}))
|
|
}
|