internal CtfStringDescriptor(CtfPropertyBag bag) : base(CtfTypes.String) { Debug.Assert(bag != null); this.SetEncoding(bag); }
public void NamedEnumTest10() { const string typeName = "EnumType1"; const bool baseTypeSigned = false; const ushort baseTypeSize = 5; var integerProperties = new CtfPropertyBag(); integerProperties.AddValue("size", baseTypeSize.ToString()); integerProperties.AddValue("signed", baseTypeSigned.ToString()); var mappings = new List <EnumeratorTestValue> { new EnumeratorTestValue { Name = "enum", AddComma = true, StartValue = 2 }, new EnumeratorTestValue { Name = "trace", StartValue = 3, ValueSpecified = false }, }; NamedEnumTest(typeName, baseTypeSigned, baseTypeSize, mappings); }
public void NamedEnumTest2() { const string typeName = "EnumType1"; const bool baseTypeSigned = false; const ushort baseTypeSize = 5; var integerProperties = new CtfPropertyBag(); integerProperties.AddValue("size", baseTypeSize.ToString()); integerProperties.AddValue("signed", baseTypeSigned.ToString()); var mappings = new List <EnumeratorTestValue> { new EnumeratorTestValue { Name = "identifier_one", StartValue = 5, AddComma = true }, new EnumeratorTestValue { Name = "identifier_two", StartValue = 6 }, }; NamedEnumTest(typeName, baseTypeSigned, baseTypeSize, mappings); }
private void SetSigned(CtfPropertyBag bag) { if (!bag.TryGetBoolean("signed", out bool signed)) { // integers default to unsigned according to specification 1.82 section 4.1.5 this.Signed = false; return; } this.Signed = signed; }
internal CtfFloatDescriptor(CtfPropertyBag bag) : base(CtfTypes.Float) { Debug.Assert(bag != null); this.Exponent = bag.GetInt("exp_dig"); this.Mantissa = bag.GetInt("mant_dig"); this.align = bag.GetInt("align"); this.ByteOrder = bag.GetByteOrder(); }
public void NamedEnumTest12() { const string typeName = "EnumType1"; const bool baseTypeSigned = true; const ushort baseTypeSize = 5; var integerProperties = new CtfPropertyBag(); integerProperties.AddValue("size", baseTypeSize.ToString()); integerProperties.AddValue("signed", baseTypeSigned.ToString()); var mappings = new List <EnumeratorTestValue> { new EnumeratorTestValue { Name = "\"this is the first enum value\"", StartValue = 2, StartValueIsSigned = false, AddComma = true }, new EnumeratorTestValue { Name = "\"this is the second enum value\"", StartValue = 3, AddComma = true, ValueSpecified = false }, new EnumeratorTestValue { Name = "\"this is the third enum value\"", StartValue = 4, AddComma = true, ValueSpecified = false, }, new EnumeratorTestValue { Name = "\"this is the final enum value\"", StartValue = 12, EndValue = 15, Range = true, EndValueIsSigned = false, AddComma = true }, }; NamedEnumTest(typeName, baseTypeSigned, baseTypeSize, mappings); }
/// <summary> /// Constructor /// </summary> /// <param name="properties">Property bag</param> /// <param name="eventHeader">Event header</param> /// <param name="eventContext">Event context</param> /// <param name="packetContext">Packet context</param> internal CtfStreamDescriptor( CtfPropertyBag properties, CtfStructDescriptor eventHeader, CtfStructDescriptor eventContext, CtfStructDescriptor packetContext) { Debug.Assert(properties != null); Debug.Assert(eventHeader != null); Debug.Assert(packetContext != null); // eventContext may be null this.Id = properties.GetUInt("id"); this.header = eventHeader; this.eventContext = eventContext; this.context = packetContext; }
internal CtfStructDescriptor(CtfPropertyBag props, ICtfFieldDescriptor[] fields) : base(CtfTypes.Struct) { Guard.NotNull(props, nameof(props)); Guard.NotNull(fields, nameof(fields)); int alignment = 1; if (props != null) { alignment = props.GetIntOrNull("align") ?? 1; } this.Fields = new List <ICtfFieldDescriptor>(fields); DetermineMinimumRequiredAlignment(alignment); }
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"); } }
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; }
public void NamedEnumTest11() { const string typeName = "EnumType1"; const bool baseTypeSigned = false; const ushort baseTypeSize = 5; var integerProperties = new CtfPropertyBag(); integerProperties.AddValue("size", baseTypeSize.ToString()); integerProperties.AddValue("signed", baseTypeSigned.ToString()); var mappings = new List <EnumeratorTestValue> { new EnumeratorTestValue { Name = "\"this is an enum value\"", StartValue = 2 }, }; NamedEnumTest(typeName, baseTypeSigned, baseTypeSize, mappings); }
private void SetAlignment(CtfPropertyBag bag) { var alignment = bag.GetShortOrNull("align"); if (alignment.HasValue) { this.align = alignment.Value; return; } // if alignment is not specifically set, then integers with a size which is multiple // of 8-bits will be 8-bit aligned, all others will be single byte aligned. // spec: 1.8.2, 4.1.2 if ((bag.GetShort("size") % 8) == 0) { this.align = 8; } else { this.align = 1; } }
private static EncodingTypes GetEncoding(CtfPropertyBag bag) { Debug.Assert(bag != null); if (!bag.TryGetString("encoding", out string encoding)) { // strings default to UTF-8 encoding to specification 1.82 section 4.2.5 return(EncodingTypes.Utf8); } if (StringComparer.InvariantCulture.Equals(encoding, "UTF8")) { return(EncodingTypes.Utf8); } if (StringComparer.InvariantCulture.Equals(encoding, "ASCII")) { return(EncodingTypes.Ascii); } return(EncodingTypes.Invalid); }
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 SetBase(CtfPropertyBag bag) { // integers default to decimal to specification 1.82 section 4.1.5 this.Base = bag.GetShortOrNull("base") ?? 10; }
private void SetEncoding(CtfPropertyBag bag) { this.Encoding = GetEncoding(bag); }
/// <summary> /// Checks for an encoding value in the property bag and determines if it is valid. /// </summary> /// <param name="bag">Property bag</param> /// <returns>true if valid</returns> internal static bool IsValidEncoding(CtfPropertyBag bag) { return(GetEncoding(bag) != EncodingTypes.Invalid); }
internal CtfEnvironmentDescriptor(CtfPropertyBag bag) { this.Properties = bag.Assignments; }
private void SetEncoding(CtfPropertyBag bag) { // integers default to no encoding to specification 1.82 section 4.1.5 this.Encoding = bag.GetString("encoding") ?? "none"; }