internal static void WriteTransportMessage(this ProtoBufferWriter writer, TransportMessage transportMessage, string?environmentOverride = null) { writer.WriteRawTag(1 << 3 | 2); Write(writer, transportMessage.Id); writer.WriteRawTag(2 << 3 | 2); Write(writer, transportMessage.MessageTypeId); var transportMessageContent = transportMessage.Content ?? _emptyStream; writer.WriteRawTag(3 << 3 | 2); writer.WriteLength((int)transportMessageContent.Length); writer.WriteRawStream(transportMessageContent); writer.WriteRawTag(4 << 3 | 2); Write(writer, transportMessage.Originator); var environment = environmentOverride ?? transportMessage.Environment; if (environment != null) { writer.WriteRawTag(5 << 3 | 2); var environmentLength = GetUtf8ByteCount(environment); writer.WriteString(environment, environmentLength); } if (transportMessage.WasPersisted != null) { WriteWasPersisted(writer, transportMessage.WasPersisted.Value); } }