private ulong GetULong(CtfIntegerValue integerValue, string fieldName)
        {
            if (!integerValue.Value.TryGetUInt64(out var field))
            {
                throw new CtfPlaybackException($"{fieldName} cannot be parsed as a ulong.");
            }

            return(field);
        }
        private int GetInt(CtfIntegerValue integerValue, string fieldName)
        {
            if (!integerValue.Value.TryGetInt32(out var field))
            {
                throw new CtfPlaybackException($"{fieldName} cannot be parsed as an int.");
            }

            return(field);
        }
        private byte GetByte(CtfIntegerValue integerValue, string fieldName)
        {
            if (!integerValue.Value.TryGetUInt8(out var field))
            {
                throw new CtfPlaybackException($"{fieldName} cannot be parsed as a byte.");
            }

            return(field);
        }
        private ulong ConvertIntegerValueToNanoseconds(CtfIntegerValue value)
        {
            if (!this.BaseIntegerValue.Value.TryGetUInt64(out var baseTime))
            {
                throw new CtfPlaybackException($"Unable to convert {nameof(CtfIntegerValue)} time into nanoseconds.");
            }

            return(ConvertTimeToNanoseconds(baseTime));
        }
示例#5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="metadataCustomization">Extensibility points</param>
        /// <param name="integerValue">Integer representation of the timestamp</param>
        /// <param name="timestampValue">Timestamp value in units specified by the ClockDescriptor</param>
        public CtfTimestamp(ICtfMetadataCustomization metadataCustomization, CtfIntegerValue integerValue, long timestampValue)
            : this(metadataCustomization, integerValue)
        {
            if (timestampValue < 0)
            {
                throw new ArgumentException("Negative timestamp value is not supported.", nameof(timestampValue));
            }

            this.NanosecondsFromClockBase = ConvertTimeToNanoseconds((ulong)timestampValue);
        }
示例#6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="metadataCustomization">Extensibility points</param>
        /// <param name="integerValue">integer representation of the timestamp</param>
        public CtfTimestamp(ICtfMetadataCustomization metadataCustomization, CtfIntegerValue integerValue)
        {
            this.BaseIntegerValue = integerValue;

            string clockName = metadataCustomization.GetTimestampClockName(integerValue);

            if (string.IsNullOrWhiteSpace(clockName))
            {
                if (!string.IsNullOrWhiteSpace(integerValue.MapValue))
                {
                    throw new CtfPlaybackException($"Unable to parse integer map value as a clock: {integerValue.MapValue}");
                }

                if (metadataCustomization.Metadata.Clocks?.Count == 1)
                {
                    clockName = metadataCustomization.Metadata.Clocks[0].Name;
                }
                else
                {
                    Debug.Assert(false, "Add support for default clock that increments once per nanosecond: ctf spec 1.8.2 section 8");
                    throw new NotImplementedException("This library doesn't currently support a default clock.");
                }
            }

            if (!metadataCustomization.Metadata.ClocksByName.TryGetValue(clockName, out var clockDescriptor))
            {
                throw new CtfPlaybackException($"Unable to retrieve clock descriptor for timestamp value: {integerValue.MapValue}");
            }

            this.ClockDescriptor = clockDescriptor;

            if (!this.BaseIntegerValue.Value.TryGetInt64(out long value))
            {
                throw new CtfPlaybackException("Unable to retrieve timestamp as long.");
            }

            this.NanosecondsFromClockBase = ConvertIntegerValueToNanoseconds(this.BaseIntegerValue);

            this.ClockName = metadataCustomization.GetTimestampClockName(integerValue);
            this.ClockOffsetFromPosixEpochInNanoseconds = ConvertTimeToNanoseconds(this.ClockDescriptor.Offset);
        }