OutgoingMessage.fromBinary constructor

OutgoingMessage.fromBinary(
  1. Uint8List data
)

Implementation

factory OutgoingMessage.fromBinary(Uint8List data) {
  var bdata = new ByteData.view(data.buffer);
  int type = bdata.getUint8(0);
  int w = 2;
  int s = 0;
  String nick = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    nick = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String avatar = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    avatar = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String text = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    text = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String sl = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    sl = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String pp = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    pp = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  int tsta = bdata.getUint64(w);
  w += 8;
  Uint8List at = Uint8List(0);
  s = bdata.getUint64(w);
  w += 8;
  if (s != 0) {
    at = data.sublist(w, w + s);
    w += s;
  }
  String cid = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    cid = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String atty = '';
  if (w < bdata.lengthInBytes - 8) {
    s = bdata.getUint16(w);
    w += 2;
    if (s != 0) {
      atty = utf8.decode(data.sublist(w, w + s));
      w += s;
    }
  }
  String xxHash = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    xxHash = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  String blurHash = '';
  s = bdata.getUint16(w);
  w += 2;
  if (s != 0) {
    blurHash = utf8.decode(data.sublist(w, w + s));
    w += s;
  }
  int atl = bdata.getUint32(w);
  w += 4;
  return OutgoingMessage(type, nick, avatar, text, sl, pp, tsta, at, cid,
      atty, xxHash, blurHash, atl);
}