public void Unpack(SocketIO client, string text) { string identity = text[0].ToString(); string content = text.Substring(1); if (Enum.TryParse(identity, out SocketIOProtocol protocol)) { IUnpackable unpackger = null; switch (protocol) { case SocketIOProtocol.Connect: unpackger = new MessageConnectedPackger(); break; case SocketIOProtocol.Disconnect: unpackger = new MessageDisconnectedPackger(); break; case SocketIOProtocol.Event: unpackger = new MessageEventPackger(); break; case SocketIOProtocol.Ack: unpackger = new MessageAckPackger(); break; case SocketIOProtocol.Error: unpackger = new MessageErrorPackger(); break; case SocketIOProtocol.BinaryEvent: unpackger = new MessageBinaryEventPackger(); break; case SocketIOProtocol.BinaryAck: unpackger = new MessageBinaryAckPackger(); break; } if (unpackger != null) { if (protocol == SocketIOProtocol.Event || protocol == SocketIOProtocol.BinaryEvent) { var receivedEvent = unpackger as IReceivedEvent; receivedEvent.OnEnd += () => { client.InvokeReceivedEvent(new ReceivedEventArgs { Event = receivedEvent.EventName, Response = receivedEvent.Response }); }; } unpackger.Unpack(client, content); } } }
public void Unpack(string msg) { if (!string.IsNullOrWhiteSpace(msg)) { string identity = msg[0].ToString(); string content = msg.Substring(1); if (Enum.TryParse(identity, out EngineIOProtocol protocol)) { IUnpackable unpackger = null; switch (protocol) { case EngineIOProtocol.Open: unpackger = new OpenedPackger(); break; case EngineIOProtocol.Close: break; case EngineIOProtocol.Ping: unpackger = new PingPackger(); break; case EngineIOProtocol.Pong: unpackger = new PongPackger(); break; case EngineIOProtocol.Message: unpackger = new MessagePackger(); break; case EngineIOProtocol.Upgrade: break; case EngineIOProtocol.Noop: break; default: break; } if (unpackger != null) { unpackger.Unpack(_client, content); } } } }
public bool Read(string name, IUnpackable unpackable) { return(Read(name, (reader) => unpackable?.UnPack(reader))); }
public void Unpack(IUnpackable unpackabele) { unpackabele?.UnPack(this); }