String vers array of bytes.
Bonjour,
Je me demande quelle est la meilleure méthode pour passer un string (Réception d'un socket) vers un tableau de valeures hex.
Exemples:
Mon socket recoit: 01 00 01 00 05 6b 6b 6b 6b 6b
Quelle est la meilleure facon de transformer ca, en genre
map<int, byte> M;
De telle sorte que dans une classe, je puisse parcourir dans un seul sens, mes valeurs
Voici une esquisse de la structure de la classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
class Packet {
private:
struct packet_s {
std::string pckt;
std::map<int, int> bytes;
int count;
} packet_s;
int index;
void ArrayOfBytes();
void PacketInfo();
void Next();
public:
Packet();
Packet(std::string p);
Packet(std::string p, bool nfo);
int GetHeader();
int GetAction();
int ReadInt();
long ReadLong();
std::string ReadString(int l);
void Skip();
~Packet();
};
void Packet::ArrayOfBytes() {}
Packet::Packet() {
}
Packet::Packet(std::string p) {
Packet(p, true);
}
Packet::Packet(std::string p, bool nfo) {
packet_s.pckt = p;
this->ArrayOfBytes();
// count
this->index = 0;
if(nfo) {
this->PacketInfo();
}
}
void Packet::Next() {
this->index++;
}
void Packet::Skip() {
int j=2;
if(j < 1) {
throw "cant skip";
}
this->index += j;
}
void Packet::PacketInfo() { }
int Packet::GetHeader() {}
int Packet::GetAction() {}
int Packet::ReadInt() {}
long Packet::ReadLong() {}
std::string Packet::ReadString(int l) {} |