Skip to content

Commit

Permalink
Unpacking message should also be able to throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed Apr 5, 2017
1 parent 807f342 commit 7b73e65
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/DNS/Bytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension Message {

// questions
for question in questions {
try! packName(question.name, onto: &bytes, labels: &labels)
try packName(question.name, onto: &bytes, labels: &labels)
bytes += question.type.rawValue.bytes
bytes += question.internetClass.bytes
}
Expand All @@ -130,18 +130,18 @@ extension Message {
return bytes
}

public init(unpackTCP bytes: Data) {
public init(unpackTCP bytes: Data) throws {
precondition(bytes.count >= 2)
let size = Int(UInt16(bytes: bytes[0..<2]))

// strip size bytes (tcp only?)
var bytes = Data(bytes[2..<2+size]) // copy? :(
precondition(bytes.count == Int(size))

self.init(unpack: bytes)
try self.init(unpack: bytes)
}

public init(unpack bytes: Data) {
public init(unpack bytes: Data) throws {
let flags = UInt16(bytes: bytes[2..<4])

header = Header(id: UInt16(bytes: bytes[0..<2]),
Expand Down

0 comments on commit 7b73e65

Please sign in to comment.