mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-31 11:09:00 +00:00
return pointers from byte parsing
This commit is contained in:
@@ -21,25 +21,25 @@ func (b *OSCBundle) ToBytes() []byte {
|
||||
return bytes
|
||||
}
|
||||
|
||||
func BundleFromBytes(bytes []byte) (OSCBundle, []byte, error) {
|
||||
func BundleFromBytes(bytes []byte) (*OSCBundle, []byte, error) {
|
||||
if len(bytes) < 20 {
|
||||
return OSCBundle{}, bytes, errors.New("bundle has to be at least 20 bytes")
|
||||
return nil, bytes, errors.New("bundle has to be at least 20 bytes")
|
||||
}
|
||||
|
||||
if bytes[0] != 35 {
|
||||
return OSCBundle{}, bytes, errors.New("bundle must start with a #")
|
||||
return nil, bytes, errors.New("bundle must start with a #")
|
||||
}
|
||||
|
||||
bundleHeader, bytesAfterBundleHeader := readOSCString(bytes)
|
||||
|
||||
if bundleHeader != "#bundle" {
|
||||
return OSCBundle{}, bytesAfterBundleHeader, errors.New("bundle must start with #bundle string")
|
||||
return nil, bytesAfterBundleHeader, errors.New("bundle must start with #bundle string")
|
||||
}
|
||||
|
||||
timeTag, bytesAfterTimeTag, err := readOSCTimeTag(bytesAfterBundleHeader)
|
||||
|
||||
if err != nil {
|
||||
return OSCBundle{}, bytesAfterBundleHeader, err
|
||||
return nil, bytesAfterBundleHeader, err
|
||||
}
|
||||
|
||||
bundleContents := []OSCPacket{}
|
||||
@@ -52,13 +52,13 @@ func BundleFromBytes(bytes []byte) (OSCBundle, []byte, error) {
|
||||
contentSize, bytesAfterContentSize, err := readOSCInt32(remainingBytes)
|
||||
|
||||
if err != nil {
|
||||
return OSCBundle{}, remainingBytes, err
|
||||
return nil, remainingBytes, err
|
||||
}
|
||||
|
||||
remainingBytes = bytesAfterContentSize
|
||||
|
||||
if len(remainingBytes) < int(contentSize) {
|
||||
return OSCBundle{}, remainingBytes, errors.New("bundle doesn't have enough bytes for the content size it specifies")
|
||||
return nil, remainingBytes, errors.New("bundle doesn't have enough bytes for the content size it specifies")
|
||||
}
|
||||
|
||||
bundleContentBytes := remainingBytes[0:contentSize]
|
||||
@@ -66,17 +66,17 @@ func BundleFromBytes(bytes []byte) (OSCBundle, []byte, error) {
|
||||
if bundleContentBytes[0] == 35 {
|
||||
content, _, err := BundleFromBytes(bundleContentBytes)
|
||||
if err != nil {
|
||||
return OSCBundle{}, remainingBytes, err
|
||||
return nil, remainingBytes, err
|
||||
}
|
||||
bundleContents = append(bundleContents, &content)
|
||||
bundleContents = append(bundleContents, content)
|
||||
} else if bundleContentBytes[0] == 47 {
|
||||
content, err := MessageFromBytes(bundleContentBytes)
|
||||
if err != nil {
|
||||
return OSCBundle{}, remainingBytes, err
|
||||
return nil, remainingBytes, err
|
||||
}
|
||||
bundleContents = append(bundleContents, &content)
|
||||
bundleContents = append(bundleContents, content)
|
||||
} else {
|
||||
return OSCBundle{}, remainingBytes, errors.New("bundle contents does not look a bundle or message")
|
||||
return nil, remainingBytes, errors.New("bundle contents does not look a bundle or message")
|
||||
}
|
||||
remainingBytes = bytesAfterContentSize[contentSize:]
|
||||
if len(remainingBytes) == 0 {
|
||||
@@ -85,7 +85,7 @@ func BundleFromBytes(bytes []byte) (OSCBundle, []byte, error) {
|
||||
|
||||
}
|
||||
|
||||
return OSCBundle{
|
||||
return &OSCBundle{
|
||||
TimeTag: timeTag,
|
||||
Contents: bundleContents,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user