From 227c8015491ac9a870463cff02aba8f7111d601b Mon Sep 17 00:00:00 2001 From: Justin Kolb Date: Sat, 1 Sep 2018 15:37:56 -0500 Subject: [PATCH] Add bytesWritten, bytesRead, and skip. --- Sources/Lilliput/BufferInputStream.swift | 11 +++++++++++ Sources/Lilliput/BufferOutputStream.swift | 11 +++++++++++ Sources/Lilliput/ByteInputStream.swift | 2 ++ Sources/Lilliput/ByteOutputStream.swift | 2 ++ Sources/Lilliput/OrderedInputStream.swift | 2 ++ Sources/Lilliput/OrderedOutputStream.swift | 2 ++ 6 files changed, 30 insertions(+) diff --git a/Sources/Lilliput/BufferInputStream.swift b/Sources/Lilliput/BufferInputStream.swift index baa3a69..5835e1c 100644 --- a/Sources/Lilliput/BufferInputStream.swift +++ b/Sources/Lilliput/BufferInputStream.swift @@ -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 { diff --git a/Sources/Lilliput/BufferOutputStream.swift b/Sources/Lilliput/BufferOutputStream.swift index 796df9a..a8803a1 100644 --- a/Sources/Lilliput/BufferOutputStream.swift +++ b/Sources/Lilliput/BufferOutputStream.swift @@ -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 { diff --git a/Sources/Lilliput/ByteInputStream.swift b/Sources/Lilliput/ByteInputStream.swift index 95e2a01..33cf14e 100644 --- a/Sources/Lilliput/ByteInputStream.swift +++ b/Sources/Lilliput/ByteInputStream.swift @@ -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 diff --git a/Sources/Lilliput/ByteOutputStream.swift b/Sources/Lilliput/ByteOutputStream.swift index e82a2f9..c370401 100644 --- a/Sources/Lilliput/ByteOutputStream.swift +++ b/Sources/Lilliput/ByteOutputStream.swift @@ -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 diff --git a/Sources/Lilliput/OrderedInputStream.swift b/Sources/Lilliput/OrderedInputStream.swift index 8174d0d..c738b01 100644 --- a/Sources/Lilliput/OrderedInputStream.swift +++ b/Sources/Lilliput/OrderedInputStream.swift @@ -29,6 +29,8 @@ public final class OrderedInputStream : 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()) } diff --git a/Sources/Lilliput/OrderedOutputStream.swift b/Sources/Lilliput/OrderedOutputStream.swift index c297e97..ccb799d 100644 --- a/Sources/Lilliput/OrderedOutputStream.swift +++ b/Sources/Lilliput/OrderedOutputStream.swift @@ -29,6 +29,8 @@ public final class OrderedOutputStream : 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)) }