ByteBuffer

struct ByteBuffer
  • Read length bytes off this ByteBuffer, move the reader index forward by length bytes and return the result as Data.

    Declaration

    Swift

    public mutating func readData(length: Int) -> Data?

    Parameters

    length

    The number of bytes to be read from this ByteBuffer.

    Return Value

    A Data value containing length bytes or nil if there aren’t at least length bytes readable.

  • Return length bytes starting at index and return the result as Data. This will not change the reader index.

    Note

    Please consider using readData which is a safer alternative that automatically maintains the readerIndex and won’t allow you to read uninitialized memory.

    Warning

    This method allows the user to read any of the bytes in the ByteBuffer‘s storage, including uninitialized ones. To use this API in a safe way the user needs to make sure all the requested bytes have been written before and are therefore initialized. Note that bytes between (including) readerIndex and (excluding) writerIndex are always initialized by contract and therefore must be safe to read.

    Declaration

    Swift

    public func getData(at index: Int, length: Int) -> Data?

    Parameters

    index

    The starting index of the bytes of interest into the ByteBuffer

    length

    The number of bytes of interest

    Return Value

    A Data value containing the bytes of interest or nil if the ByteBuffer doesn’t contain those bytes.

  • Get a String decoding length bytes starting at index with encoding. This will not change the reader index.

    Note

    Please consider using readString which is a safer alternative that automatically maintains the readerIndex and won’t allow you to read uninitialized memory.

    Warning

    This method allows the user to read any of the bytes in the ByteBuffer‘s storage, including uninitialized ones. To use this API in a safe way the user needs to make sure all the requested bytes have been written before and are therefore initialized. Note that bytes between (including) readerIndex and (excluding) writerIndex are always initialized by contract and therefore must be safe to read.

    Declaration

    Swift

    public func getString(at index: Int, length: Int, encoding: String.Encoding) -> String?

    Parameters

    index

    The starting index of the bytes of interest into the ByteBuffer.

    length

    The number of bytes of interest.

    encoding

    The String encoding to be used.

    Return Value

    A String value containing the bytes of interest or nil if the ByteBuffer doesn’t contain those bytes.