Esempio n. 1
0
        // Placed object message payload into a segment.
        private ArraySegment <byte> EncodeMessageIntoSegment(StreamPosition streamPosition, EventData queueMessage)
        {
            byte[] propertiesBytes = queueMessage.SerializeProperties();
            byte[] payload         = queueMessage.GetBytes();
            // get size of namespace, offset, partitionkey, properties, and payload
            int size = SegmentBuilder.CalculateAppendSize(streamPosition.StreamIdentity.Namespace) +
                       SegmentBuilder.CalculateAppendSize(queueMessage.Offset) +
                       SegmentBuilder.CalculateAppendSize(queueMessage.PartitionKey) +
                       SegmentBuilder.CalculateAppendSize(propertiesBytes) +
                       SegmentBuilder.CalculateAppendSize(payload);

            // get segment
            ArraySegment <byte> segment = GetSegment(size);

            // encode namespace, offset, partitionkey, properties and payload into segment
            int writeOffset = 0;

            SegmentBuilder.Append(segment, ref writeOffset, streamPosition.StreamIdentity.Namespace);
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Offset);
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.PartitionKey);
            SegmentBuilder.Append(segment, ref writeOffset, propertiesBytes);
            SegmentBuilder.Append(segment, ref writeOffset, payload);

            return(segment);
        }
Esempio n. 2
0
        // Placed object message payload into a segment from a buffer pool.  When this get's too big, older blocks will be purged
        private ArraySegment <byte> SerializeMessageIntoPooledSegment(EventData queueMessage)
        {
            byte[] payloadBytes    = queueMessage.GetBytes();
            string streamNamespace = queueMessage.GetStreamNamespaceProperty();
            int    size            = SegmentBuilder.CalculateAppendSize(streamNamespace) +
                                     SegmentBuilder.CalculateAppendSize(queueMessage.Offset) +
                                     SegmentBuilder.CalculateAppendSize(payloadBytes);

            // get segment from current block
            ArraySegment <byte> segment;

            if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment))
            {
                // no block or block full, get new block and try again
                currentBuffer = bufferPool.Allocate();
                currentBuffer.SetPurgeAction(PurgeAction);
                // if this fails with clean block, then requested size is too big
                if (!currentBuffer.TryGetSegment(size, out segment))
                {
                    string errmsg = String.Format(CultureInfo.InvariantCulture,
                                                  "Message size is to big. MessageSize: {0}", size);
                    throw new ArgumentOutOfRangeException("queueMessage", errmsg);
                }
            }
            // encode namespace, offset, and payload into segment
            int writeOffset = 0;

            SegmentBuilder.Append(segment, ref writeOffset, streamNamespace);
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Offset);
            SegmentBuilder.Append(segment, ref writeOffset, payloadBytes);

            return(segment);
        }
        // Placed object message payload into a segment.
        private ArraySegment <byte> EncodeMessageIntoSegment(StreamPosition streamPosition, EventData queueMessage)
        {
            byte[] propertiesBytes = queueMessage.SerializeProperties(this.serializationManager);
#if !BUILD_FLAVOR_LEGACY
            byte[] payload = queueMessage.Body.Array;
#else
            byte[] payload = queueMessage.GetBytes();
#endif
            // get size of namespace, offset, partitionkey, properties, and payload
            int size = SegmentBuilder.CalculateAppendSize(streamPosition.StreamIdentity.Namespace) +
#if !BUILD_FLAVOR_LEGACY
                       SegmentBuilder.CalculateAppendSize(queueMessage.SystemProperties.Offset) +
                       SegmentBuilder.CalculateAppendSize(queueMessage.SystemProperties.PartitionKey) +
#else
                       SegmentBuilder.CalculateAppendSize(queueMessage.Offset) +
                       SegmentBuilder.CalculateAppendSize(queueMessage.PartitionKey) +
#endif
                       SegmentBuilder.CalculateAppendSize(propertiesBytes) +
                       SegmentBuilder.CalculateAppendSize(payload);

            // get segment
            ArraySegment <byte> segment = GetSegment(size);

            // encode namespace, offset, partitionkey, properties and payload into segment
            int writeOffset = 0;
            SegmentBuilder.Append(segment, ref writeOffset, streamPosition.StreamIdentity.Namespace);
#if !BUILD_FLAVOR_LEGACY
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.SystemProperties.Offset);
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.SystemProperties.PartitionKey);
#else
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Offset);
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.PartitionKey);
#endif
            SegmentBuilder.Append(segment, ref writeOffset, propertiesBytes);
            SegmentBuilder.Append(segment, ref writeOffset, payload);

            return(segment);
        }
Esempio n. 4
0
        // Placed object message payload into a segment.
        protected virtual ArraySegment <byte> EncodeMessageIntoSegment(EventData queueMessage, Func <int, ArraySegment <byte> > getSegment)
        {
            byte[] propertiesBytes = queueMessage.SerializeProperties(this.serializer);
            var    payload         = queueMessage.Body;
            // get size of namespace, offset, partitionkey, properties, and payload
            int size = SegmentBuilder.CalculateAppendSize(queueMessage.Offset.ToString()) +
                       SegmentBuilder.CalculateAppendSize(queueMessage.PartitionKey) +
                       SegmentBuilder.CalculateAppendSize(propertiesBytes) +
                       SegmentBuilder.CalculateAppendSize(payload);

            // get segment
            ArraySegment <byte> segment = getSegment(size);

            // encode namespace, offset, partitionkey, properties and payload into segment
            int writeOffset = 0;

            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Offset.ToString());
            SegmentBuilder.Append(segment, ref writeOffset, queueMessage.PartitionKey);
            SegmentBuilder.Append(segment, ref writeOffset, propertiesBytes);
            SegmentBuilder.Append(segment, ref writeOffset, payload);

            return(segment);
        }