Skip to content

Commit

Permalink
#161 Fix LowEnergyAdvertisingData.init(data:)
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 5, 2024
1 parent cc03c43 commit 550b1fb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/Bluetooth/LowEnergyAdvertisingData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public extension LowEnergyAdvertisingData {
}
}

init?<Data: DataContainer>(data: Data) {
init<Data: DataContainer>(data: Data) {
self.init(data)
}

Expand Down Expand Up @@ -337,10 +337,10 @@ extension LowEnergyAdvertisingData: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let data = try container.decode(Data.self)
guard let value = Self.init(data: data) else {
guard data.count <= LowEnergyAdvertisingData.capacity else {
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Invalid number of bytes (\(data.count)."))
}
self = value
self.init(data: data)
}

public func encode(to encoder: Encoder) throws {
Expand Down

0 comments on commit 550b1fb

Please sign in to comment.