mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-05 15:23:38 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7c6da5c5b | |||
| 6f3a65322b | |||
| e34a589c5f | |||
| 41112d583b | |||
| 24a0501a4d | |||
| e06a0a2776 | |||
| d1696baa31 | |||
| c0304bf7a6 | |||
| d62d65c386 | |||
| f2888cc038 | |||
| 24077a77d6 | |||
| 9e515cc28e |
@@ -36,7 +36,7 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -147,9 +147,9 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
for _, byteToEncode := range bytes {
|
||||
if byteToEncode == END {
|
||||
encodedBytes = append(encodedBytes, ESC_END)
|
||||
encodedBytes = append(encodedBytes, ESC, ESC_END)
|
||||
} else if byteToEncode == ESC {
|
||||
encodedBytes = append(encodedBytes, ESC_ESC)
|
||||
encodedBytes = append(encodedBytes, ESC, ESC_ESC)
|
||||
} else {
|
||||
encodedBytes = append(encodedBytes, byteToEncode)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -177,9 +178,9 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
for _, byteToEncode := range bytes {
|
||||
if byteToEncode == END {
|
||||
encodedBytes = append(encodedBytes, ESC_END)
|
||||
encodedBytes = append(encodedBytes, ESC, ESC_END)
|
||||
} else if byteToEncode == ESC {
|
||||
encodedBytes = append(encodedBytes, ESC_ESC)
|
||||
encodedBytes = append(encodedBytes, ESC, ESC_ESC)
|
||||
} else {
|
||||
encodedBytes = append(encodedBytes, byteToEncode)
|
||||
}
|
||||
@@ -211,6 +212,12 @@ func send(host string, port int32, address string, args []string, types []string
|
||||
|
||||
if slip {
|
||||
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)
|
||||
|
||||
@@ -2,4 +2,4 @@ module github.com/jwetzell/osc-go
|
||||
|
||||
go 1.25.1
|
||||
|
||||
require github.com/urfave/cli/v3 v3.4.1
|
||||
require github.com/urfave/cli/v3 v3.6.2
|
||||
|
||||
@@ -2,9 +2,9 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
|
||||
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
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/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8=
|
||||
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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -26,6 +26,10 @@ func (m *OSCMessage) ToBytes() []byte {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
if address[0] != 47 {
|
||||
|
||||
@@ -174,17 +174,13 @@ func argsToBuffer(args []OSCArg) []byte {
|
||||
func readOSCString(bytes []byte) (string, []byte) {
|
||||
//TODO(jwetzell): add error handling
|
||||
oscString := ""
|
||||
stringFinished := false
|
||||
stringEndIndex := 0
|
||||
remainingBytes := []byte{}
|
||||
|
||||
for index, byteIn := range bytes {
|
||||
if !stringFinished {
|
||||
if byteIn == 0 {
|
||||
oscString = string(bytes[0:index])
|
||||
stringEndIndex = index + 1
|
||||
break
|
||||
}
|
||||
if byteIn == 0 {
|
||||
oscString = string(bytes[0:index])
|
||||
stringEndIndex = index + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +190,7 @@ func readOSCString(bytes []byte) (string, []byte) {
|
||||
stringEndIndex = stringEndIndex + stringPadding
|
||||
}
|
||||
|
||||
remainingBytes = bytes[stringEndIndex:]
|
||||
remainingBytes := bytes[stringEndIndex:]
|
||||
|
||||
return oscString, remainingBytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user