Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength) { if ((int)valueLength < 2 || (int)valueLength > 3) { return((Option)null); } TcpOptionMoodEmotion emotion = TcpOptionMood.StringToEmotion(Encoding.ASCII.GetString(ByteArrayExtensions.ReadBytes(buffer, ref offset, (int)valueLength))); if (emotion == TcpOptionMoodEmotion.None) { return((Option)null); } return((Option) new TcpOptionMood(emotion)); }
/// <summary> /// Tries to read the option from a buffer starting from the option value (after the type and length). /// </summary> /// <param name="buffer">The buffer to read the option from.</param> /// <param name="offset">The offset to the first byte to read the buffer. Will be incremented by the number of bytes read.</param> /// <param name="valueLength">The number of bytes the option value should take according to the length field that was already read.</param> /// <returns>On success - the complex option read. On failure - null.</returns> Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength) { if (valueLength < OptionValueMinimumLength || valueLength > OptionValueMaximumLength) { return(null); } byte[] emotionBuffer = buffer.ReadBytes(ref offset, valueLength); TcpOptionMoodEmotion emotion = StringToEmotion(Encoding.ASCII.GetString(emotionBuffer)); if (emotion == TcpOptionMoodEmotion.None) { return(null); } return(new TcpOptionMood(emotion)); }
/// <summary> /// Creates the option using the given emotion. /// </summary> public TcpOptionMood(TcpOptionMoodEmotion emotion) : base(TcpOptionType.Mood) { Emotion = emotion; }
public TcpOptionMood(TcpOptionMoodEmotion emotion) : base(TcpOptionType.Mood) { this.Emotion = emotion; }