/// <summary> /// Acquires an appropriate event envelope. /// </summary> /// <returns></returns> private static MeshEvent Create(MeshEventType type) { // Get the appropriate packet switch (type) { case MeshEventType.Error: case MeshEventType.Ping: case MeshEventType.PingAck: case MeshEventType.HandshakeAck: return(MeshEvent.Acquire()); case MeshEventType.Handshake: return(MeshHandshake.Acquire()); case MeshEventType.GossipDigest: case MeshEventType.GossipSince: case MeshEventType.GossipUpdate: return(MeshGossip.Acquire()); case MeshEventType.Subscribe: case MeshEventType.Unsubscribe: case MeshEventType.Custom: return(MeshEmitterEvent.Acquire()); default: throw new InvalidOperationException("Unknown mesh packet"); } }
/// <summary> /// Acquires a <see cref="MeshEvent"/> instance. /// </summary> /// <param name="type">The event type.</param> /// <param name="value">The value of the event.</param> /// <returns> A <see cref="MeshEvent"/> that can be sent to the remote client.</returns> public static MeshEvent Acquire(MeshEventType type, string value = "") { // Set the type var packet = Pool.Acquire(); packet.Type = type; packet.Value = value; return(packet); }
/// <summary> /// Acquires a <see cref="MeshEmitterEvent"/> instance. /// </summary> /// <param name="nodes">The list of nodes to populate the gossip packet with.</param> public static MeshEmitterEvent Acquire(MeshEventType type, int contract, string channel, string value = "") { // Acquires a new emitter event packet var packet = Pool.Acquire(); packet.Type = type; packet.Value = value; packet.Contract = contract; packet.Channel = channel; return(packet); }
/// <summary> /// Serializes this packet to a binary stream. /// </summary> /// <param name="reader">PacketReader used to serialize the packet.</param> public override void Read(PacketReader reader) { // Read the type this.Type = (MeshEventType)reader.ReadByte(); // Read the version and the payload var version = reader.ReadUInt16(); switch (version) { case 1: this.Value = reader.ReadString(); break; } }
/// <summary> /// Recycles the packet object. /// </summary> public override void Recycle() { this.Type = default(MeshEventType); this.Value = null; base.Recycle(); }