add error handling to arg encoding and message/bundle ToBytes()

This commit is contained in:
Joel Wetzell
2026-04-13 18:38:25 -05:00
parent 1130adf046
commit 4744321d71
9 changed files with 169 additions and 62 deletions
+17 -6
View File
@@ -4,21 +4,32 @@ import (
"errors"
)
func (b *OSCBundle) ToBytes() []byte {
func (b *OSCBundle) ToBytes() ([]byte, error) {
bytes := stringToOSCBytes("#bundle")
bytes = append(bytes, timeTagToOSCBytes(b.TimeTag)...)
timeTagBytes, err := timeTagToOSCBytes(b.TimeTag)
if err != nil {
return nil, err
}
bytes = append(bytes, timeTagBytes...)
for _, packet := range b.Contents {
packetBytes := packet.ToBytes()
packetLength := len(packet.ToBytes())
packetBytes, err := packet.ToBytes()
if err != nil {
return nil, err
}
packetLength := len(packetBytes)
bytes = append(bytes, int32ToOSCBytes(int32(packetLength))...)
packetLengthBytes, err := int32ToOSCBytes(int32(packetLength))
if err != nil {
return nil, err
}
bytes = append(bytes, packetLengthBytes...)
bytes = append(bytes, packetBytes...)
}
return bytes
return bytes, nil
}
func BundleFromBytes(bytes []byte) (*OSCBundle, []byte, error) {