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 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; }
internal override void Parse(byte[] buffer, ref int offset) { while (offset < buffer.Length) { VariableInt messageNameLength = VariableInt.DecodeVariableInt(buffer.Skip(offset).ToArray()); offset += messageNameLength.Length; string messageName = Encoding.ASCII.GetString(buffer, offset, (int)messageNameLength.Value); offset += messageName.Length; byte numberOfArgs = buffer.Skip(offset).Take(1).First(); offset++; var message = new SpoeMessage(messageName); for (byte i = 0; i < numberOfArgs; i++) { VariableInt keyNameLength = VariableInt.DecodeVariableInt(buffer.Skip(offset).ToArray()); offset += keyNameLength.Length; string keyname = Encoding.ASCII.GetString(buffer, offset, (int)keyNameLength.Value); offset += keyname.Length; TypedData data = TypedDataParser.ParseNext(buffer, ref offset); message.Args.Add(keyname, data); } this.Messages.Add(message); } }
/// <summary> /// Initializes a new instance of the <see cref="ParticleEmitter"/> class. /// </summary> /// <param name="owner">The <see cref="IParticleEffect"/> that owns this <see cref="IParticleEmitter"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="owner"/> is null.</exception> protected ParticleEmitter(IParticleEffect owner) { if (owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; ((ParticleEffect)owner).AddParticleEmitter(this); _budget = DefaultBudget; _particles = new Particle[_initialParticleArraySize]; // Set some default values BlendMode = _defaultBlendMode; ParticleLife = new VariableInt(2000); ReleaseAmount = new VariableUShort(1); ReleaseColor = new VariableColor(Color.White); ReleaseRate = new VariableUShort(100); ReleaseRotation = new VariableFloat(0); ReleaseScale = new VariableFloat(1); ReleaseSpeed = new VariableFloat(50); Name = DefaultName; }
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 }; }
private void Awake() { playerInfo = PullPush.player; playerSelection = PullPush.playerCharacter; afterFightButton.interactable = false; playerDeathButton.interactable = false; demonkidBeaten.interactable = false; battle = battleState.talking; timeBetweenTurns = attackTime.floatingPoint; SelectedFoe(enemyLevel.number); PlayerCharacter(playerSelection.number); }
/// <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; }
/// <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; }
public void RandomVariableIntTest() { for (var i = 0; i < _randomVariableTestIterations; i++) { const int min = int.MinValue; const int max = int.MaxValue; var a = RandomHelper.NextInt(min, max); var b = RandomHelper.NextInt(min, max); var v = new VariableInt(a, b); WriteTest(v, (x, y, z) => x.Write(y, (VariableInt)z), (x, y) => x.ReadVariableInt(y)); } }
internal override void Parse(byte[] buffer, ref int offset) { while (offset < buffer.Length) { // key-value format: [length-of-keyname(varint)][keyname][datatype][value] VariableInt keyNameLength = VariableInt.DecodeVariableInt(buffer.Skip(offset).ToArray()); offset += keyNameLength.Length; string keyname = Encoding.ASCII.GetString(buffer, offset, (int)keyNameLength.Value); offset += keyname.Length; TypedData data = TypedDataParser.ParseNext(buffer, ref offset); this.KeyValueItems.Add(keyname, data); } }
public void DecodeVariableInt_WhenGivenBuffer_ThenReturnsExpectedValue() { // arrange // 0001111111110100 BitArray ba = new BitArray( new bool[] { false, false, false, true, true, true, true, true, true, true, true, true, false, true, false, false }); byte[] buffer = new byte[2]; ba.CopyTo(buffer, 0); // act VariableInt result = VariableInt.DecodeVariableInt(buffer); // assert Assert.AreEqual(1000, result.Value); }
/// <summary> /// Initializes a new instance of the <see cref="ParticleEmitter"/> class. /// </summary> /// <param name="owner">The <see cref="IParticleEffect"/> that owns this <see cref="IParticleEmitter"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="owner"/> is null.</exception> protected ParticleEmitter(IParticleEffect owner) { if (owner == null) throw new ArgumentNullException("owner"); _owner = owner; ((ParticleEffect)owner).AddParticleEmitter(this); _budget = DefaultBudget; _particles = new Particle[_initialParticleArraySize]; // Set some default values BlendMode = _defaultBlendMode; ParticleLife = new VariableInt(2000); ReleaseAmount = new VariableUShort(1); ReleaseColor = new VariableColor(Color.White); ReleaseRate = new VariableUShort(100); ReleaseRotation = new VariableFloat(0); ReleaseScale = new VariableFloat(1); ReleaseSpeed = new VariableFloat(50); Name = DefaultName; }