diff --git a/Sources/BitWiser/Extension/Extension+Data.swift b/Sources/BitWiser/Extension/Extension+Data.swift index 79533c1..4a8e462 100644 --- a/Sources/BitWiser/Extension/Extension+Data.swift +++ b/Sources/BitWiser/Extension/Extension+Data.swift @@ -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()) } } diff --git a/Tests/BitWiserTests/DSLTests.swift b/Tests/BitWiserTests/DSLTests.swift index a4da825..8129434 100644 --- a/Tests/BitWiserTests/DSLTests.swift +++ b/Tests/BitWiserTests/DSLTests.swift @@ -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 {