navidrome/plugins/cmd/hostgen/testdata/counter_expected.go
Deluan de90e191bb feat(hostgen): add hostgen tool for generating Extism host function wrappers
- Implemented hostgen tool to generate wrappers from annotated Go interfaces.
- Added command-line flags for input/output directories and package name.
- Introduced parsing and code generation logic for host services.
- Created test data for various service interfaces and expected generated code.
- Added documentation for host services and annotations for code generation.
- Implemented SubsonicAPI service with corresponding generated code.
2025-12-31 17:06:28 -05:00

38 lines
985 B
Go

// Code generated by hostgen. DO NOT EDIT.
package testpkg
import (
"context"
extism "github.com/extism/go-sdk"
)
// RegisterCounterHostFunctions registers Counter service host functions.
// The returned host functions should be added to the plugin's configuration.
func RegisterCounterHostFunctions(service CounterService) []extism.HostFunction {
return []extism.HostFunction{
newCounterCountHostFunction(service),
}
}
func newCounterCountHostFunction(service CounterService) extism.HostFunction {
return extism.NewHostFunctionWithStack(
"counter_count",
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
// Read parameters from stack
name, err := p.ReadString(stack[0])
if err != nil {
return
}
// Call the service method
value := service.Count(ctx, name)
// Write return values to stack
stack[0] = extism.EncodeI32(value)
},
[]extism.ValueType{extism.ValueTypePTR},
[]extism.ValueType{extism.ValueTypeI32},
)
}