Packet class

This class models the raw data that needs to be sent or received over the network. and is just a wrapper around the raw bytes/stream.

Packets can serialize and deserialize formats supported by jsonEncode using Packet.from. When using Packet.from, it assumes that the enclosed data is safe for utf8 encoding and decoding.

If you want to create a Packet from raw bytes, you have two options:

  1. If you already know all the bytes, you can use Packet.fromBytes.
  2. If you don't yet have all of the bytes, you can use the Packet constructor and keep adding bytes using the add or addAll methods

If you want to create a Packet from stream, use the Packet.fromStream constructor.

Constructors

Packet()
Packet.from(dynamic data)
Allow Packets to be created from different data types. Supported data types are: String, numbers, Map, List, and Uint8List. Complex data types such as Map and List must be supported by jsonEncode
factory
Packet.fromBytes(List<int> bytes)
Allow Packets to be created/copied from other bytes
factory
Packet.fromStream(Stream<List<int>> stream)
Allow Packets to be created from Stream
factory

Properties

bytes Uint8List
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
isStream bool
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
size int
read-only
stream Stream
read-only

Methods

add(int byte) → dynamic
addAll(Iterable<int> bytes) → dynamic
as<E>() → E
Allow transformation back to popular data types For using these methods, We're assuming it is safe to transform to String
asBool() bool
asDouble() double
asInt() int
asList() List
asMap() Map<String, dynamic>
asNumber() num
asString() String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited