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

45 lines
1.1 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"
"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
}
return &response, nil
}