//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/well-known/proto/known.proto

package proto

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

const KnownTypesTestPluginAPIVersion = 1

//go:wasmexport known_types_test_api_version
func _known_types_test_api_version() uint64 {
	return KnownTypesTestPluginAPIVersion
}

var knownTypesTest KnownTypesTest

func RegisterKnownTypesTest(p KnownTypesTest) {
	knownTypesTest = p
}

//go:wasmexport known_types_test_test
func _known_types_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 := knownTypesTest.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)
}

const EmptyTestPluginAPIVersion = 1

//go:wasmexport empty_test_api_version
func _empty_test_api_version() uint64 {
	return EmptyTestPluginAPIVersion
}

var emptyTest EmptyTest

func RegisterEmptyTest(p EmptyTest) {
	emptyTest = p
}

//go:wasmexport empty_test_do_nothing
func _empty_test_do_nothing(ptr, size uint32) uint64 {
	b := wasm.PtrToByte(ptr, size)
	req := new(emptypb.Empty)
	if err := req.UnmarshalVT(b); err != nil {
		return 0
	}
	response, err := emptyTest.DoNothing(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)
}
