// Code generated by ndpgen. DO NOT EDIT.package testpkgimport ("context""encoding/json"extism "github.com/extism/go-sdk")// StoreSaveRequest is the request type for Store.Save.type StoreSaveRequest struct {Item Item `json:"item"`}// StoreSaveResponse is the response type for Store.Save.type StoreSaveResponse struct {Id string `json:"id,omitempty"`Error string `json:"error,omitempty"`}// RegisterStoreHostFunctions registers Store service host functions.// The returned host functions should be added to the plugin's configuration.func RegisterStoreHostFunctions(service StoreService) []extism.HostFunction {return []extism.HostFunction{newStoreSaveHostFunction(service),}}func newStoreSaveHostFunction(service StoreService) extism.HostFunction {return extism.NewHostFunctionWithStack("store_save",func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {// Read JSON request from plugin memoryreqBytes, err := p.ReadBytes(stack[0])if err != nil {storeWriteError(p, stack, err)return}var req StoreSaveRequestif err := json.Unmarshal(reqBytes, &req); err != nil {storeWriteError(p, stack, err)return}// Call the service methodid, svcErr := service.Save(ctx, req.Item)if svcErr != nil {storeWriteError(p, stack, svcErr)return}// Write JSON response to plugin memoryresp := StoreSaveResponse{Id: id,}storeWriteResponse(p, stack, resp)},[]extism.ValueType{extism.ValueTypePTR},[]extism.ValueType{extism.ValueTypePTR},)}// storeWriteResponse writes a JSON response to plugin memory.func storeWriteResponse(p *extism.CurrentPlugin, stack []uint64, resp any) {respBytes, err := json.Marshal(resp)if err != nil {storeWriteError(p, stack, err)return}respPtr, err := p.WriteBytes(respBytes)if err != nil {stack[0] = 0return}stack[0] = respPtr}// storeWriteError writes an error response to plugin memory.func storeWriteError(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}