Compare commits

..

1 Commits

Author SHA1 Message Date
Joel Wetzell a117f668fa remove all fmt.println from receiveosc 2026-02-04 11:41:25 -06:00
4 changed files with 31 additions and 50 deletions
+1 -5
View File
@@ -30,11 +30,7 @@ func BundleFromBytes(bytes []byte) (*OSCBundle, []byte, error) {
return nil, bytes, errors.New("bundle must start with a #")
}
bundleHeader, bytesAfterBundleHeader, err := readOSCString(bytes)
if err != nil {
return nil, bytes, err
}
bundleHeader, bytesAfterBundleHeader := readOSCString(bytes)
if bundleHeader != "#bundle" {
return nil, bytesAfterBundleHeader, errors.New("bundle must start with #bundle string")
+5 -6
View File
@@ -88,7 +88,7 @@ func main() {
func listenTCP(netAddress string, useSLIP bool, format string) {
socket, err := net.Listen("tcp4", netAddress)
if err != nil {
fmt.Println(err)
// TODO(jwetzell): output error properly
return
}
@@ -97,7 +97,7 @@ func listenTCP(netAddress string, useSLIP bool, format string) {
for {
conn, err := socket.Accept()
if err != nil {
fmt.Println(err)
// TODO(jwetzell): output error properly
continue
}
go handleTCPConnection(conn, useSLIP, format)
@@ -185,9 +185,8 @@ func handlePacket(message osc.OSCPacket, format string) {
handleBundle(bundle, format)
} else if msg, ok := message.(*osc.OSCMessage); ok {
handleMessage(msg, format)
} else {
fmt.Println("Received unknown OSC Packet type")
}
// TODO(jwetzell): handle other packet types?
}
func handleMessage(message *osc.OSCMessage, format string) {
@@ -209,13 +208,13 @@ func listenUDP(netAddress string, format string) {
s, err := net.ResolveUDPAddr("udp4", netAddress)
if err != nil {
fmt.Println(err)
// TODO(jwetzell): output error properly
return
}
connection, err := net.ListenUDP("udp4", s)
if err != nil {
fmt.Println(err)
// TODO(jwetzell): output error properly
return
}
+4 -11
View File
@@ -29,14 +29,11 @@ func MessageFromBytes(bytes []byte) (*OSCMessage, error) {
if len(bytes) == 0 {
return nil, errors.New("cannot create OSC Message from empty byte array")
}
if bytes[0] != 47 {
return nil, errors.New("OSC Message must start with /")
}
address, typeAndArgBytes, err := readOSCString(bytes)
address, typeAndArgBytes := readOSCString(bytes)
if err != nil {
return nil, err
if address[0] != 47 {
return nil, errors.New("OSC Message address must start with /")
}
oscMessage := OSCMessage{
@@ -44,11 +41,7 @@ func MessageFromBytes(bytes []byte) (*OSCMessage, error) {
Args: []OSCArg{},
}
typeString, argBytes, err := readOSCString(typeAndArgBytes)
if err != nil {
return nil, err
}
typeString, argBytes := readOSCString(typeAndArgBytes)
for index, oscType := range typeString {
if index == 0 {
+21 -28
View File
@@ -171,7 +171,7 @@ func argsToBuffer(args []OSCArg) []byte {
return argBuffers
}
func readOSCString(bytes []byte) (string, []byte, error) {
func readOSCString(bytes []byte) (string, []byte) {
//TODO(jwetzell): add error handling
oscString := ""
stringEndIndex := 0
@@ -190,13 +190,9 @@ func readOSCString(bytes []byte) (string, []byte, error) {
stringEndIndex = stringEndIndex + stringPadding
}
if stringEndIndex > len(bytes) {
return "", bytes, errors.New("string data is not properly padded")
}
remainingBytes := bytes[stringEndIndex:]
return oscString, remainingBytes, nil
return oscString, remainingBytes
}
func readOSCInt32(bytes []byte) (int32, []byte, error) {
@@ -291,30 +287,27 @@ func readOSCArg(bytes []byte, oscType string) (OSCArg, []byte, error) {
//TODO(jwetzell): add error handling
switch oscType {
case "s":
argString, bytesLeft, err := readOSCString(bytes)
if err != nil {
return OSCArg{}, bytes, err
}
argString, bytesLeft := readOSCString(bytes)
oscArg.Value = argString
remainingBytes = bytesLeft
case "i":
argInt, bytesLeft, err := readOSCInt32(bytes)
if err != nil {
readArgError = err
argInt, bytesLeft, error := readOSCInt32(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argInt
remainingBytes = bytesLeft
case "f":
argFloat, bytesLeft, err := readOSCFloat32(bytes)
if err != nil {
readArgError = err
argFloat, bytesLeft, error := readOSCFloat32(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argFloat
remainingBytes = bytesLeft
case "b":
argBytes, bytesLeft, err := readOSCBlob(bytes)
if err != nil {
readArgError = err
argBytes, bytesLeft, error := readOSCBlob(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argBytes
remainingBytes = bytesLeft
@@ -331,23 +324,23 @@ func readOSCArg(bytes []byte, oscType string) (OSCArg, []byte, error) {
oscArg.Value = math.MaxInt32
remainingBytes = bytes
case "r":
argColor, bytesLeft, err := readOSCColor(bytes)
if err != nil {
readArgError = err
argColor, bytesLeft, error := readOSCColor(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argColor
remainingBytes = bytesLeft
case "h":
argInt, bytesLeft, err := readOSCInt64(bytes)
if err != nil {
readArgError = err
argInt, bytesLeft, error := readOSCInt64(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argInt
remainingBytes = bytesLeft
case "d":
argFloat, bytesLeft, err := readOSCFloat64(bytes)
if err != nil {
readArgError = err
argFloat, bytesLeft, error := readOSCFloat64(bytes)
if error != nil {
readArgError = error
}
oscArg.Value = argFloat
remainingBytes = bytesLeft