Beispiel #1
0
 public bool Equals(TimeTag obj)
 {
     return(obj != null && ReferenceEquals(this, obj));
 }
Beispiel #2
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 public TimeTag(TimeTag other)
 {
     Raw = other.Raw;
 }
Beispiel #3
0
        /// <summary>
        /// Parser function.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public bool Unpack(byte[] bytes)
        {
            try
            {
                int index = 0;
                Errors.Clear();
                Messages.Clear();

                // Parse marker.
                string marker = null;
                if (Unpack(bytes, ref index, ref marker))
                {
                    if (marker != BUNDLE_ID)
                    {
                        Errors.Add("Invalid marker string");
                    }
                }
                else
                {
                    Errors.Add("Invalid marker string");
                }

                // Parse timetag.
                ulong tt = 0;
                if (Unpack(bytes, ref index, ref tt))
                {
                    TimeTag = new TimeTag(tt);
                }
                else
                {
                    Errors.Add("Invalid timetag");
                }

                // Parse bundles and messages.
                List <Bundle> bundles = new List <Bundle>();

                while (index < bytes.Count() && Errors.Count == 0)
                {
                    if (bytes[index] == '#') // bundle?
                    {
                        Bundle b = new Bundle();
                        if (b.Unpack(bytes))
                        {
                            bundles.Add(b);
                        }
                        else
                        {
                            Errors.Add("Couldn't unpack bundle");
                        }
                    }
                    else // message?
                    {
                        Message m = new Message();
                        if (m.Unpack(bytes))
                        {
                            Messages.Add(m);
                        }
                        else
                        {
                            Errors.Add("Couldn't unpack message");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Add($"Exception while unpacking bundle: {ex.Message}");
            }

            return(Errors.Count == 0);
        }