Skip to content

Commit

Permalink
Fixed Data to use DataRepresentableBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
DrAma999 committed Feb 6, 2022
1 parent a8867d6 commit 9290afe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions Sources/BitWiser/Extension/Extension+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@ public extension Data {
}

public extension Data {
/// Initialize a `Data` with a `@ByteArrayBuilder`.

/// Initialize a `Data` with a `@DataConvertibleBuilder`.
///
/// Data {
/// [Byte(0x00)]
/// Byte(0x01)
/// 0x02
/// [UInt8(0x03)]
/// "\u{03}"
/// CustomObject()
/// }
///
/// - parameter builder: A DSL closure with `Byte`s.
/// - Important: Always start from the LSB
init(@ByteArrayBuilder _ builder: () -> [Byte]) {
self.init(bytes: builder())
///
/// - parameter representables: A DSL closure with `DataRepresentable`s. Object passed in the closure must conform to `DataRepresentable` protocol.
/// - Note: Objects passed in the closure can have different `Data` lenght.
/// - Important: Always start from the LSB.
init(@DataConvertibleBuilder _ representables: () -> Data) {
self.init(representables())
}
}
5 changes: 3 additions & 2 deletions Tests/BitWiserTests/DSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ class DSLTests: XCTestCase {
let bytes = value.bytes
let dataFromValue = Data(bytes: bytes)

// Must use UInt8 to define the lenght
let dslData = Data {
0b1010_1010
0b1100_1100
Byte(0b1010_1010)
Byte(0b1100_1100)
}

let dslByteArray = Array<Byte> {
Expand Down

0 comments on commit 9290afe

Please sign in to comment.