57 lines
1.2 KiB
Text
57 lines
1.2 KiB
Text
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains client wrappers for the Counter host service.
|
||
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
||
|
|
//
|
||
|
|
//go:build wasip1
|
||
|
|
|
||
|
|
package ndhost
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
|
||
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
// counter_count is the host function provided by Navidrome.
|
||
|
|
//
|
||
|
|
//go:wasmimport extism:host/user counter_count
|
||
|
|
func counter_count(uint64) uint64
|
||
|
|
|
||
|
|
type counterCountRequest struct {
|
||
|
|
Name string `json:"name"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type counterCountResponse struct {
|
||
|
|
Value int32 `json:"value,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// CounterCount calls the counter_count host function.
|
||
|
|
func CounterCount(name string) int32 {
|
||
|
|
// Marshal request to JSON
|
||
|
|
req := counterCountRequest{
|
||
|
|
Name: name,
|
||
|
|
}
|
||
|
|
reqBytes, err := json.Marshal(req)
|
||
|
|
if err != nil {
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
reqMem := pdk.AllocateBytes(reqBytes)
|
||
|
|
defer reqMem.Free()
|
||
|
|
|
||
|
|
// Call the host function
|
||
|
|
responsePtr := counter_count(reqMem.Offset())
|
||
|
|
|
||
|
|
// Read the response from memory
|
||
|
|
responseMem := pdk.FindMemory(responsePtr)
|
||
|
|
responseBytes := responseMem.ReadBytes()
|
||
|
|
|
||
|
|
// Parse the response
|
||
|
|
var response counterCountResponse
|
||
|
|
if err := json.Unmarshal(responseBytes, &response); err != nil {
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.Value
|
||
|
|
}
|