mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-18 21:13:57 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7c6da5c5b | |||
| 6f3a65322b | |||
| e34a589c5f | |||
| 41112d583b | |||
| 24a0501a4d |
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@@ -211,6 +212,12 @@ func send(host string, port int32, address string, args []string, types []string
|
|||||||
|
|
||||||
if slip {
|
if slip {
|
||||||
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
||||||
|
} else if protocol == "tcp" {
|
||||||
|
// OSC 1.0 prepends a 4 byte size header for non-SLIP TCP messages
|
||||||
|
size := uint32(len(oscMessageBuffer))
|
||||||
|
sizeBytes := make([]byte, 4)
|
||||||
|
binary.BigEndian.PutUint32(sizeBytes, size)
|
||||||
|
oscMessageBuffer = append(sizeBytes, oscMessageBuffer...)
|
||||||
}
|
}
|
||||||
|
|
||||||
netAddress := fmt.Sprintf("%s:%d", host, port)
|
netAddress := fmt.Sprintf("%s:%d", host, port)
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ module github.com/jwetzell/osc-go
|
|||||||
|
|
||||||
go 1.25.1
|
go 1.25.1
|
||||||
|
|
||||||
require github.com/urfave/cli/v3 v3.6.1
|
require github.com/urfave/cli/v3 v3.6.2
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
|
github.com/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8=
|
||||||
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ func (m *OSCMessage) ToBytes() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MessageFromBytes(bytes []byte) (OSCMessage, error) {
|
func MessageFromBytes(bytes []byte) (OSCMessage, error) {
|
||||||
|
if len(bytes) == 0 {
|
||||||
|
return OSCMessage{}, errors.New("cannot create OSC Message from empty byte array")
|
||||||
|
}
|
||||||
|
|
||||||
address, typeAndArgBytes := readOSCString(bytes)
|
address, typeAndArgBytes := readOSCString(bytes)
|
||||||
|
|
||||||
if address[0] != 47 {
|
if address[0] != 47 {
|
||||||
|
|||||||
@@ -174,17 +174,13 @@ func argsToBuffer(args []OSCArg) []byte {
|
|||||||
func readOSCString(bytes []byte) (string, []byte) {
|
func readOSCString(bytes []byte) (string, []byte) {
|
||||||
//TODO(jwetzell): add error handling
|
//TODO(jwetzell): add error handling
|
||||||
oscString := ""
|
oscString := ""
|
||||||
stringFinished := false
|
|
||||||
stringEndIndex := 0
|
stringEndIndex := 0
|
||||||
remainingBytes := []byte{}
|
|
||||||
|
|
||||||
for index, byteIn := range bytes {
|
for index, byteIn := range bytes {
|
||||||
if !stringFinished {
|
if byteIn == 0 {
|
||||||
if byteIn == 0 {
|
oscString = string(bytes[0:index])
|
||||||
oscString = string(bytes[0:index])
|
stringEndIndex = index + 1
|
||||||
stringEndIndex = index + 1
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +190,7 @@ func readOSCString(bytes []byte) (string, []byte) {
|
|||||||
stringEndIndex = stringEndIndex + stringPadding
|
stringEndIndex = stringEndIndex + stringPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
remainingBytes = bytes[stringEndIndex:]
|
remainingBytes := bytes[stringEndIndex:]
|
||||||
|
|
||||||
return oscString, remainingBytes
|
return oscString, remainingBytes
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user