Skip to content

Commit

Permalink
Add bytesWritten, bytesRead, and skip.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkolb committed Sep 1, 2018
1 parent d667c08 commit 227c801
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Lilliput/BufferInputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public final class BufferInputStream : ByteInputStream {
self.offset = 0
}

public var bytesRead: Int {
@inline(__always) get {
return offset
}
}

@inline(__always)
public func skip(count: Int) throws {
offset += count
}

public var remainingBytes: UnsafeRawPointer {
@inline(__always)
get {
Expand Down
11 changes: 11 additions & 0 deletions Sources/Lilliput/BufferOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public final class BufferOutputStream : ByteOutputStream {
self.offset = 0
}

public var bytesWritten: Int {
@inline(__always) get {
return offset
}
}

@inline(__always)
public func skip(count: Int) throws {
offset += count
}

public var remainingBytes: UnsafeMutableRawPointer {
@inline(__always)
get {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Lilliput/ByteInputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

public protocol ByteInputStream {
var bytesRead: Int { get }
func skip(count: Int) throws
func readUInt8() throws -> UInt8
func readUInt16() throws -> UInt16
func readUInt32() throws -> UInt32
Expand Down
2 changes: 2 additions & 0 deletions Sources/Lilliput/ByteOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

public protocol ByteOutputStream {
var bytesWritten: Int { get }
func skip(count: Int) throws
func writeUInt8 (_ value: UInt8 ) throws
func writeUInt16(_ value: UInt16) throws
func writeUInt32(_ value: UInt32) throws
Expand Down
2 changes: 2 additions & 0 deletions Sources/Lilliput/OrderedInputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public final class OrderedInputStream<Order : ByteOrder> : ByteInputStream {
self.stream = stream
}

public var bytesRead: Int { @inline(__always) get { return stream.bytesRead } }
@inline(__always) public func skip(count: Int) throws { try stream.skip(count: count) }
@inline(__always) public func readUInt8() throws -> UInt8 { return try stream.readUInt8() }
@inline(__always) public func readUInt16() throws -> UInt16 { return Order.swapOrderUInt16(try stream.readUInt16()) }
@inline(__always) public func readUInt32() throws -> UInt32 { return Order.swapOrderUInt32(try stream.readUInt32()) }
Expand Down
2 changes: 2 additions & 0 deletions Sources/Lilliput/OrderedOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public final class OrderedOutputStream<Order : ByteOrder> : ByteOutputStream {
self.stream = stream
}

public var bytesWritten: Int { @inline(__always) get { return stream.bytesWritten } }
@inline(__always) public func skip(count: Int) throws { try stream.skip(count: count) }
@inline(__always) public func writeUInt8 (_ value: UInt8 ) throws { try stream.writeUInt8(value) }
@inline(__always) public func writeUInt16(_ value: UInt16) throws { try stream.writeUInt16(Order.swapOrderUInt16(value)) }
@inline(__always) public func writeUInt32(_ value: UInt32) throws { try stream.writeUInt32(Order.swapOrderUInt32(value)) }
Expand Down

0 comments on commit 227c801

Please sign in to comment.