Ejemplo n.º 1
0
 public bool add(SingleMessage x)                    //添加singleMessage x所包含的信息到包里
 {
     if (x.IFset())
     {
         SingleMessage y = new SingleMessage();
         y.message = new byte[x.message.Length];
         x.message.CopyTo(y.message, 0);
         components.Add(y);
         length = y.message.Length + intlength + length;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        public static byte[] TimeToByteArray(DateTime mTimeStamp)
        {
            List <byte> timeStamp = new List <byte>();

            byte[] secondsSinceEpoch = BitConverter.GetBytes((uint)(mTimeStamp - Epoch).TotalSeconds);
            byte[] fractionalSecond  = BitConverter.GetBytes((uint)((mTimeStamp - Epoch).Milliseconds));

            if (BitConverter.IsLittleEndian) // != OscPacket.LittleEndianByteOrder)
            {
                secondsSinceEpoch = SingleMessage.swapEndian(secondsSinceEpoch);
                fractionalSecond  = SingleMessage.swapEndian(fractionalSecond);
            }

            timeStamp.AddRange(secondsSinceEpoch);
            timeStamp.AddRange(fractionalSecond);

            return(timeStamp.ToArray());
        }
Ejemplo n.º 3
0
        //Add方法添加的singleMessage均通过深度复制添加到private List<SingleMessage> components里
        //待最后getMessage时一起转化为byte数组信息。

        public byte[] getMessage()                          //获得目前为止存储的总信息
        {
            time        = DateTime.Now;
            timeMessage = packTimeTag(time);
            length      = length + bundle.Length + timeMessage.Length;
            message     = new byte[length];
            byte[] intMessage;
            int    start = 0;

            bundle.CopyTo(message, start);
            start += bundle.Length;
            timeMessage.CopyTo(message, start);
            start += timeMessage.Length;
            foreach (SingleMessage x in components)
            {
                intMessage = SingleMessage.packInt(x.message.Length);
                intMessage.CopyTo(message, start);
                start += intlength;
                x.message.CopyTo(message, start);
                start += x.message.Length;
            }
            return(message);
        }