12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- namespace OSC.NET
- {
- /// <summary>
- /// OSCBundle
- /// </summary>
- public class OSCBundle : OSCPacket
- {
- protected const string BUNDLE = "#bundle";
- private long timestamp = 0;
- public OSCBundle(long ts)
- {
- this.address = BUNDLE;
- this.timestamp = ts;
- }
- public OSCBundle()
- {
- this.address = BUNDLE;
- this.timestamp = 0;
- }
- public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
- {
- string address = unpackString(bytes, ref start);
- //Console.WriteLine("bundle: " + address);
- if (!address.Equals(BUNDLE)) return null; // TODO
- long timestamp = unpackLong(bytes, ref start);
- OSCBundle bundle = new OSCBundle(timestamp);
- while (start < end)
- {
- int length = unpackInt(bytes, ref start);
- int sub_end = start + length;
- //Console.WriteLine(bytes.Length +" "+ start+" "+length+" "+sub_end);
- bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end));
- }
- return bundle;
- }
- override public void Append(object value)
- {
- if (value is OSCPacket)
- {
- values.Add(value);
- }
- else
- {
- // TODO: exception
- }
- }
- public long getTimeStamp()
- {
- return timestamp;
- }
- override public bool IsBundle()
- {
- return true;
- }
- override protected void pack()
- {
- ArrayList data = new ArrayList();
- addBytes(data, packString(this.Address));
- padNull(data);
- addBytes(data, packLong(0)); // TODO
- foreach (object value in this.Values)
- {
- if (value is OSCPacket)
- {
- byte[] bs = ((OSCPacket)value).BinaryData;
- addBytes(data, packInt(bs.Length));
- addBytes(data, bs);
- }
- else
- {
- // TODO
- }
- }
- this.binaryData = (byte[])data.ToArray(typeof(byte));
- }
- }
- }
|