/*
	CD Utils - Control-Debug utilites

	Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CDUTILS_PROTOCOL_H
#define CDUTILS_PROTOCOL_H

#include "pibytearray.h"

namespace CDUtils {

	enum CDPacketType {
		CD_Ping,
		CD_Pong,

		CD_KQuery,
		CD_KSend,
		CD_KDirectChange,

		CD_XQuery,
		CD_XSend,
		CD_XRequest,
		CD_XValues,

		CD_CQuery,
		CD_CSend,
		CD_Command,

		CD_MQuery,
		CD_MSend,
		CD_Message,
	};

# pragma pack(push,1)

	struct PacketHeader {
		int type; // CDPacketType
		int session_id;
	};

	struct PacketKDirectChange {
		PIDeque<int> path;
		PIString value;
	};

# pragma pack(pop)


inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.type << v.session_id; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.type >> v.session_id; return s;}

inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.path << v.value; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.path >> v.value; return s;}

}

#endif // CDUTILS_PROTOCOL_H
