private int CalculateSize(IWriteablePacket packet) { var writer = new CountingPacketWriter(); packet.Write(writer); return(writer.Size); }
private void WritePacketToPipe(IWriteablePacket packet) { var dataSize = CalculateSize(packet) + CountingPacketWriter.GetVarIntSize(packet.Id); var packetSize = dataSize + CountingPacketWriter.GetVarIntSize(dataSize); var writer = _writerFactory.CreateWriter(_writer.GetMemory(packetSize)); writer.WriteVarInt(dataSize); writer.WriteVarInt(packet.Id); packet.Write(writer); _writer.Advance(packetSize); _metrics.Measure.Histogram.Update(MetricsRegistry.WritePacketSize, packetSize); }