Initializerswift-nio 2.72.0NIOFoundationCompat->NIOCore
init(data:)
ByteBuffer-foundation.swift:204init(data: Data)
Other members in extension
Types
enum ByteTransferStrategy
Controls how bytes are transferred between
ByteBuffer
and other storage types.
Instance members
func getData(at: Int, length: Int
) -> Data? Return
length
bytes starting atindex
and return the result asData
. This will not change the reader index. The selected bytes must be readable or elsenil
will be returned.func getData(at: Int, length: Int, byteTransferStrategy: ByteTransferStrategy
) -> Data? Return
length
bytes starting atindex
and return the result asData
. This will not change the reader index. The selected bytes must be readable or elsenil
will be returned.func getJSONDecodable<T>(T.Type, decoder: JSONDecoder, at: Int, length: Int
) throws -> T? Attempts to decode the
length
bytes fromindex
using theJSONDecoder
decoder
asT
.func getString(at: Int, length: Int, encoding: String.Encoding
) -> String? Get a
String
decodinglength
bytes starting atindex
withencoding
. This will not change the reader index. The selected bytes must be readable or elsenil
will be returned.func getUUIDBytes(at: Int
) -> UUID? Get a
UUID
from the 16 bytes starting atindex
. This will not change the reader index. If there are less than 16 bytes starting atindex
thennil
will be returned.func readData(length: Int
) -> Data? Read
length
bytes off thisByteBuffer
, move the reader index forward bylength
bytes and return the result asData
.func readData(length: Int, byteTransferStrategy: ByteTransferStrategy
) -> Data? Read
length
bytes off thisByteBuffer
, move the reader index forward bylength
bytes and return the result asData
.func readJSONDecodable<T>(T.Type, decoder: JSONDecoder, length: Int
) throws -> T? Reads
length
bytes from thisByteBuffer
and then attempts to decode them using theJSONDecoder
decoder
.func readString(length: Int, encoding: String.Encoding
) -> String? Read a
String
decodinglength
bytes withencoding
from thereaderIndex
, moving thereaderIndex
appropriately.func readUUIDBytes(
) -> UUID? Read a
UUID
from the first 16 bytes in the buffer. Advances the reader index.func setContiguousBytes<Bytes>(Bytes, at: Int
) -> Int Write
bytes
into thisByteBuffer
atindex
. Does not move the writer index.func setData<D>(D, at: Int
) -> Int Write the bytes of
data
into thisByteBuffer
atindex
. Does not move the writer index.func setJSONEncodable<T>(T, encoder: JSONEncoder, at: Int
) throws -> Int Encodes
value
using theJSONEncoder
encoder
and set the resulting bytes into thisByteBuffer
at the givenindex
.func setString(String, encoding: String.Encoding, at: Int
) throws -> Int Write
string
into thisByteBuffer
atindex
using the encodingencoding
. Does not move the writer index.func setUUIDBytes(UUID, at: Int
) -> Int Set the bytes of the
UUID
into thisByteBuffer
atindex
, allocating more storage if necessary. Does not move the writer index.func writeContiguousBytes<Bytes>(Bytes
) -> Int Write
bytes
into thisByteBuffer
at the writer index, moving the writer index forward appropriately.func writeData<D>(D
) -> Int Write the bytes of
data
into thisByteBuffer
at the writer index, moving the writer index forward appropriately.func writeJSONEncodable<T>(T, encoder: JSONEncoder
) throws -> Int Encodes
value
using theJSONEncoder
encoder
and writes the resulting bytes into thisByteBuffer
.func writeString(String, encoding: String.Encoding
) throws -> Int Write
string
into thisByteBuffer
using the encodingencoding
, moving the writer index forward appropriately.func writeUUIDBytes(UUID
) -> Int Write a
UUID
info the buffer and advances the writer index.