Beispiel #1
0
        internal CtfClockDescriptor(CtfPropertyBag bag)
        {
            Debug.Assert(bag != null);

            this.Name = bag.GetString("name");

            if (bag.ContainsKey("uuid"))
            {
                string uuid = bag.GetString("uuid").Replace("\"", string.Empty);
                if (!Guid.TryParse(uuid, out var id))
                {
                    throw new ArgumentException($"Unable to parse the uuid value: {bag.GetString("uuid")}.");
                }

                this.Uuid = id;
            }

            this.Description = bag.GetString("description");

            // According to CTF specification 1.8.2 section 8, if the 'freq' field is not present,
            // it will default to 1 ns.
            this.Frequency = bag.ContainsKey("freq") ? bag.GetUlong("freq") : (ulong)1000000000;

            if (bag.ContainsKey("offset"))
            {
                this.Offset = bag.GetUlong("offset");
            }
            else if (bag.ContainsKey("offset_s"))
            {
                // todo:this might not be the best approach from an overflow perspective.
                // leaving for now until we have reason to change it
                ulong offsetInSeconds = bag.GetUlong("offset_s");
                this.Offset = offsetInSeconds * this.Frequency;
            }

            if (bag.ContainsKey("precision"))
            {
                this.Precision = bag.GetUlong("precision");
            }

            if (bag.ContainsKey("absolute"))
            {
                this.Absolute = bag.GetBoolean("absolute");
            }
        }
Beispiel #2
0
        internal CtfTraceDescriptor(CtfPropertyBag bag, ICtfStructDescriptor packetHeader)
        {
            Debug.Assert(bag != null);

            // According to CTF specification 1.8.2 section C.Examples."Minimal Examples", the packetHeader
            // isn't required if the entire trace consists of a single packet - so no null check here.

            // According to CTF specification 1.8.2 section C.Examples."Minimal Examples", the fields
            // "major", "minor", and "byte_order" are required.

            if (!bag.ContainsKey("major"))
            {
                throw new ArgumentException("Trace declaration does not contain 'major' field.");
            }

            if (!bag.ContainsKey("minor"))
            {
                throw new ArgumentException("Trace declaration does not contain 'major' field.");
            }

            if (!bag.ContainsKey("byte_order"))
            {
                throw new ArgumentException("Trace declaration does not contains 'byte_order' field.");
            }

            this.Major     = bag.GetShort("major");
            this.Minor     = bag.GetShort("minor");
            this.ByteOrder = bag.GetString("byte_order").Replace("\"", string.Empty);

            Guid id = Guid.Empty;

            if (bag.TryGetString("uuid", out string uuid))
            {
                uuid = uuid.Replace("\"", string.Empty);
                if (!Guid.TryParse(uuid, out id))
                {
                    throw new ArgumentException($"Unable to parse the uuid value: {bag.GetString("uuid")}.");
                }
            }
            this.Uuid = id;

            this.PacketHeader = packetHeader;
        }
        internal CtfIntegerDescriptor(CtfPropertyBag bag)
            : base(CtfTypes.Integer)
        {
            Debug.Assert(bag != null);

            // size is the only required field for an integer
            this.Size = bag.GetShort("size");
            if (this.Size <= 0)
            {
                throw new ArgumentException("An integer size must be greater than zero.");
            }

            this.SetAlignment(bag);
            this.SetSigned(bag);
            this.SetEncoding(bag);
            this.SetBase(bag);

            this.ByteOrder = bag.GetByteOrder();

            // there is no default for "map", as it is not defined in specification 1.82, but
            // examples show it referencing a clock name
            this.Map = bag.GetString("map");
        }
 private void SetEncoding(CtfPropertyBag bag)
 {
     // integers default to no encoding to specification 1.82 section 4.1.5
     this.Encoding = bag.GetString("encoding") ?? "none";
 }