int CalculateSize (bool unicode)
{
var encoding = unicode ? Encoding.Unicode : Encoding.UTF8;
int length = 4;
if (!string.IsNullOrEmpty (DomainName))
length += 4 + encoding.GetByteCount (DomainName);
if (!string.IsNullOrEmpty (ServerName))
length += 4 + encoding.GetByteCount (ServerName);
if (!string.IsNullOrEmpty (DnsDomainName))
length += 4 + encoding.GetByteCount (DnsDomainName);
if (!string.IsNullOrEmpty (DnsServerName))
length += 4 + encoding.GetByteCount (DnsServerName);
if (!string.IsNullOrEmpty (DnsTreeName))
length += 4 + encoding.GetByteCount (DnsTreeName);
if (Flags.HasValue)
length += 8;
if (Timestamp != 0)
length += 12;
if (!string.IsNullOrEmpty (TargetName))
length += 4 + encoding.GetByteCount (TargetName);
return length;
}