mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-13 02:53:38 +00:00
add method to parse bytes as packet
This commit is contained in:
@@ -350,3 +350,25 @@ func readOSCArg(bytes []byte, oscType string) (OSCArg, []byte, error) {
|
||||
}
|
||||
return oscArg, remainingBytes, readArgError
|
||||
}
|
||||
|
||||
func PacketFromBytes(bytes []byte) (OSCPacket, []byte, error) {
|
||||
if len(bytes) == 0 {
|
||||
return nil, bytes, errors.New("cannot create OSC Packet from empty byte array")
|
||||
}
|
||||
|
||||
if bytes[0] == '#' {
|
||||
bundle, remainingBytes, err := BundleFromBytes(bytes)
|
||||
if err != nil {
|
||||
return nil, bytes, err
|
||||
}
|
||||
return bundle, remainingBytes, nil
|
||||
} else if bytes[0] == '/' {
|
||||
message, err := MessageFromBytes(bytes)
|
||||
if err != nil {
|
||||
return nil, bytes, err
|
||||
}
|
||||
return message, []byte{}, nil
|
||||
} else {
|
||||
return nil, bytes, errors.New("OSC Packet must start with # for bundle or / for message")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user