Function Message.maxSerializedSize

Gives the estimated serialized size

ulong maxSerializedSize() pure nothrow @nogc scope @safe const;

This routine can be used to avoid serialization if it goes over the payload size (either 512 or EDNS0-set) expectation. Note that this does not take into account compression, which could significantly reduce the size.