navidrome/plugins/cmd/hostgen/testdata/codec_client_expected.go
2025-12-31 17:06:32 -05:00

66 lines
1.5 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.
//
//go:build wasip1
package ndhost
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
// CodecEncodeRequest is the request type for Codec.Encode.
type CodecEncodeRequest struct {
Data []byte `json:"data"`
}
// 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) {
// Marshal request to JSON
req := CodecEncodeRequest{
Data: data,
}
reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
reqMem := pdk.AllocateBytes(reqBytes)
defer reqMem.Free()
// Call the host function
responsePtr := codec_encode(reqMem.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
}
// Convert Error field to Go error
if response.Error != "" {
return nil, errors.New(response.Error)
}
return &response, nil
}