public void SetHeaderData(WvBytes data) { var it = new WvDbusIter((Dbus.Endian)data[0], "yyyyuua{yv}", data) .GetEnumerator(); endian = (Dbus.Endian)(byte)it.pop(); type = (Dbus.MType)(byte)it.pop(); flags = (Dbus.MFlag)(byte)it.pop(); it.pop(); // version it.pop(); // length serial = it.pop(); foreach (var _f in it.pop()) { var f = _f.GetEnumerator(); Dbus.Field c = (Dbus.Field)(byte)f.pop(); var v = f.pop(); switch (c) { case Dbus.Field.Sender: sender = v; break; case Dbus.Field.Destination: dest = v; break; case Dbus.Field.ReplySerial: rserial = v; break; case Dbus.Field.Signature: signature = v; break; case Dbus.Field.Path: path = v; break; case Dbus.Field.Interface: ifc = v; break; case Dbus.Field.Member: method = v; break; case Dbus.Field.ErrorName: err = v; break; default: break; // unknown field code, ignore } } }
// Tries to guess how many bytes you'll need into inbuf before you can // read an entire message. The buffer needs to have at least 16 // bytes before you can start. static void _bytes_needed(WvBytes b, out int hlen, out int blen) { wv.assert(b.len >= 16); // the real header signature is: yyyyuua{yv} // However, we only care about the first 16 bytes, and we know // that the a{yv} starts with an unsigned int that's the number // of bytes in the array, which is what we *really* want to know. // So we lie about the signature here. var it = new WvDbusIter((Dbus.Endian)b[0], "yyyyuuu", b.sub(0,16)) .GetEnumerator(); it.pop(); it.pop(); it.pop(); byte version = it.pop(); if (version < Dbus.Protocol.MinVersion || version > Dbus.Protocol.MaxVersion) throw new NotSupportedException ("Dbus.Protocol version '" + version.ToString() + "' is not supported"); uint _blen = it.pop(); // body length it.pop(); // serial uint _hlen = it.pop(); // remaining header length if (_blen > Int32.MaxValue || _hlen > Int32.MaxValue) throw new NotImplementedException ("Long messages are not yet supported"); hlen = 16 + Dbus.Protocol.Padded((int)_hlen, 8); blen = (int)_blen; }