Esempio n. 1
0
        public int WriteFrame(short streamId, MemoryStream stream, ISerializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);
            var protocolVersion = serializer.ProtocolVersion;

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteShortBytes(_id);

            if (protocolVersion.SupportsResultMetadataId())
            {
                wb.WriteShortBytes(_resultMetadataId);
            }

            _queryOptions.Write(wb, true);
            return(wb.Close());
        }
 public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
 {
     var wb = new FrameWriter(stream, serializer);
     wb.WriteFrameHeader(0x00, streamId, OpCode);
     wb.WriteStringList(_eventTypes);
     return wb.Close();
 }
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     var wb = new FrameWriter(stream);
     wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
     wb.WriteStringList(_eventTypes);
     return wb.Close();
 }
Esempio n. 4
0
        public int WriteFrame(short streamId, MemoryStream stream)
        {
            var wb = new FrameWriter(stream);

            wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
            return(wb.Close());
        }
 internal void WriteMessage(ReadOnlyMemory <byte> message, ref ValueWriter writer)
 {
     FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, _channelId, message.Length, ref writer);
     writer.WriteBytes(message.Span);
     writer.WriteOctet(RabbitMQConstants.FrameEnd);
     writer.Commit();
 }
        public void BeBinaryWriter_Close_Sets_Frame_Body_Length()
        {
            const int  frameLength     = 10;
            const int  iterations      = 8;
            const byte protocolVersion = 2;
            var        bufferPool      = new RecyclableMemoryStreamManager();

            using (var stream = bufferPool.GetStream("test"))
            {
                for (var i = 0; i < iterations; i++)
                {
                    var writer = new FrameWriter(stream, new Serializer(protocolVersion));
                    writer.WriteFrameHeader(0, 127, 8);
                    writer.WriteInt16(Convert.ToInt16(0x0900 + i));
                    var length = writer.Close();
                    Assert.AreEqual(frameLength, length);
                }
                Assert.AreEqual(frameLength * iterations, stream.Length);
                for (byte i = 0; i < iterations; i++)
                {
                    var buffer = new byte[frameLength];
                    stream.Position = i * frameLength;
                    stream.Read(buffer, 0, frameLength);
                    CollectionAssert.AreEqual(new byte[] { 2, 0, 127, 8, 0, 0, 0, 2, 9, i }, buffer);
                }
            }
        }
 public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
 {
     var wb = new FrameWriter(stream, serializer);
     wb.WriteFrameHeader(0x00, streamId, OpCode);
     wb.WriteBytes(_token);
     return wb.Close();
 }
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     var wb = new FrameWriter(stream);
     wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
     wb.WriteBytes(_token);
     return wb.Close();
 }
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);

            wb.WriteFrameHeader(0x00, streamId, OpCode);
            return(wb.Close());
        }
Esempio n. 10
0
        public int WriteFrame(short streamId, MemoryStream stream, ISerializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);

            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            var protocolVersion = serializer.ProtocolVersion;

            if (_payload != null)
            {
                wb.WriteBytesMap(_payload);
            }

            wb.WriteLongString(Query);

            if (protocolVersion.SupportsKeyspaceInRequest())
            {
                wb.WriteInt32((int)_prepareFlags);
                if (Keyspace != null)
                {
                    wb.WriteString(Keyspace);
                }
            }

            return(wb.Close());
        }
Esempio n. 11
0
        public void WriteMessage(NoPaylodMethodInfo message, IBufferWriter <byte> output)
        {
            var writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(message.FrameType, message.Channel, 4, ref writer);
            FrameWriter.WriteMethodFrame(message.ClassId, message.MethodId, ref writer);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
Esempio n. 12
0
        public void WriteMessage(byte[] message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameBody, _channelId, message.Length, ref writer);
            writer.WriteBytes(message);
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
Esempio n. 13
0
        public void WriteMessage(RejectInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channel, 13, ref writer);
            FrameWriter.WriteMethodFrame(60, 90, ref writer);
            writer.WriteLongLong(message.DeliveryTag);
            writer.WriteBit(message.Requeue);
            writer.WriteOctet(Constants.FrameEnd);
        }
Esempio n. 14
0
        public void WriteMessage(ushort message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, message, 5, ref writer);
            FrameWriter.WriteMethodFrame(20, 10, ref writer);
            writer.WriteOctet(0);
            writer.WriteOctet(206);
            writer.Commit();
        }
Esempio n. 15
0
 public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
 {
     var wb = new FrameWriter(stream, serializer);
     wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
     if (Payload != null)
     {
         wb.WriteBytesMap(Payload);
     }
     wb.WriteLongString(Query);
     return wb.Close();
 }
Esempio n. 16
0
        private void WriteFrameHeader(FrameWriter writer, short streamId)
        {
            var flags = _headerFlags;

            if (writer.Serializer.ProtocolVersion.IsBeta())
            {
                flags |= HeaderFlags.UseBeta;
            }

            writer.WriteFrameHeader((byte)flags, streamId, OpCode);
        }
Esempio n. 17
0
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     var wb = new FrameWriter(stream);
     wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
     wb.WriteUInt16((ushort) _options.Count);
     foreach (var kv in _options)
     {
         wb.WriteString(kv.Key);
         wb.WriteString(kv.Value);
     }
     return wb.Close();
 }
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);

            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                wb.WriteBytesMap(Payload);
            }
            wb.WriteLongString(Query);
            return(wb.Close());
        }
        public void WriteMessage(AckInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channelId, 13, ref writer);
            FrameWriter.WriteMethodFrame(60, 80, ref writer);
            writer.WriteLongLong(message.DeliveryTag);
            writer.WriteBit(message.Multiple);
            writer.BitFlush();
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
Esempio n. 20
0
        public void WriteMessage(RabbitMQMainInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, 0, 12, ref writer);
            FrameWriter.WriteMethodFrame(10, 31, ref writer);
            writer.WriteShortInt(message.ChannelMax);
            writer.WriteLong(message.FrameMax);
            writer.WriteShortInt(message.Heartbeat);
            writer.WriteOctet(206);
            writer.Commit();
        }
Esempio n. 21
0
        public void WriteMessage(ReadOnlyMemory <byte> message, IBufferWriter <byte> output)
        {
            if (message.IsEmpty)
            {
                return;
            }
            var writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, _channelId, message.Length, ref writer);
            writer.WriteBytes(message.Span);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
Esempio n. 22
0
        public void WriteMessage(QoSInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, _channel, 11, ref writer);
            FrameWriter.WriteMethodFrame(60, 10, ref writer);
            writer.WriteLong(message.PrefetchSize);
            writer.WriteShortInt(message.PrefetchCount);
            writer.WriteBool(message.Global);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            writer.Commit();
        }
Esempio n. 23
0
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);

            wb.WriteFrameHeader(0x00, streamId, StartupRequest.OpCode);
            wb.WriteUInt16((ushort)_options.Count);
            foreach (var kv in _options)
            {
                wb.WriteString(kv.Key);
                wb.WriteString(kv.Value);
            }
            return(wb.Close());
        }
Esempio n. 24
0
        public int WriteFrame(short streamId, MemoryStream stream)
        {
            var wb = new FrameWriter(stream);

            wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
            wb.WriteUInt16((ushort)_options.Count);
            foreach (var kv in _options)
            {
                wb.WriteString(kv.Key);
                wb.WriteString(kv.Value);
            }
            return(wb.Close());
        }
Esempio n. 25
0
        public int WriteFrame(short streamId, MemoryStream stream, ISerializer serializer)
        {
            //protocol v2: <type><n><query_1>...<query_n><consistency>
            //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var protocolVersion = serializer.ProtocolVersion;
            var wb = new FrameWriter(stream, serializer);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteByte((byte)_type);
            wb.WriteUInt16((ushort)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch(wb);
            }
            wb.WriteUInt16((ushort)Consistency);
            if (protocolVersion.SupportsTimestamp())
            {
                if (protocolVersion.Uses4BytesQueryFlags())
                {
                    wb.WriteInt32((int)_batchFlags);
                }
                else
                {
                    wb.WriteByte((byte)_batchFlags);
                }

                wb.WriteUInt16((ushort)SerialConsistency);

                if (_timestamp != null)
                {
                    wb.WriteLong(_timestamp.Value);
                }

                if (_keyspace != null)
                {
                    wb.WriteString(_keyspace);
                }
            }
            return(wb.Close());
        }
Esempio n. 26
0
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            if (serializer.ProtocolVersion > 1)
            {
                throw new NotSupportedException("Credentials request is only supported in C* = 1.2.x");
            }

            var wb = new FrameWriter(stream, serializer);
            wb.WriteFrameHeader(0x00, streamId, OpCode);
            wb.WriteUInt16((ushort) _credentials.Count);
            foreach (var kv in _credentials)
            {
                wb.WriteString(kv.Key);
                wb.WriteString(kv.Value);
            }
            return wb.Close();
        }
        internal void WriteMessage(ref BasicPublishInfo message, ref ValueWriter writer)
        {
            var payloadSize = 9 + message.ExchangeName.Length + message.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameMethod, _channelid, payloadSize, ref writer);
            //var checkpoint = writer.Written;
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.ExchangeName);
            writer.WriteShortStr(message.RoutingKey);
            writer.WriteBit(message.Mandatory);
            writer.WriteBit(message.Immediate);
            writer.BitFlush();
            //var size = writer.Written - checkpoint;
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
Esempio n. 28
0
        public int WriteFrame(short streamId, MemoryStream stream)
        {
            if (ProtocolVersion > 1)
            {
                throw new NotSupportedException("Credentials request is only supported in C* = 1.2.x");
            }

            var wb = new FrameWriter(stream);

            wb.WriteFrameHeader((byte)ProtocolVersion, 0x00, streamId, OpCode);
            wb.WriteUInt16((ushort)_credentials.Count);
            foreach (var kv in _credentials)
            {
                wb.WriteString(kv.Key);
                wb.WriteString(kv.Value);
            }
            return(wb.Close());
        }
Esempio n. 29
0
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            var wb = new FrameWriter(stream, serializer);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteLongString(_cqlQuery);
            _queryOptions.Write(wb, false);
            return(wb.Close());
        }
Esempio n. 30
0
        public void WriteMessage(BasicPublishInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer      = new ValueWriter(output);
            var         payloadSize = 9 + message.ExchangeName.Length + message.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channelid, payloadSize, ref writer);
            //var checkpoint = writer.Written;
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.ExchangeName);
            writer.WriteShortStr(message.RoutingKey);
            writer.WriteBit(message.Mandatory);
            writer.WriteBit(message.Immediate);
            writer.BitFlush();
            //var size = writer.Written - checkpoint;
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
Esempio n. 31
0
        public int WriteFrame(short streamId, MemoryStream stream)
        {
            var wb = new FrameWriter(stream);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)ProtocolVersion, (byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteShortBytes(_id);
            _queryOptions.Write(wb, (byte)ProtocolVersion, true);
            return(wb.Close());
        }
Esempio n. 32
0
        public void WriteMessage(PublishAllInfo message, IBufferWriter <byte> output)
        {
            var writer = new ValueWriter(output);

            var framePayloadSize = 9 + message.Info.ExchangeName.Length + message.Info.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameMethod, message.ChannelId, framePayloadSize, ref writer);
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.Info.ExchangeName);
            writer.WriteShortStr(message.Info.RoutingKey);
            writer.WriteBit(message.Info.Mandatory);
            writer.WriteBit(message.Info.Immediate);
            writer.BitFlush();
            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            _bitCount = 0;
            _flagWord = 0;
            writer.WriteOctet(RabbitMQConstants.FrameHeader);
            writer.WriteShortInt(message.ChannelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            writer.WriteShortInt(message.Header.ClassId);
            writer.WriteShortInt(message.Header.Weight);
            writer.WriteLongLong(message.Header.BodySize);
            WriteBitFlagsAndContinuation(ref message.Header.Properties, ref writer);
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, message.ChannelId, message.Body.Length, ref writer);
            writer.WriteBytes(message.Body.Span);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);


            writer.Commit();
        }
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            //protocol v2: <type><n><query_1>...<query_n><consistency>
            //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var protocolVersion = serializer.ProtocolVersion;
            var wb = new FrameWriter(stream, serializer);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteByte((byte)_type);
            wb.WriteInt16((short)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch(wb);
            }
            wb.WriteInt16((short)Consistency);
            if (protocolVersion >= 3)
            {
                wb.WriteByte((byte)_batchFlags);
            }
            if (_serialConsistency != null)
            {
                wb.WriteInt16((short)_serialConsistency.Value);
            }
            if (_timestamp != null)
            {
                //Expressed in microseconds
                wb.WriteLong(TypeSerializer.SinceUnixEpoch(_timestamp.Value).Ticks / 10);
            }
            return(wb.Close());
        }
Esempio n. 34
0
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     var wb = new FrameWriter(stream);
     if (Payload != null)
     {
         _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
     }
     wb.WriteFrameHeader((byte)ProtocolVersion, (byte)_headerFlags, streamId, OpCode);
     if (Payload != null)
     {
         //A custom payload for this request
         wb.WriteBytesMap(Payload);
     }
     wb.WriteShortBytes(_id);
     _queryOptions.Write(wb, (byte)ProtocolVersion, true);
     return wb.Close();
 }
Esempio n. 35
0
 public void BeBinaryWriter_Close_Sets_Frame_Body_Length()
 {
     const int frameLength = 10;
     const int iterations = 8;
     var bufferPool = new RecyclableMemoryStreamManager();
     using (var stream = bufferPool.GetStream("test"))
     {
         for (var i = 0; i < iterations; i++)
         {
             var writer = new FrameWriter(stream);
             writer.WriteFrameHeader(2, 0, 127, 8);
             writer.WriteInt16(Convert.ToInt16(0x0900 + i));
             var length = writer.Close();
             Assert.AreEqual(frameLength, length);
         }
         Assert.AreEqual(frameLength * iterations, stream.Length);
         for (byte i = 0; i < iterations; i++)
         {
             var buffer = new byte[frameLength];
             stream.Position = i * frameLength;
             stream.Read(buffer, 0, frameLength);
             CollectionAssert.AreEqual(new byte[] { 2, 0, 127, 8, 0, 0, 0, 2, 9, i}, buffer);
         }
     }
 }
Esempio n. 36
0
 public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
 {
     var wb = new FrameWriter(stream, serializer);
     if (Payload != null)
     {
         _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
     }
     wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
     if (Payload != null)
     {
         //A custom payload for this request
         wb.WriteBytesMap(Payload);
     }
     wb.WriteLongString(_cqlQuery);
     _queryOptions.Write(wb, false);
     return wb.Close();
 }
Esempio n. 37
0
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     //protocol v2: <type><n><query_1>...<query_n><consistency>
     //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
     var wb = new FrameWriter(stream);
     if (Payload != null)
     {
         _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
     }
     wb.WriteFrameHeader((byte)ProtocolVersion, (byte)_headerFlags, streamId, OpCode);
     if (Payload != null)
     {
         //A custom payload for this request
         wb.WriteBytesMap(Payload);
     }
     wb.WriteByte((byte) _type);
     wb.WriteInt16((short) _requests.Count);
     foreach (var br in _requests)
     {
         br.WriteToBatch((byte)ProtocolVersion, wb);
     }
     wb.WriteInt16((short) Consistency);
     if (ProtocolVersion >= 3)
     {
         wb.WriteByte((byte)_batchFlags);
     }
     if (_serialConsistency != null)
     {
         wb.WriteInt16((short)_serialConsistency.Value);
     }
     if (_timestamp != null)
     {
         //Expressed in microseconds
         wb.WriteLong(TypeCodec.ToUnixTime(_timestamp.Value).Ticks / 10);
     }
     return wb.Close();
 }