github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/types/to_binary.go (about) 1 package types 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/runtime/core" 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 ) 9 10 // ToBinary takes an input value of any type and converts it into a binary value. 11 // @param {Any} value - Input value of arbitrary type. 12 // @return {Binary} - A binary value. 13 func ToBinary(_ context.Context, args ...core.Value) (core.Value, error) { 14 err := core.ValidateArgs(args, 1, 1) 15 16 if err != nil { 17 return values.None, err 18 } 19 20 val := args[0].String() 21 22 return values.NewBinary([]byte(val)), nil 23 }