-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1234 from DataDog/maxep/merge-develop-v2
Update `feature/v2` with `develop`
- Loading branch information
Showing
111 changed files
with
3,628 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
DatadogInternal/Sources/Extensions/FixedWidthInteger+Convenience.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// An extension for FixedWidthInteger that provides a convenient API for | ||
/// converting numeric values into different units of data storage, such as | ||
/// bytes, kilobytes, megabytes, and gigabytes. | ||
public extension FixedWidthInteger { | ||
/// A private property that represents the base unit (1024) used for | ||
/// converting between data storage units. | ||
private var base: Self { 1_024 } | ||
|
||
/// A property that converts the given numeric value into kilobytes. | ||
var KB: Self { return self.multipliedReportingOverflow(by: base).partialValue } | ||
|
||
/// A property that converts the given numeric value into megabytes. | ||
var MB: Self { return self.KB.multipliedReportingOverflow(by: base).partialValue } | ||
|
||
/// A property that converts the given numeric value into gigabytes. | ||
var GB: Self { return self.MB.multipliedReportingOverflow(by: base).partialValue } | ||
|
||
/// A helper property that returns the current value as a direct representation in bytes. | ||
var bytes: Self { return self } | ||
} |
71 changes: 71 additions & 0 deletions
71
DatadogInternal/Sources/Extensions/TimeInterval+Convenience.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// An extension for TimeInterval that provides a more semantic and expressive | ||
/// API for converting time representations into TimeInterval's default unit: seconds. | ||
public extension TimeInterval { | ||
/// A helper property that returns the current value as a direct representation in seconds. | ||
var seconds: TimeInterval { return TimeInterval(self) } | ||
|
||
/// A property that converts the given number of minutes into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var minutes: TimeInterval { return self.multiplyOrClamp(by: 60) } | ||
|
||
/// A property that converts the given number of hours into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var hours: TimeInterval { return self.multiplyOrClamp(by: 60.minutes) } | ||
|
||
/// A property that converts the given number of days into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var days: TimeInterval { return self.multiplyOrClamp(by: 24.hours) } | ||
|
||
/// A private helper method for multiplying the TimeInterval value by a factor | ||
/// and clamping the result to prevent overflow. If the multiplication results in | ||
/// overflow, the greatest finite magnitude value of TimeInterval is returned. | ||
/// | ||
/// - Parameter factor: The multiplier to apply to the time interval. | ||
/// - Returns: The multiplied time interval, clamped to the greatest finite magnitude if necessary. | ||
private func multiplyOrClamp(by factor: TimeInterval) -> TimeInterval { | ||
guard factor != 0 else { | ||
return 0 | ||
} | ||
let multiplied = TimeInterval(self) * factor | ||
if multiplied / factor != TimeInterval(self) { | ||
return TimeInterval.greatestFiniteMagnitude | ||
} | ||
return multiplied | ||
} | ||
} | ||
|
||
/// An extension for FixedWidthInteger that provides a more semantic and expressive | ||
/// API for converting time representations into TimeInterval's default unit: seconds. | ||
public extension FixedWidthInteger { | ||
/// A helper property that returns the current value as a direct representation in seconds. | ||
var seconds: TimeInterval { return TimeInterval(self) } | ||
|
||
/// A property that converts the given numeric value of minutes into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var minutes: TimeInterval { | ||
let (result, overflow) = self.multipliedReportingOverflow(by: 60) | ||
return overflow ? TimeInterval.greatestFiniteMagnitude : TimeInterval(result) | ||
} | ||
|
||
/// A property that converts the given numeric value of hours into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var hours: TimeInterval { | ||
let (result, overflow) = self.multipliedReportingOverflow(by: Self(60.minutes)) | ||
return overflow ? TimeInterval.greatestFiniteMagnitude : TimeInterval(result) | ||
} | ||
|
||
/// A property that converts the given numeric value of days into seconds. | ||
/// In case of overflow, TimeInterval.greatestFiniteMagnitude is returned. | ||
var days: TimeInterval { | ||
let (result, overflow) = self.multipliedReportingOverflow(by: Self(24.hours)) | ||
return overflow ? TimeInterval.greatestFiniteMagnitude : TimeInterval(result) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
DatadogInternal/Sources/Storage/PerformancePresetOverride.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// `PerformancePresetOverride` is a public structure that allows you to customize | ||
/// performance presets by setting optional limits. If the limits are not provided, the default values from | ||
/// the `PerformancePreset` object will be used. | ||
public struct PerformancePresetOverride { | ||
/// An optional value representing the maximum allowed file size in bytes. | ||
/// If not provided, the default value from the `PerformancePreset` object is used. | ||
public let maxFileSize: UInt64? | ||
|
||
/// An optional value representing the maximum allowed object size in bytes. | ||
/// If not provided, the default value from the `PerformancePreset` object is used. | ||
public let maxObjectSize: UInt64? | ||
|
||
/// Initializes a new `PerformancePresetOverride` instance with the provided | ||
/// maximum file size and maximum object size limits. | ||
/// | ||
/// - Parameters: | ||
/// - maxFileSize: The maximum allowed file size in bytes, or `nil` to use the default value from `PerformancePreset`. | ||
/// - maxObjectSize: The maximum allowed object size in bytes, or `nil` to use the default value from `PerformancePreset`. | ||
public init(maxFileSize: UInt64?, maxObjectSize: UInt64?) { | ||
self.maxFileSize = maxFileSize | ||
self.maxObjectSize = maxObjectSize | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
DatadogInternal/Tests/Extensions/FixedWidthInteger+ConvenienceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import XCTest | ||
@testable import DatadogInternal | ||
|
||
final class FixedWidthIntegerConvenienceTests: XCTestCase { | ||
func test_Bytes() { | ||
let value: Int = 1_000 | ||
XCTAssertEqual(value.bytes, 1_000) | ||
} | ||
|
||
func test_Kilobytes() { | ||
let value: Int = 1 | ||
XCTAssertEqual(value.KB, 1_024) | ||
} | ||
|
||
func test_Megabytes() { | ||
let value: Int = 1 | ||
XCTAssertEqual(value.MB, 1_048_576) | ||
} | ||
|
||
func test_Gigabytes() { | ||
let value: Int = 1 | ||
XCTAssertEqual(value.GB, 1_073_741_824) | ||
} | ||
|
||
func test_OverflowKilobytes() { | ||
let value = UInt64.max / 1_024 | ||
XCTAssertEqual(value.KB, UInt64.max &- 1_023) | ||
} | ||
|
||
func test_OverflowMegabytes() { | ||
let value = UInt64.max / (1_024 * 1_024) | ||
XCTAssertEqual(value.MB, UInt64.max &- 1_048_575) | ||
} | ||
|
||
func test_OverflowGigabytes() { | ||
let value = UInt64.max / (1_024 * 1_024 * 1_024) | ||
XCTAssertEqual(value.GB, UInt64.max &- 1_073_741_823) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
DatadogInternal/Tests/Extensions/TimeInterval+ConvenienceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import XCTest | ||
@testable import Datadog | ||
|
||
final class TimeIntervalConvenienceTests: XCTestCase { | ||
func test_Seconds() { | ||
XCTAssertEqual(TimeInterval(30).seconds, 30) | ||
XCTAssertEqual(Int(30).seconds, 30) | ||
} | ||
|
||
func test_Minutes() { | ||
XCTAssertEqual(TimeInterval(2).minutes, 120) | ||
XCTAssertEqual(Int(2).minutes, 120) | ||
} | ||
|
||
func test_Hours() { | ||
XCTAssertEqual(TimeInterval(3).hours, 10_800) | ||
XCTAssertEqual(Int(2).minutes, 120) | ||
} | ||
|
||
func test_Days() { | ||
XCTAssertEqual(TimeInterval(1).days, 86_400) | ||
XCTAssertEqual(Int(2).minutes, 120) | ||
} | ||
|
||
func test_Overflow() { | ||
let timeInterval = TimeInterval.greatestFiniteMagnitude | ||
XCTAssertEqual(timeInterval.minutes, TimeInterval.greatestFiniteMagnitude) | ||
XCTAssertEqual(timeInterval.hours, TimeInterval.greatestFiniteMagnitude) | ||
XCTAssertEqual(timeInterval.days, TimeInterval.greatestFiniteMagnitude) | ||
|
||
let integerTimeInterval = Int.max | ||
XCTAssertEqual(integerTimeInterval.minutes, TimeInterval.greatestFiniteMagnitude) | ||
XCTAssertEqual(integerTimeInterval.hours, TimeInterval.greatestFiniteMagnitude) | ||
XCTAssertEqual(integerTimeInterval.days, TimeInterval.greatestFiniteMagnitude) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
DatadogSessionReplay/SRSnapshotTests/SRHost/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
DatadogSessionReplay/SRSnapshotTests/SRHost/Assets.xcassets/dd_logo.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "dd_logo.jpg", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+6.91 KB
...ssionReplay/SRSnapshotTests/SRHost/Assets.xcassets/dd_logo.imageset/dd_logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.