public Interfaces.ICommand <byte> Decode(ArraySegment <byte> input) { if (input.Count != 0) { Helpers.ArraySegmentStream segstream = new Helpers.ArraySegmentStream(input); int size = segstream.GetInt32(); if (input.Count == size) { short code = segstream.GetInt16(); if (code == Code) { var function = segstream.GetInt64(); var thread = segstream.GetInt64(); var term = segstream.GetInt16(); if (term != 0) { throw new System.Runtime.Serialization.SerializationException("Terminator is a non zero value. Please check the incoming byte stream for possible errors."); } return(new FunctionsToProfile(new List <string>())); } else { throw new System.Runtime.Serialization.SerializationException("Invalid command code detected. Please check the incoming byte stream for possible errors."); } } else { throw new System.Runtime.Serialization.SerializationException("Size of message does not match size of byte stream. Please check the incoming byte stream for possible errors."); } } else { throw new System.Runtime.Serialization.SerializationException("Size of message is zero. Please check the incoming byte stream for possible errors. "); } }
public Interfaces.ICommand <byte> Decode(ArraySegment <byte> input) { if (input.Count != 0) { Helpers.ArraySegmentStream segstream = new Helpers.ArraySegmentStream(input); int size = segstream.GetInt32(); if (input.Count == size) { int code = segstream.GetInt16(); if (code == Code | code == Code + 1) { var strlen = segstream.GetInt32(); var hashcode = segstream.GetInt64(); string s = null; if (code == Code + 1) { s = segstream.GetUnicode(strlen); } else { s = segstream.GetASCII(strlen); } return(new SendString(s)); } } } return(null); }