public WvDbusMsg(WvBytes b) { int hlen, blen; _bytes_needed(b, out hlen, out blen); wv.assert(b.len == hlen+blen); SetHeaderData(b); Body = b.sub(hlen, blen).ToArray(); }
// 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; }