public UnsetFrame(long streamId, long frameId, bool fin, bool abort) : this()
 {
     this.Metadata.StreamId    = VariableInt.EncodeVariableInt(streamId);
     this.Metadata.FrameId     = VariableInt.EncodeVariableInt(frameId);
     this.Metadata.Flags.Fin   = fin;
     this.Metadata.Flags.Abort = abort;
 }
        public void Bytes_WhenFlagsAndStreamIdAndFrameIdSet_ReturnsExpectedResult()
        {
            // arrange
            var metadata = new Metadata();

            metadata.Flags.Fin = true;
            metadata.StreamId  = VariableInt.EncodeVariableInt(1);
            metadata.FrameId   = VariableInt.EncodeVariableInt(1);

            // 00000000 00000000 00000000 10000000 10000000 10000000
            BitArray ba = new BitArray(
                new bool[] {
                false, false, false, false, false, false, false, false,
                false, false, false, false, false, false, false, false,
                false, false, false, false, false, false, false, false,
                true, false, false, false, false, false, false, false,
                true, false, false, false, false, false, false, false,
                true, false, false, false, false, false, false, false
            });

            byte[] expected = new byte[6];
            ba.CopyTo(expected, 0);

            // assert
            Assert.AreEqual(
                HelperMethods.ToBitString(expected),
                HelperMethods.ToBitString(metadata.Bytes));
        }
        public void EncodeVariableInt_WhenPositiveNumber_ThenReturnsExpectedVarIntLength(long input, int length)
        {
            // act
            VariableInt result = VariableInt.EncodeVariableInt(input);

            // assert
            Assert.AreEqual(length, result.Length);
        }
        public void EncodeVariableInt_WhenPositiveNumber_ThenReturnsExpectedVarIntBytes(long input, string output)
        {
            // act
            VariableInt result = VariableInt.EncodeVariableInt(input);

            // assert
            Assert.AreEqual(output, HelperMethods.ToBitString(result.Bytes));
        }
        public void EncodeVariableInt_WhenPositiveNumber_ThenReturnsExpectedVarIntValue(long input, long output)
        {
            // act
            VariableInt result = VariableInt.EncodeVariableInt(input);

            // assert
            Assert.AreEqual(output, result.Value);
        }
 /// <summary>
 /// Initializes a new instance of the AckFrame class. An agent sends an ACK frame
 /// in response to a NOTIFY. An ACK may contain actions for HAProxy to perform.
 /// </summary>
 /// <param name="streamId">The stream ID to include in the ACK frame.</param>
 /// <param name="frameId">The frame ID to include in the ACK frame.</param>
 /// <param name="actions">A list of actions for HAProxy to apply.</param>
 public AckFrame(long streamId, long frameId, IList <SpoeAction> actions) : base(FrameType.Ack)
 {
     this.Metadata.Flags.Fin   = true;
     this.Metadata.Flags.Abort = false;
     this.Metadata.StreamId    = VariableInt.EncodeVariableInt(streamId);
     this.Metadata.FrameId     = VariableInt.EncodeVariableInt(frameId);
     this.Payload = new ListOfActionsPayload()
     {
         Actions = actions
     };
 }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the AgentHelloFrame. The agent sends a HELLO frame
        /// during the initial handshake with HAProxy.
        /// </summary>
        /// <param name="supportedSpopVersion">The SPOP version that the agent supports</param>
        /// <param name="maxFrameSize">The max size of a frame supported</param>
        public AgentHelloFrame(string supportedSpopVersion, uint maxFrameSize, string[] capabilities) : base(FrameType.AgentHello)
        {
            this.Metadata.Flags.Fin   = true;
            this.Metadata.Flags.Abort = false;
            this.Metadata.StreamId    = VariableInt.EncodeVariableInt(0);
            this.Metadata.FrameId     = VariableInt.EncodeVariableInt(0);

            var payload = new KeyValueListPayload();

            payload.KeyValueItems.Add("version", new TypedData(DataType.String, supportedSpopVersion));
            payload.KeyValueItems.Add("max-frame-size", new TypedData(DataType.Uint32, maxFrameSize));
            payload.KeyValueItems.Add("capabilities", new TypedData(DataType.String, string.Join(",", capabilities)));
            this.Payload = payload;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the AgentDisconnectFrame class. The agent sends
        /// a Disconnect frame when it wants to stop communicating with HAProxy.
        /// </summary>
        /// <param name="status">The status when disconnecting</param>
        /// <param name="message">The message to include when disconnecting</param>
        public AgentDisconnectFrame(Status status, string message) : base(FrameType.AgentDisconnect)
        {
            this.Metadata.Flags.Fin   = true;
            this.Metadata.Flags.Abort = false;
            this.Metadata.StreamId    = VariableInt.EncodeVariableInt(0);
            this.Metadata.FrameId     = VariableInt.EncodeVariableInt(0);

            var payload = new KeyValueListPayload();

            payload.KeyValueItems.Add("status-code", new TypedData(DataType.Uint32, (uint)status));
            payload.KeyValueItems.Add("message", new TypedData(DataType.String, message));
            this.Payload = payload;
            this.Status  = status;
        }