mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-14 03:13:38 +00:00
add handling for blob type (b)
This commit is contained in:
+33
@@ -56,6 +56,23 @@ func floatToOSCBytes(number float32) []byte {
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func byteArrayToOSCBytes(bytes []byte) []byte {
|
||||
oscBytes := []byte{}
|
||||
|
||||
bytesSize := len(bytes)
|
||||
oscBytes = append(oscBytes, integerToOSCBytes(int32(bytesSize))...)
|
||||
oscBytes = append(oscBytes, bytes...)
|
||||
|
||||
padLength := 4 - (bytesSize % 4)
|
||||
if padLength < 4 {
|
||||
for i := 0; i < padLength; i++ {
|
||||
oscBytes = append(oscBytes, 0)
|
||||
}
|
||||
}
|
||||
|
||||
return oscBytes
|
||||
}
|
||||
|
||||
func argsToBuffer(args []OSCArg) []byte {
|
||||
var argBuffers = []byte{}
|
||||
|
||||
@@ -79,6 +96,12 @@ func argsToBuffer(args []OSCArg) []byte {
|
||||
} else {
|
||||
fmt.Println("OSC arg had float type but non-float value.")
|
||||
}
|
||||
case "b":
|
||||
if value, ok := arg.Value.([]byte); ok {
|
||||
argBuffers = append(argBuffers, byteArrayToOSCBytes(value)...)
|
||||
} else {
|
||||
fmt.Println("OSC arg had blob type but non-blob value.")
|
||||
}
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
@@ -161,6 +184,16 @@ func argToTypedArg(rawArg string, oscType string) OSCArg {
|
||||
Type: "f",
|
||||
Value: float32(number),
|
||||
}
|
||||
case "b":
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return OSCArg{
|
||||
Type: "b",
|
||||
Value: data,
|
||||
}
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
|
||||
Reference in New Issue
Block a user