Instance Methodswift-nio 2.74.0NIOCore
writeLengthPrefixed(strategy:writeData:)
Prefixes bytes written by writeData
with the number of bytes written. The number of bytes written is encoded using strategy
.
@discardableResult mutating func writeLengthPrefixed<Strategy>(strategy: Strategy, writeData: (_ buffer: inout ByteBuffer) throws -> Int) rethrows -> Int where Strategy : NIOBinaryIntegerEncodingStrategy
Parameters
Returns
Number of total bytes written. This is the length of the written data + the number of bytes used to write the length before it.
Other members in extension
Types
struct CopyBytesError
Errors thrown when calling
copyBytes
.struct HexDecodingError
An error that is thrown when an invalid hex encoded string was attempted to be written to a ByteBuffer.
struct HexDumpFormat
Describes a ByteBuffer hexDump format. Can be either xxd output compatible, or hexdump compatible.
struct LengthPrefixError
struct QUICBinaryEncodingStrategy
A
NIOBinaryIntegerEncodingStrategy
which encodes bytes as defined in RFC 9000 § 16
Typealiases
Show implementation details (2)
Hide implementation details
Type members
init(
) Return an empty
ByteBuffer
allocated withByteBufferAllocator()
.init(ByteBufferView
) Create a
ByteBuffer
from the givenByteBufferView
s range.init(buffer: ByteBuffer
) Create a fresh
ByteBuffer
containing the readable bytes ofbuffer
.init<Bytes>(bytes: Bytes
) Create a fresh
ByteBuffer
containing thebytes
.init(dispatchData: DispatchData
) Create a fresh
ByteBuffer
containing the bytes contained in the givenDispatchData
.init(from: Decoder
) throws Creates a ByteByffer by decoding from a Base64 encoded single value container.
init<I>(integer: I, endianness: Endianness, as: I.Type
) Create a fresh
ByteBuffer
containing the bytes of the byte representation in the givenendianness
ofinteger
.init(plainHexEncodedBytes: String
) throws Create a fresh
ByteBuffer
containing thebytes
decoded from the string representation ofplainHexEncodedBytes
.init(repeating: UInt8, count: Int
) Create a fresh
ByteBuffer
containingcount
repetitions ofbyte
.init(staticString: StaticString
) Create a fresh
ByteBuffer
containing the bytes of thestring
encoded as UTF-8.init(string: String
) Create a fresh
ByteBuffer
containing the bytes of thestring
encoded as UTF-8.init(substring: Substring
) Create a fresh
ByteBuffer
containing the bytes of thestring
encoded as UTF-8.static func == (lhs: ByteBuffer, rhs: ByteBuffer
) -> Bool Compare two
ByteBuffer
values. TwoByteBuffer
values are considered equal if the readable bytes are equal.
Instance members
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 thisByteBuffer
.var debugDescription: String
var description: String
A
String
describing thisByteBuffer
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
is0
for a newly allocatedByteBuffer
.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
is0
for a newly allocatedByteBuffer
.func clear(
) Set both reader index and writer index to
0
. This will reset the state of thisByteBuffer
to the state of a freshly allocated one, if possible without allocations. This is the cheapest way to recycle aByteBuffer
for a new use-case.func clear(minimumCapacity: Int
) Set both reader index and writer index to
0
. This will reset the state of thisByteBuffer
to the state of a freshly allocated one, if possible without allocations. This is the cheapest way to recycle aByteBuffer
for a new use-case.func copyBytes(at: Int, to: Int, length: Int
) throws -> Int Copies
length
bytes
starting at thefromIndex
totoIndex
. 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 index0
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 atindex
and return the result as[UInt8]
. This will not change the reader index. The selected bytes must be readable or elsenil
will be returned.func getDispatchData(at: Int, length: Int
) -> DispatchData? Get the bytes at
index
from thisByteBuffer
as aDispatchData
. Does not move the reader index. The selected bytes must be readable or elsenil
will be returned.func getInteger<T>(at: Int, endianness: Endianness, as: T.Type
) -> T? Get the integer at
index
from thisByteBuffer
. Does not move the reader index. The selected bytes must be readable or elsenil
will be returned.func getLengthPrefixedSlice<Integer>(at: Int, endianness: Endianness, as: Integer.Type
) -> ByteBuffer? Gets an
Integer
fromself
and gets a slice of that length fromself
and returns it.func getNullTerminatedString(at: Int
) -> String? Get the string at
index
from thisByteBuffer
decoding using the UTF-8 encoding. Does not move the reader index. The selected bytes must be readable or elsenil
will be returned.func getSlice(at: Int, length: Int
) -> ByteBuffer? Returns a slice of size
length
bytes, starting atindex
. TheByteBuffer
this is invoked on and theByteBuffer
returned will share the same underlying storage. However, the byte atindex
in thisByteBuffer
will correspond to index0
in the returnedByteBuffer
. ThereaderIndex
of the returnedByteBuffer
will be0
, thewriterIndex
will belength
.func getString(at: Int, length: Int
) -> String? Get the string at
index
from thisByteBuffer
decoding using the UTF-8 encoding. Does not move the reader index. The selected bytes must be readable or elsenil
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 preferredHexDumpFormat
.func modifyIfUniquelyOwned<T>((inout ByteBuffer) throws -> T
) rethrows -> T? Modify this
ByteBuffer
if thisByteBuffer
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 thisByteBuffer
, move the reader index forward bylength
bytes and return the result as[UInt8]
.func readDispatchData(length: Int
) -> DispatchData? Read
length
bytes off thisByteBuffer
and return them as aDispatchData
. Move the reader index forward bylength
.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
fromself
, reads a slice of that length and passes it toreadMessage
. It is checked thatreadMessage
returns a non-nil value.func readLengthPrefixedSlice<Integer>(endianness: Endianness, as: Integer.Type
) -> ByteBuffer? Reads an
Integer
fromself
and reads a slice of that length fromself
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, T9>(endianness: Endianness, as: (T1, T2, T3, T4, T5, T6, T7, T8, T9).Type
) -> (T1, T2, T3, T4, T5, T6, T7, T8, T9)? 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 asString
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 thisByteBuffer
and move the reader index forward bylength
. If enough bytes are readable theByteBuffer
returned by this method will share the underlying storage with theByteBuffer
the method was invoked on. The returnedByteBuffer
will contain the bytes in the rangereaderIndex..<(readerIndex + length)
of the originalByteBuffer
. ThereaderIndex
of the returnedByteBuffer
will be0
, thewriterIndex
will belength
.func readString(length: Int
) -> String? Read
length
bytes off thisByteBuffer
, decoding it asString
using the UTF-8 encoding. Move the reader index forward bylength
.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 bybody
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 bytesbody
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 bybody
.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 bytesbody
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 thisByteBuffer
starting atindex
. Does not move any of the reader or writer indices.func setBytes(UnsafeRawBufferPointer, at: Int
) -> Int Copy
bytes
into theByteBuffer
atindex
. Does not move the writer index.func setBytes<Bytes>(Bytes, at: Int
) -> Int Copy the collection of
bytes
into theByteBuffer
atindex
. Does not move the writer index.func setDispatchData(DispatchData, at: Int
) -> Int Write
dispatchData
into thisByteBuffer
atindex
. Does not move the writer index.func setInteger<T>(T, at: Int, endianness: Endianness, as: T.Type
) -> Int Write
integer
into thisByteBuffer
starting atindex
. This does not alter the writer index.func setNullTerminatedString(String, at: Int
) -> Int Write
string
null terminated into thisByteBuffer
atindex
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 givenindex
. Will reserve more memory if necessary. Does not move the writer index.func setStaticString(StaticString, at: Int
) -> Int Write the static
string
into thisByteBuffer
atindex
using UTF-8 encoding, moving the writer index forward appropriately.func setString(String, at: Int
) -> Int Write
string
into thisByteBuffer
atindex
using UTF-8 encoding. Does not move the writer index.func setSubstring(Substring, at: Int
) -> Int Write
substring
into thisByteBuffer
atindex
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 aByteBuffer
sharing the underlying storage with theByteBuffer
the method was invoked on. The returnedByteBuffer
will contain the bytes in the rangereaderIndex..<writerIndex
of the originalByteBuffer
.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 theUnmanaged
instance. If you don’t require the pointer after the closure returns, usewithUnsafeReadableBytes
.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 usewithUnsafeReadableBytes
.func withVeryUnsafeBytesWithStorageManagement<T>((UnsafeRawBufferPointer, Unmanaged<AnyObject>) throws -> T
) rethrows -> T See
withUnsafeReadableBytesWithStorageManagement
andwithVeryUnsafeBytes
.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 usewithUnsafeMutableWritableBytes
.func writeBuffer(inout ByteBuffer
) -> Int Write
buffer
’s readable bytes into thisByteBuffer
starting atwriterIndex
. This will move both thisByteBuffer
’s writer index as well asbuffer
’s reader index by the number of bytes readable inbuffer
.func writeBytes(UnsafeRawBufferPointer
) -> Int Write
bytes
into thisByteBuffer
. Moves the writer index forward by the number of bytes written.func writeBytes<Bytes>(Bytes
) -> Int Write
bytes
, aSequence
ofUInt8
into thisByteBuffer
. Moves the writer index forward by the number of bytes written.func writeDispatchData(DispatchData
) -> Int Write
dispatchData
into thisByteBuffer
, 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 thisByteBuffer
, 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 anInteger
.func writeLengthPrefixedBuffer<Strategy>(ByteBuffer, strategy: Strategy
) -> Int Write the length of
buffer
usingstrategy
. Then write the buffer.func writeLengthPrefixedBytes<Bytes, Strategy>(Bytes, strategy: Strategy
) -> Int Write the length of
bytes
usingstrategy
. Then write the bytes.func writeLengthPrefixedString<Strategy>(String, strategy: Strategy
) -> Int Write the length of
string
usingstrategy
. 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 thisByteBuffer
null terminated using UTF-8 encoding, moving the writer index forward appropriately.func writePlainHexEncodedBytes(String
) throws -> Int Write ASCII hexadecimal
string
into thisByteBuffer
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 thisByteBuffer
using UTF-8 encoding, moving the writer index forward appropriately.func writeString(String
) -> Int Write
string
into thisByteBuffer
using UTF-8 encoding, moving the writer index forward appropriately.func writeSubstring(Substring
) -> Int Write
substring
into thisByteBuffer
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 thewriterIndex
after ensuring that the buffer has at leastminimumWritableBytes
of writable bytes available.
Show obsolete interfaces (3)
Hide obsolete interfaces
func clear(minimumCapacity: UInt32
) Set both reader index and writer index to
0
. This will reset the state of thisByteBuffer
to the state of a freshly allocated one, if possible without allocations. This is the cheapest way to recycle aByteBuffer
for a new use-case.func set(buffer: ByteBuffer, at: Int
) -> Int Copy
buffer
’s readable bytes into thisByteBuffer
starting atindex
. Does not move any of the reader or writer indices.func writeWithUnsafeMutableBytes((UnsafeMutableRawBufferPointer) throws -> Int
) rethrows -> Int