// serialization functions public void Serialize(BitStream message, UserCommand?old) { if (old == null) { message.WriteUInt32(ServerTime); message.WriteInt16((short)Buttons); } else { var oldCommand = old.Value; if ((ServerTime - oldCommand.ServerTime) < 255) { message.WriteBool(true); message.WriteByte((byte)(ServerTime - oldCommand.ServerTime)); } else { message.WriteBool(false); message.WriteUInt32(ServerTime); } message.WriteDeltaInt16((short)Buttons, (short)oldCommand.Buttons); } }