StreamPeer
Abstract base class for interacting with streams.
StreamPeer.swift:14class StreamPeer
StreamPeer is an abstract base class mostly used for stream-based protocols (such as TCP). It provides an API for sending and receiving data through streams as raw data or strings.
Superclasses
class RefCounted
Base class for reference-counted objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var bigEndian: Bool
If
true
, thisStreamPeer
will using big-endian format for encoding and decoding.func get16(
) -> Int16 Gets a signed 16-bit value from the stream.
func get32(
) -> Int32 Gets a signed 32-bit value from the stream.
func get64(
) -> Int Gets a signed 64-bit value from the stream.
func get8(
) -> Int8 Gets a signed byte from the stream.
func getAvailableBytes(
) -> Int32 Returns the number of bytes this
StreamPeer
has available.func getData(bytes: Int32
) -> GArray Returns a chunk data with the received bytes. The number of bytes to be received can be requested in the
bytes
argument. If not enough bytes are available, the function will block until the desired amount is received. This function returns two values, anGodotError
code and a data array.func getDouble(
) -> Double Gets a double-precision float from the stream.
func getFloat(
) -> Double Gets a single-precision float from the stream.
func getPartialData(bytes: Int32
) -> GArray Returns a chunk data with the received bytes. The number of bytes to be received can be requested in the “bytes” argument. If not enough bytes are available, the function will return how many were actually received. This function returns two values, an
GodotError
code, and a data array.func getString(bytes: Int32
) -> String Gets an ASCII string with byte-length
bytes
from the stream. Ifbytes
is negative (default) the length will be read from the stream using the reverse process ofputString(value:)
.func getU16(
) -> UInt16 Gets an unsigned 16-bit value from the stream.
func getU32(
) -> UInt32 Gets an unsigned 32-bit value from the stream.
func getU64(
) -> UInt Gets an unsigned 64-bit value from the stream.
func getU8(
) -> UInt8 Gets an unsigned byte from the stream.
func getUtf8String(bytes: Int32
) -> String Gets a UTF-8 string with byte-length
bytes
from the stream (this decodes the string sent as UTF-8). Ifbytes
is negative (default) the length will be read from the stream using the reverse process ofputUtf8String(value:)
.func getVar(allowObjects: Bool
) -> Variant Gets a Variant from the stream. If
allowObjects
istrue
, decoding objects is allowed.func put16(value: Int16
) Puts a signed 16-bit value into the stream.
func put32(value: Int32
) Puts a signed 32-bit value into the stream.
func put64(value: Int
) Puts a signed 64-bit value into the stream.
func put8(value: Int8
) Puts a signed byte into the stream.
func putData(PackedByteArray
) -> GodotError Sends a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an
GodotError
code.func putDouble(value: Double
) Puts a double-precision float into the stream.
func putFloat(value: Double
) Puts a single-precision float into the stream.
func putPartialData(PackedByteArray
) -> GArray Sends a chunk of data through the connection. If all the data could not be sent at once, only part of it will. This function returns two values, an
GodotError
code and an integer, describing how much data was actually sent.func putString(value: String
) Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
func putU16(value: UInt16
) Puts an unsigned 16-bit value into the stream.
func putU32(value: UInt32
) Puts an unsigned 32-bit value into the stream.
func putU64(value: UInt
) Puts an unsigned 64-bit value into the stream.
func putU8(value: UInt8
) Puts an unsigned byte into the stream.
func putUtf8String(value: String
) Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
func putVar(value: Variant, fullObjects: Bool
) Puts a Variant into the stream. If
fullObjects
istrue
encoding objects is allowed (and can potentially include code).
Subclasses
class StreamPeerBuffer
A stream peer used to handle binary data streams.
class StreamPeerExtension
class StreamPeerGZIP
A stream peer that handles GZIP and deflate compression/decompression.
class StreamPeerTCP
A stream peer that handles TCP connections.
class StreamPeerTLS
A stream peer that handles TLS connections.