var capacity: Int
The current capacity of the storage of this ByteBuffer
, this is not constant and does not signify the number of bytes that have been written to this ByteBuffer
.
var debugDescription: String
var description: String
A String
describing this ByteBuffer
including length and the bytes it contains (partially).
var readableBytes: Int
The number of bytes readable (readableBytes
= writerIndex
- readerIndex
).
var readableBytesView: ByteBufferView
A view into the readable bytes of the ByteBuffer
.
var readerIndex: Int
The reader index or the number of bytes previously read from this ByteBuffer
. readerIndex
is 0
for a newly allocated ByteBuffer
.
var storageCapacity: Int
The current capacity of the underlying storage of this ByteBuffer
. A COW slice of the buffer (e.g. readSlice(length: x)) will posses the same storageCapacity as the original buffer until new data is written.
var writableBytes: Int
The number of bytes writable until ByteBuffer
will need to grow its underlying storage which will likely trigger a copy of the bytes.
var writerIndex: Int
The write index or the number of bytes previously written to this ByteBuffer
. writerIndex
is 0
for a newly allocated ByteBuffer
.
func clear()
Set both reader index and writer index to 0
. This will reset the state of this ByteBuffer
to the state of a freshly allocated one, if possible without allocations. This is the cheapest way to recycle a ByteBuffer
for a new use-case.
func clear(minimumCapacity: Int)
Set both reader index and writer index to 0
. This will reset the state of this ByteBuffer
to the state of a freshly allocated one, if possible without allocations. This is the cheapest way to recycle a ByteBuffer
for a new use-case.
func copyBytes(at: Int, to: Int, length: Int) throws -> Int
Copies length
bytes
starting at the fromIndex
to toIndex
. Does not move the writer index.
func discardReadBytes() -> Bool
Discard the bytes before the reader index. The byte at index readerIndex
before calling this method will be at index 0
after the call returns.
func encode(to: Encoder) throws
Encodes this buffer as a base64 string in a single value container.
func getBytes(at: Int, length: Int) -> [UInt8]?
Get length
bytes starting at index
and return the result as [UInt8]
. This will not change the reader index. The selected bytes must be readable or else nil
will be returned.
func getDispatchData(at: Int, length: Int) -> DispatchData?
Get the bytes at index
from this ByteBuffer
as a DispatchData
. Does not move the reader index. The selected bytes must be readable or else nil
will be returned.
func getInteger<T>(at: Int, endianness: Endianness, as: T.Type) -> T?
Get the integer at index
from this ByteBuffer
. Does not move the reader index. The selected bytes must be readable or else nil
will be returned.
func getLengthPrefixedSlice<Integer>(at: Int, endianness: Endianness, as: Integer.Type) -> ByteBuffer?
Gets an Integer
from self
and gets a slice of that length from self
and returns it.
func getNullTerminatedString(at: Int) -> String?
Get the string at index
from this ByteBuffer
decoding using the UTF-8 encoding. Does not move the reader index. The selected bytes must be readable or else nil
will be returned.
func getSlice(at: Int, length: Int) -> ByteBuffer?
Returns a slice of size length
bytes, starting at index
. The ByteBuffer
this is invoked on and the ByteBuffer
returned will share the same underlying storage. However, the byte at index
in this ByteBuffer
will correspond to index 0
in the returned ByteBuffer
. The readerIndex
of the returned ByteBuffer
will be 0
, the writerIndex
will be length
.
func getString(at: Int, length: Int) -> String?
Get the string at index
from this ByteBuffer
decoding using the UTF-8 encoding. Does not move the reader index. The selected bytes must be readable or else nil
will be returned.
func getUTF8ValidatedString(at: Int, length: Int) throws -> String?
Get the string at index
from this ByteBuffer
decoding using the UTF-8 encoding. Does not move the reader index. The selected bytes must be readable or else nil
will be returned.
func hash(into: inout Hasher)
The hash value for the readable bytes.
func hexDump(format: HexDumpFormat) -> String
Returns a hex dump of this ByteBuffer
in a preferred HexDumpFormat
.
func modifyIfUniquelyOwned<T>((inout ByteBuffer) throws -> T) rethrows -> T?
Modify this ByteBuffer
if this ByteBuffer
is known to uniquely own its storage.
func moveReaderIndex(forwardBy: Int)
Move the reader index forward by offset
bytes.
func moveReaderIndex(to: Int)
Set the reader index to offset
.
func moveWriterIndex(forwardBy: Int)
Move the writer index forward by offset
bytes.
func moveWriterIndex(to: Int)
Set the writer index to offset
.
func readBytes(length: Int) -> [UInt8]?
Read length
bytes off this ByteBuffer
, move the reader index forward by length
bytes and return the result as [UInt8]
.
func readDispatchData(length: Int) -> DispatchData?
Read length
bytes off this ByteBuffer
and return them as a DispatchData
. Move the reader index forward by length
.
func readEncodedInteger<Strategy, Integer>(as: Integer.Type, strategy: Strategy) -> Integer?
Read a binary encoded integer, moving the readerIndex
appropriately. If there are not enough bytes, nil is returned.
func readInteger<T>(endianness: Endianness, as: T.Type) -> T?
Read an integer off this ByteBuffer
, move the reader index forward by the integer’s byte size and return the result.
func readLengthPrefixed<Integer, Result>(endianness: Endianness, as: Integer.Type, readMessage: (ByteBuffer) throws -> Result?) throws -> Result?
Reads an Integer
from self
, reads a slice of that length and passes it to readMessage
. It is checked that readMessage
returns a non-nil value.
func readLengthPrefixedSlice<Integer>(endianness: Endianness, as: Integer.Type) -> ByteBuffer?
Reads an Integer
from self
and reads a slice of that length from self
and returns it.
func readLengthPrefixedSlice<Strategy>(strategy: Strategy) -> ByteBuffer?
Reads a slice which is prefixed with a length. The length will be read using strategy
, and then that many bytes will be read to create a slice.
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8).Type) -> (T1, T2, T3, T4, T5, T6, T7, T8)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6, T7>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7).Type) -> (T1, T2, T3, T4, T5, T6, T7)?
func readMultipleIntegers<T1, T2, T3, T4, T5, T6>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6).Type) -> (T1, T2, T3, T4, T5, T6)?
func readMultipleIntegers<T1, T2, T3, T4, T5>(endianness: Endianness, as: (T1, T2, T3, T4, T5).Type) -> (T1, T2, T3, T4, T5)?
func readMultipleIntegers<T1, T2, T3, T4>(endianness: Endianness, as: (T1, T2, T3, T4).Type) -> (T1, T2, T3, T4)?
func readMultipleIntegers<T1, T2, T3>(endianness: Endianness, as: (T1, T2, T3).Type) -> (T1, T2, T3)?
func readMultipleIntegers<T1, T2>(endianness: Endianness, as: (T1, T2).Type) -> (T1, T2)?
func readNullTerminatedString() -> String?
Read a null terminated string off this ByteBuffer
, decoding it as String
using the UTF-8 encoding. Move the reader index forward by the string’s length and its null terminator.
func readSlice(length: Int) -> ByteBuffer?
Slice length
bytes off this ByteBuffer
and move the reader index forward by length
. If enough bytes are readable the ByteBuffer
returned by this method will share the underlying storage with the ByteBuffer
the method was invoked on. The returned ByteBuffer
will contain the bytes in the range readerIndex..<(readerIndex + length)
of the original ByteBuffer
. The readerIndex
of the returned ByteBuffer
will be 0
, the writerIndex
will be length
.
func readString(length: Int) -> String?
Read length
bytes off this ByteBuffer
, decoding it as String
using the UTF-8 encoding. Move the reader index forward by length
.
func readUTF8ValidatedString(length: Int) throws -> String?
Read length
bytes off this ByteBuffer
, decoding it as String
using the UTF-8 encoding. Move the reader index forward by length
.
func readWithUnsafeMutableReadableBytes((UnsafeMutableRawBufferPointer) throws -> Int) rethrows -> Int
Yields a mutable buffer pointer containing this ByteBuffer
’s readable bytes. You may modify the yielded bytes. Will move the reader index by the number of bytes returned by body
but leave writer index as it was.
func readWithUnsafeMutableReadableBytes<T>((UnsafeMutableRawBufferPointer) throws -> (Int, T)) rethrows -> T
Yields a mutable buffer pointer containing this ByteBuffer
’s readable bytes. You may modify the yielded bytes. Will move the reader index by the number of bytes body
returns in the first tuple component but leave writer index as it was.
func readWithUnsafeReadableBytes((UnsafeRawBufferPointer) throws -> Int) rethrows -> Int
Yields an immutable buffer pointer containing this ByteBuffer
’s readable bytes. Will move the reader index by the number of bytes returned by body
.
func readWithUnsafeReadableBytes<T>((UnsafeRawBufferPointer) throws -> (Int, T)) rethrows -> T
Yields an immutable buffer pointer containing this ByteBuffer
’s readable bytes. Will move the reader index by the number of bytes body
returns in the first tuple component.
func reserveCapacity(Int)
Reserves enough space to store the specified number of bytes.
func reserveCapacity(minimumWritableBytes: Int)
Reserves enough space to write at least the specified number of bytes.
func setBuffer(ByteBuffer, at: Int) -> Int
Copy buffer
’s readable bytes into this ByteBuffer
starting at index
. Does not move any of the reader or writer indices.
func setBytes(UnsafeRawBufferPointer, at: Int) -> Int
Copy bytes
into the ByteBuffer
at index
. Does not move the writer index.
func setBytes<Bytes>(Bytes, at: Int) -> Int
Copy the collection of bytes
into the ByteBuffer
at index
. Does not move the writer index.
func setDispatchData(DispatchData, at: Int) -> Int
Write dispatchData
into this ByteBuffer
at index
. Does not move the writer index.
func setInteger<T>(T, at: Int, endianness: Endianness, as: T.Type) -> Int
Write integer
into this ByteBuffer
starting at index
. This does not alter the writer index.
func setNullTerminatedString(String, at: Int) -> Int
Write string
null terminated into this ByteBuffer
at index
using UTF-8 encoding. Does not move the writer index.
func setRepeatingByte(UInt8, count: Int, at: Int) -> Int
Sets the given byte
count
times at the given index
. Will reserve more memory if necessary. Does not move the writer index.
func setStaticString(StaticString, at: Int) -> Int
Write the static string
into this ByteBuffer
at index
using UTF-8 encoding, moving the writer index forward appropriately.
func setString(String, at: Int) -> Int
Write string
into this ByteBuffer
at index
using UTF-8 encoding. Does not move the writer index.
func setSubstring(Substring, at: Int) -> Int
Write substring
into this ByteBuffer
at index
using UTF-8 encoding. Does not move the writer index.
func shrinkBufferCapacity(to: Int) -> Bool
The ByteBuffer
will successfully be shrunk if the requested capacity is less than the current capacity, and the requested capacity is greater than or equal to the number of readable bytes in the buffer. If either condition is not true, the buffer will not be shrunk.
func slice() -> ByteBuffer
Slice the readable bytes off this ByteBuffer
without modifying the reader index. This method will return a ByteBuffer
sharing the underlying storage with the ByteBuffer
the method was invoked on. The returned ByteBuffer
will contain the bytes in the range readerIndex..<writerIndex
of the original ByteBuffer
.
func viewBytes(at: Int, length: Int) -> ByteBufferView?
Returns a view into some portion of the readable bytes of a ByteBuffer
.
func withUnsafeMutableReadableBytes<T>((UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T
Yields a mutable buffer pointer containing this ByteBuffer
’s readable bytes. You may modify those bytes.
func withUnsafeMutableWritableBytes<T>((UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T
Yields the bytes currently writable (bytesWritable
= capacity
- writerIndex
). Before reading those bytes you must first write to them otherwise you will trigger undefined behaviour. The writer index will remain unchanged.
func withUnsafeReadableBytes<T>((UnsafeRawBufferPointer) throws -> T) rethrows -> T
Yields a buffer pointer containing this ByteBuffer
’s readable bytes.
func withUnsafeReadableBytesWithStorageManagement<T>((UnsafeRawBufferPointer, Unmanaged<AnyObject>) throws -> T) rethrows -> T
Yields a buffer pointer containing this ByteBuffer
‘s readable bytes. You may hold a pointer to those bytes even after the closure returned iff you model the lifetime of those bytes correctly using the Unmanaged
instance. If you don’t require the pointer after the closure returns, use withUnsafeReadableBytes
.
func withVeryUnsafeBytes<T>((UnsafeRawBufferPointer) throws -> T) rethrows -> T
This vends a pointer to the storage of the ByteBuffer
. It’s marked as very unsafe because it might contain uninitialised memory and it’s undefined behaviour to read it. In most cases you should use withUnsafeReadableBytes
.
func withVeryUnsafeBytesWithStorageManagement<T>((UnsafeRawBufferPointer, Unmanaged<AnyObject>) throws -> T) rethrows -> T
See withUnsafeReadableBytesWithStorageManagement
and withVeryUnsafeBytes
.
func withVeryUnsafeMutableBytes<T>((UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T
This vends a pointer to the storage of the ByteBuffer
. It’s marked as very unsafe because it might contain uninitialised memory and it’s undefined behaviour to read it. In most cases you should use withUnsafeMutableWritableBytes
.
func writeBuffer(inout ByteBuffer) -> Int
Write buffer
’s readable bytes into this ByteBuffer
starting at writerIndex
. This will move both this ByteBuffer
’s writer index as well as buffer
’s reader index by the number of bytes readable in buffer
.
func writeBytes(UnsafeRawBufferPointer) -> Int
Write bytes
into this ByteBuffer
. Moves the writer index forward by the number of bytes written.
func writeBytes<Bytes>(Bytes) -> Int
Write bytes
, a Sequence
of UInt8
into this ByteBuffer
. Moves the writer index forward by the number of bytes written.
func writeDispatchData(DispatchData) -> Int
Write dispatchData
into this ByteBuffer
, moving the writer index forward appropriately.
func writeEncodedInteger<Integer, Strategy>(Integer, strategy: Strategy) -> Int
Write a binary encoded integer.
func writeImmutableBuffer(ByteBuffer) -> Int
func writeInteger<T>(T, endianness: Endianness, as: T.Type) -> Int
Write integer
into this ByteBuffer
, moving the writer index forward appropriately.
func writeLengthPrefixed<Integer>(endianness: Endianness, as: Integer.Type, writeMessage: (inout ByteBuffer) throws -> Int) throws -> Int
Prefixes a message written by writeMessage
with the number of bytes written as an Integer
.
func writeLengthPrefixed<Strategy>(strategy: Strategy, writeData: (_ buffer: inout ByteBuffer) throws -> Int) rethrows -> Int
Prefixes bytes written by writeData
with the number of bytes written. The number of bytes written is encoded using strategy
.
func writeLengthPrefixedBuffer<Strategy>(ByteBuffer, strategy: Strategy) -> Int
Write the length of buffer
using strategy
. Then write the buffer.
func writeLengthPrefixedBytes<Bytes, Strategy>(Bytes, strategy: Strategy) -> Int
Write the length of bytes
using strategy
. Then write the bytes.
func writeLengthPrefixedString<Strategy>(String, strategy: Strategy) -> Int
Write the length of string
using strategy
. Then write the string.
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8, T9>(T1, T2, T3, T4, T5, T6, T7, T8, T9, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7, T8>(T1, T2, T3, T4, T5, T6, T7, T8, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6, T7>(T1, T2, T3, T4, T5, T6, T7, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5, T6>(T1, T2, T3, T4, T5, T6, endianness: Endianness, as: (T1, T2, T3, T4, T5, T6).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5, endianness: Endianness, as: (T1, T2, T3, T4, T5).Type) -> Int
func writeMultipleIntegers<T1, T2, T3, T4>(T1, T2, T3, T4, endianness: Endianness, as: (T1, T2, T3, T4).Type) -> Int
func writeMultipleIntegers<T1, T2, T3>(T1, T2, T3, endianness: Endianness, as: (T1, T2, T3).Type) -> Int
func writeMultipleIntegers<T1, T2>(T1, T2, endianness: Endianness, as: (T1, T2).Type) -> Int
func writeNullTerminatedString(String) -> Int
Write string
into this ByteBuffer
null terminated using UTF-8 encoding, moving the writer index forward appropriately.
func writePlainHexEncodedBytes(String) throws -> Int
Write ASCII hexadecimal string
into this ByteBuffer
as raw bytes, decoding the hexadecimal & moving the writer index forward appropriately. This method will throw if the string input is not of the “plain” hex encoded format.
func writeRepeatingByte(UInt8, count: Int) -> Int
Writes byte
count
times. Moves the writer index forward by the number of bytes written.
func writeStaticString(StaticString) -> Int
Write the static string
into this ByteBuffer
using UTF-8 encoding, moving the writer index forward appropriately.
func writeString(String) -> Int
Write string
into this ByteBuffer
using UTF-8 encoding, moving the writer index forward appropriately.
func writeSubstring(Substring) -> Int
Write substring
into this ByteBuffer
using UTF-8 encoding, moving the writer index forward appropriately.
func writeWithUnsafeMutableBytes(minimumWritableBytes: Int, (UnsafeMutableRawBufferPointer) throws -> Int) rethrows -> Int
This vends a pointer of the ByteBuffer
at the writerIndex
after ensuring that the buffer has at least minimumWritableBytes
of writable bytes available.