Ejemplo n.º 1
0
        internal EncodedFramingRecord(FramingRecordType recordType, string value)
        {
            int valueByteCount = Encoding.UTF8.GetByteCount(value);
            int sizeByteCount  = IntEncoder.GetEncodedSize(valueByteCount);

            _encodedBytes    = Fx.AllocateByteArray(checked (1 + sizeByteCount + valueByteCount));
            _encodedBytes[0] = (byte)recordType;
            int offset = 1;

            offset += IntEncoder.Encode(valueByteCount, _encodedBytes, offset);
            Encoding.UTF8.GetBytes(value, 0, value.Length, _encodedBytes, offset);
            SetEncodedBytes(_encodedBytes);
        }
Ejemplo n.º 2
0
        public static ArraySegment <byte> EncodeMessageFrame(ArraySegment <byte> messageFrame)
        {
            int spaceNeeded = IntEncoder.GetEncodedSize(messageFrame.Count);
            int offset      = messageFrame.Offset - spaceNeeded;

            if (offset < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageFrame.Offset",
                                                                                                          messageFrame.Offset, SR.Format(SR.SpaceNeededExceedsMessageFrameOffset, spaceNeeded)));
            }

            byte[] buffer = messageFrame.Array;
            IntEncoder.Encode(messageFrame.Count, buffer, offset);
            return(new ArraySegment <byte>(buffer, offset, messageFrame.Count + spaceNeeded));
        }