public static void TryParse(byte[] input, out CGMessage cgMessage) { BinaryReader reader = new BinaryReader(new MemoryStream(input)); cgMessage = new CGMessage(reader); switch (cgMessage.messageType) { case MessageType.Type1: cgMessage = Module1.ContinueParse(reader, cgMessage); break; case MessageType.Type2: cgMessage = Module2.ContinueParse(reader, cgMessage); break; case MessageType.Type3: cgMessage = Module3.ContinueParse(reader, cgMessage); break; default: break; } cgMessage.ParseTailingFields(reader); }
public static Module3 ContinueParse(BinaryReader input, CGMessage cgMessage) { Module3 feature = new Module3(cgMessage); feature.value = Encoding.UTF8.GetString(input.ReadBytes(cgMessage.dataLength)); return(feature); }
public CGMessage(CGMessage cgMessage) { this.TransactionId = cgMessage.TransactionId; this.address = cgMessage.address; this.messageType = cgMessage.messageType; this.compressionType = cgMessage.compressionType; this.encryptionType = cgMessage.encryptionType; this.dataLength = cgMessage.dataLength; }
public void Handle(byte[] buffer) { CGMessage cgMessage; CGMessage.TryParse(buffer, out cgMessage); processor.Process(cgMessage); Console.WriteLine("type your reply...."); string replyMessage = Console.ReadLine(); Socket.Send(Socket.GetMessage(replyMessage)); }
public void Send(CGMessage message) { long dataGramLength; try { BinaryWriter writer = new BinaryWriter(new MemoryStream(_TransmitBuffer, 0, _TransmitBuffer.Length, true)); message.TryPublish(writer); dataGramLength = writer.BaseStream.Length; } catch (Exception ex) { Console.WriteLine("exception occured in publishing object:{0}", ex.Message); return; } _socket.SendTo(_TransmitBuffer, SocketFlags.None, CurrentRemoteIp); }
public void Process(CGMessage cgMessage) { switch (cgMessage.messageType) { case MessageType.Type1: Console.WriteLine(((Module1)cgMessage).value); break; case MessageType.Type2: Console.WriteLine(((Module2)cgMessage).value); break; case MessageType.Type3: Console.WriteLine(((Module3)cgMessage).value); break; default: break; } }
public CGMessage GetMessage(string value) { CGMessage message = null; switch (Program.CurrentMessageType) { case MessageType.Type1: message = new Module1(value); break; case MessageType.Type2: message = new Module2(value); break; case MessageType.Type3: message = new Module3(value); break; default: break; } return(message); }
public Module3(CGMessage cgMessage) : base(cgMessage) { }