private void Finish() {
if (buf != null)
return;
if (OutStream.Position > ushort.MaxValue)
throw new Exception("Packet too large " + OutStream.Position + " > " + ushort.MaxValue);
len = (ushort)OutStream.Position;
Seek(0, SeekOrigin.Begin);
Write(len);
Close();
buf = ((MemoryStream) OutStream).GetBuffer();
}
}