// Code generated by ndpgen. DO NOT EDIT.package testpkgimport ("context""encoding/json"extism "github.com/extism/go-sdk")// MetaGetRequest is the request type for Meta.Get.type MetaGetRequest struct {Key string `json:"key"`}// MetaGetResponse is the response type for Meta.Get.type MetaGetResponse struct {Value any `json:"value,omitempty"`Error string `json:"error,omitempty"`}// MetaSetRequest is the request type for Meta.Set.type MetaSetRequest struct {Data map[string]any `json:"data"`}// MetaSetResponse is the response type for Meta.Set.type MetaSetResponse struct {Error string `json:"error,omitempty"`}// RegisterMetaHostFunctions registers Meta service host functions.// The returned host functions should be added to the plugin's configuration.func RegisterMetaHostFunctions(service MetaService) []extism.HostFunction {return []extism.HostFunction{newMetaGetHostFunction(service),newMetaSetHostFunction(service),}}func newMetaGetHostFunction(service MetaService) extism.HostFunction {return extism.NewHostFunctionWithStack("meta_get",func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {// Read JSON request from plugin memoryreqBytes, err := p.ReadBytes(stack[0])if err != nil {metaWriteError(p, stack, err)return}var req MetaGetRequestif err := json.Unmarshal(reqBytes, &req); err != nil {metaWriteError(p, stack, err)return}// Call the service methodvalue, svcErr := service.Get(ctx, req.Key)if svcErr != nil {metaWriteError(p, stack, svcErr)return}// Write JSON response to plugin memoryresp := MetaGetResponse{Value: value,}metaWriteResponse(p, stack, resp)},[]extism.ValueType{extism.ValueTypePTR},[]extism.ValueType{extism.ValueTypePTR},)}func newMetaSetHostFunction(service MetaService) extism.HostFunction {return extism.NewHostFunctionWithStack("meta_set",func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {// Read JSON request from plugin memoryreqBytes, err := p.ReadBytes(stack[0])if err != nil {metaWriteError(p, stack, err)return}var req MetaSetRequestif err := json.Unmarshal(reqBytes, &req); err != nil {metaWriteError(p, stack, err)return}// Call the service methodif svcErr := service.Set(ctx, req.Data); svcErr != nil {metaWriteError(p, stack, svcErr)return}// Write JSON response to plugin memoryresp := MetaSetResponse{}metaWriteResponse(p, stack, resp)},[]extism.ValueType{extism.ValueTypePTR},[]extism.ValueType{extism.ValueTypePTR},)}// metaWriteResponse writes a JSON response to plugin memory.func metaWriteResponse(p *extism.CurrentPlugin, stack []uint64, resp any) {respBytes, err := json.Marshal(resp)if err != nil {metaWriteError(p, stack, err)return}respPtr, err := p.WriteBytes(respBytes)if err != nil {stack[0] = 0return}stack[0] = respPtr}// metaWriteError writes an error response to plugin memory.func metaWriteError(p *extism.CurrentPlugin, stack []uint64, err error) {errResp := struct {Error string `json:"error"`}{Error: err.Error()}respBytes, _ := json.Marshal(errResp)respPtr, _ := p.WriteBytes(respBytes)stack[0] = respPtr}