send method
send message through the channel
Implementation
Future<O?> send(I msg) async {
while (_socket == null) {
await Future.delayed(const Duration(milliseconds: 100));
}
List<int> msgBuffer = [];
// generate and add the id
Uint8List id = _genID();
msgBuffer.addAll(id);
// add (is reply) byte
msgBuffer.add(0);
msgBuffer.addAll(decodeInput(msg));
msgBuffer.addAll([0, 0, 0]);
try {
_socket!.add(msgBuffer);
} catch (e) {}
// wait the reply
_Message reply = await _replyMessages
.where((event) => event.id == _bytesToInt(id))
.first;
if (reply.data.isNotEmpty) {
return encodeOutput(reply.data);
}
}