Documentation
¶
Overview ¶
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.
Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
Index ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsStreamPeer() Instance
- func (self Instance) BigEndian() bool
- func (self Instance) Get16() int
- func (self Instance) Get32() int
- func (self Instance) Get64() int
- func (self Instance) Get8() int
- func (self Instance) GetAvailableBytes() int
- func (self Instance) GetData(bytes int) (error, []uint8)
- func (self Instance) GetDouble() Float.X
- func (self Instance) GetFloat() Float.X
- func (self Instance) GetHalf() Float.X
- func (self Instance) GetPartialData(bytes int) (error, []uint8)
- func (self Instance) GetString() string
- func (self Instance) GetU16() int
- func (self Instance) GetU32() int
- func (self Instance) GetU64() int
- func (self Instance) GetU8() int
- func (self Instance) GetUtf8String() string
- func (self Instance) GetVar() any
- func (self Instance) ID() ID
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) Put16(value int)
- func (self Instance) Put32(value int)
- func (self Instance) Put64(value int)
- func (self Instance) Put8(value int)
- func (self Instance) PutData(data []byte) error
- func (self Instance) PutDouble(value Float.X)
- func (self Instance) PutFloat(value Float.X)
- func (self Instance) PutHalf(value Float.X)
- func (self Instance) PutPartialData(data []byte) (error, int)
- func (self Instance) PutString(value string)
- func (self Instance) PutU16(value int)
- func (self Instance) PutU32(value int)
- func (self Instance) PutU64(value int)
- func (self Instance) PutU8(value int)
- func (self Instance) PutUtf8String(value string)
- func (self Instance) PutVar(value any)
- func (self Instance) SetBigEndian(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type MoreArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsStreamPeer ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.StreamPeer
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsStreamPeer ¶
func (Instance) BigEndian ¶
If true, this StreamPeer will using big-endian format for encoding and decoding.
func (Instance) GetAvailableBytes ¶
Returns the number of bytes this StreamPeer has available.
func (Instance) GetData ¶
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, an [Error] code and a data array.
func (Instance) GetPartialData ¶
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 [Error] code and a data array.
func (Instance) GetString ¶
Gets an ASCII string with byte-length 'bytes' from the stream. If 'bytes' is negative (default) the length will be read from the stream using the reverse process of PutString.
func (Instance) GetUtf8String ¶
Gets a UTF-8 string with byte-length 'bytes' from the stream (this decodes the string sent as UTF-8). If 'bytes' is negative (default) the length will be read from the stream using the reverse process of PutUtf8String.
func (Instance) GetVar ¶
Gets a Variant from the stream. If 'allow_objects' is true, decoding objects is allowed.
Internally, this uses the same decoding mechanism as the @GlobalScope.BytesToVar method.
Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) PutData ¶
Sends a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an [Error] code.
func (Instance) PutPartialData ¶
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 [Error] code and an integer, describing how much data was actually sent.
func (Instance) PutString ¶
Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
Note: To put an ASCII string without prepending its size, you can use PutData:
streamPeer.PutData([]byte("Hello world"))
func (Instance) PutUtf8String ¶
Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
Note: To put a UTF-8 string without prepending its size, you can use PutData:
streamPeer.PutData([]byte("Hello World"))
func (Instance) PutVar ¶
Puts a Variant into the stream. If 'full_objects' is true encoding objects is allowed (and can potentially include code).
Internally, this uses the same encoding mechanism as the @GlobalScope.VarToBytes method.
func (Instance) SetBigEndian ¶
SetBigEndian sets the property returned by [IsBigEndianEnabled].
type MoreArgs ¶
type MoreArgs [1]gdclass.StreamPeer
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) GetString ¶
Gets an ASCII string with byte-length 'bytes' from the stream. If 'bytes' is negative (default) the length will be read from the stream using the reverse process of PutString.
func (MoreArgs) GetUtf8String ¶
Gets a UTF-8 string with byte-length 'bytes' from the stream (this decodes the string sent as UTF-8). If 'bytes' is negative (default) the length will be read from the stream using the reverse process of PutUtf8String.
func (MoreArgs) GetVar ¶
Gets a Variant from the stream. If 'allow_objects' is true, decoding objects is allowed.
Internally, this uses the same decoding mechanism as the @GlobalScope.BytesToVar method.
Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.