//go:build wasip1

// Code generated by protoc-gen-go-plugin. DO NOT EDIT.
// versions:
// 	protoc-gen-go-plugin v0.1.0
// 	protoc               v5.29.3
// source: tests/fields/proto/fields.proto

package proto

import (
	context "context"
	emptypb "github.com/knqyf263/go-plugin/types/known/emptypb"
	wasm "github.com/knqyf263/go-plugin/wasm"
)

const FieldTestPluginAPIVersion = 1

//go:wasmexport field_test_api_version
func _field_test_api_version() uint64 {
	return FieldTestPluginAPIVersion
}

var fieldTest FieldTest

func RegisterFieldTest(p FieldTest) {
	fieldTest = p
}

//go:wasmexport field_test_test
func _field_test_test(ptr, size uint32) uint64 {
	b := wasm.PtrToByte(ptr, size)
	req := new(Request)
	if err := req.UnmarshalVT(b); err != nil {
		return 0
	}
	response, err := fieldTest.Test(context.Background(), req)
	if err != nil {
		ptr, size = wasm.ByteToPtr([]byte(err.Error()))
		return (uint64(ptr) << uint64(32)) | uint64(size) |
			// Indicate that this is the error string by setting the 32-th bit, assuming that
			// no data exceeds 31-bit size (2 GiB).
			(1 << 31)
	}

	b, err = response.MarshalVT()
	if err != nil {
		return 0
	}
	ptr, size = wasm.ByteToPtr(b)
	return (uint64(ptr) << uint64(32)) | uint64(size)
}

//go:wasmexport field_test_test_empty_input
func _field_test_test_empty_input(ptr, size uint32) uint64 {
	b := wasm.PtrToByte(ptr, size)
	req := new(emptypb.Empty)
	if err := req.UnmarshalVT(b); err != nil {
		return 0
	}
	response, err := fieldTest.TestEmptyInput(context.Background(), req)
	if err != nil {
		ptr, size = wasm.ByteToPtr([]byte(err.Error()))
		return (uint64(ptr) << uint64(32)) | uint64(size) |
			// Indicate that this is the error string by setting the 32-th bit, assuming that
			// no data exceeds 31-bit size (2 GiB).
			(1 << 31)
	}

	b, err = response.MarshalVT()
	if err != nil {
		return 0
	}
	ptr, size = wasm.ByteToPtr(b)
	return (uint64(ptr) << uint64(32)) | uint64(size)
}

//go:wasmexport field_test_test_error
func _field_test_test_error(ptr, size uint32) uint64 {
	b := wasm.PtrToByte(ptr, size)
	req := new(ErrorRequest)
	if err := req.UnmarshalVT(b); err != nil {
		return 0
	}
	response, err := fieldTest.TestError(context.Background(), req)
	if err != nil {
		ptr, size = wasm.ByteToPtr([]byte(err.Error()))
		return (uint64(ptr) << uint64(32)) | uint64(size) |
			// Indicate that this is the error string by setting the 32-th bit, assuming that
			// no data exceeds 31-bit size (2 GiB).
			(1 << 31)
	}

	b, err = response.MarshalVT()
	if err != nil {
		return 0
	}
	ptr, size = wasm.ByteToPtr(b)
	return (uint64(ptr) << uint64(32)) | uint64(size)
}
