Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Changelog

## 2.1.2

- Fixes writing bool as UInt8 instead of Int

## 2.1.1

- Fixes FileStream to create a file if it does not exists.
Expand Down
2 changes: 1 addition & 1 deletion Sources/BinaryHandler/BinaryWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension BinaryWritable {
}

public func write(_ value: Bool) throws {
try write(value ? 1 : 0)
try write(UInt8(value ? 1 : 0))
}

public func writeFixedString(_ value: String) throws {
Expand Down
15 changes: 15 additions & 0 deletions Tests/BinaryHandlerTests/BinaryHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import XCTest

final class BinaryHandlerTests: XCTestCase {

func testWriteReadBool() throws {
let stream = MemoryStream(withData: Data())
let writer = BinaryWriter(source: stream)

try writer.write(false)
try writer.write(true)

let reader = BinaryReader(source: stream)
try reader.seekTo(position: 0) // Reset position for reading

XCTAssertEqual(try? reader.readBool(), false)
XCTAssertEqual(try? reader.readBool(), true)
XCTAssertEqual(stream.data.count, 2)
}

func testWriteReadUint8() throws {
let stream = MemoryStream(withData: Data())
let writer = BinaryWriter(source: stream)
Expand Down