#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
