navidrome/plugins/cmd/hostgen/testdata/codec_client_expected.go
Deluan ba27a8ceef feat(plugins): generate client wrappers for host functions
Signed-off-by: Deluan <deluan@navidrome.org>
2025-12-31 17:06:28 -05:00

50 lines
1.2 KiB
Go

// Code generated by hostgen. DO NOT EDIT.
//
// This file contains client wrappers for the Codec host service.
// It is intended for use in Navidrome plugins built with TinyGo.
package main
import (
"encoding/json"
"errors"
"github.com/extism/go-pdk"
)
// codec_encode is the host function provided by Navidrome.
//
//go:wasmimport extism:host/user codec_encode
func codec_encode(uint64) uint64
// CodecEncodeResponse is the response type for Codec.Encode.
type CodecEncodeResponse struct {
Result []byte `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
// CodecEncode calls the codec_encode host function.
func CodecEncode(data []byte) (*CodecEncodeResponse, error) {
dataMem := pdk.AllocateBytes(data)
defer dataMem.Free()
// Call the host function
responsePtr := codec_encode(dataMem.Offset())
// Read the response from memory
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
// Parse the response
var response CodecEncodeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
if response.Error != "" {
return nil, errors.New(response.Error)
}
return &response, nil
}