private void ReadMessages( ArraySegment <byte> buffer, OscReader reader, int count, List <OscMessageRaw> messages, out OscTimeTag timestamp) { int start = reader.Position; int bundleEnd = start + count; reader.BeginBundle(count); string ident = reader.ReadAddress(); if (OscBundle.BundleIdent.Equals(ident, StringComparison.Ordinal) == false) { // this is an error throw new OscException(OscError.InvalidBundleIdent, $"Invalid bundle ident '{ident}'"); } timestamp = reader.ReadBundleTimeTag(); while (reader.Position < bundleEnd) { if (reader.Position + 4 > bundleEnd) { // this is an error throw new OscException(OscError.InvalidBundleMessageHeader, "Invalid bundle message header"); } int messageLength = reader.ReadBundleMessageLength(start, count); if (reader.Position + messageLength > bundleEnd || messageLength < 0 || messageLength % 4 != 0) { // this is an error throw new OscException(OscError.InvalidBundleMessageLength, "Invalid bundle message length"); } if (reader.PeekByte() == (byte)'#') { ReadMessages(buffer, reader, messageLength, messages, out OscTimeTag _); } else { messages.Add(new OscMessageRaw(new ArraySegment <byte>(buffer.Array, buffer.Offset + reader.Position, messageLength), Origin, timestamp)); reader.Position += messageLength; } } }
public static OscPacket Read( OscReader reader, int count, Uri origin = null, OscTimeTag?timeTag = null) { if (reader.PeekByte() == (byte)'#') { return(OscBundle.Read(reader, count, origin)); } return(OscMessage.Read(reader, count, origin, timeTag)); }