internal void WriteInternal()

in Source/Tx.Bond/BinaryEventSource.cs [248:303]


        internal void WriteInternal(IEnvelope envelope)
        {
            var typeId = envelope.TypeId ?? string.Empty;
            var source = envelope.Source ?? string.Empty;
            var protocol = envelope.Protocol ?? string.Empty;

            // Maximum record size is 64K for both system and user data, so counting 88 bytes for system data here as well
            var maxPayloadSize = MaxPayloadSize - (typeId.Length + source.Length + protocol.Length) * 2;

            if (maxPayloadSize <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var occurenceFileTimeUtc = envelope.OccurrenceTime.ToFileTime();
            var receiveFileTimeUtc = envelope.ReceivedTime.ToFileTime();

            if (envelope.Payload.Length <= maxPayloadSize)
            {
                this.WriteBinaryPayload(
                    occurenceFileTimeUtc,
                    receiveFileTimeUtc,
                    protocol,
                    source,
                    typeId,
                    unchecked((uint)(envelope.Payload.Length)),
                    envelope.Payload);
            }
            else
            {
                // User data for chunked event is 12 bytes greather than non-chunked event
                maxPayloadSize -= 12;

                var chunks = envelope.Payload.Split(maxPayloadSize);

                lock (this.writeChuckedBinaryPayloadGuard)
                {
                    var packageId = unchecked(this.currentPackageId++);

                    for (uint i = 0; i < chunks.Length; i++)
                    {
                        this.WriteChunkedBinaryPayload(
                            packageId,
                            occurenceFileTimeUtc,
                            receiveFileTimeUtc,
                            protocol,
                            source,
                            typeId,
                            unchecked((uint)(chunks.Length)),
                            i,
                            unchecked((uint)(chunks[i].Length)),
                            chunks[i]);
                    }
                }
            }
        }