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. The selected bytes must be readable or else nil will be returned.

    Declaration

    Swift

    public func getData(at index0: 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 selected bytes are not readable.

  • Get a String decoding length bytes starting at index with encoding. This will not change the reader index. The selected bytes must be readable or else nil will be returned.

    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 selected bytes are not readable or cannot be decoded with the given encoding.

  • Read a String decoding length bytes with encoding from the readerIndex, moving the readerIndex appropriately.

    Declaration

    Swift

    public mutating func readString(length: Int, encoding: String.Encoding) -> String?

    Parameters

    length

    The number of bytes to read.

    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 enough bytes, or if those bytes cannot be decoded with the given encoding.

  • Write string into this ByteBuffer using the encoding encoding, moving the writer index forward appropriately.

    Declaration

    Swift

    @discardableResult
    public mutating func writeString(_ string: String, encoding: String.Encoding) throws -> Int

    Parameters

    string

    The string to write.

    encoding

    The encoding to use to encode the string.

    Return Value

    The number of bytes written.

  • Write string into this ByteBuffer at index using the encoding encoding. Does not move the writer index.

    Declaration

    Swift

    @discardableResult
    public mutating func setString(_ string: String, encoding: String.Encoding, at index: Int) throws -> Int

    Parameters

    string

    The string to write.

    encoding

    The encoding to use to encode the string.

    index

    The index for the first serialized byte.

    Return Value

    The number of bytes written.