mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-02 06:24:14 +00:00
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
// Code generated by hostgen. DO NOT EDIT.
|
|
//
|
|
// This file contains client wrappers for the Math host service.
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
|
//
|
|
//go:build wasip1
|
|
|
|
package ndhost
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/extism/go-pdk"
|
|
)
|
|
|
|
// math_add is the host function provided by Navidrome.
|
|
//
|
|
//go:wasmimport extism:host/user math_add
|
|
func math_add(uint64) uint64
|
|
|
|
// MathAddRequest is the request type for Math.Add.
|
|
type MathAddRequest struct {
|
|
A int32 `json:"a"`
|
|
B int32 `json:"b"`
|
|
}
|
|
|
|
// MathAddResponse is the response type for Math.Add.
|
|
type MathAddResponse struct {
|
|
Result int32 `json:"result,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// MathAdd calls the math_add host function.
|
|
func MathAdd(a int32, b int32) (*MathAddResponse, error) {
|
|
// Marshal request to JSON
|
|
req := MathAddRequest{
|
|
A: a,
|
|
B: b,
|
|
}
|
|
reqBytes, err := json.Marshal(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reqMem := pdk.AllocateBytes(reqBytes)
|
|
defer reqMem.Free()
|
|
|
|
// Call the host function
|
|
responsePtr := math_add(reqMem.Offset())
|
|
|
|
// Read the response from memory
|
|
responseMem := pdk.FindMemory(responsePtr)
|
|
responseBytes := responseMem.ReadBytes()
|
|
|
|
// Parse the response
|
|
var response MathAddResponse
|
|
if err := json.Unmarshal(responseBytes, &response); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Convert Error field to Go error
|
|
if response.Error != "" {
|
|
return nil, errors.New(response.Error)
|
|
}
|
|
|
|
return &response, nil
|
|
}
|