J'ai finalement trouvé une solution. Et cela était plus simple que je le pensait.
Exemple pour PartyMember:
public void toByteTable(byte[] tab, int startInd)
{
//copi l'entier à partir de startInd j'usqu'à (startInd + la longueur du champ)
Functions.intToByteTab(account_id, startInd,
startInd += Constants.INT_LENTH, tab);
Functions.intToByteTab(char_id, startInd,
startInd += Constants.INT_LENTH, tab);
//les String sont en fait des tableaux de charatères(char) et un char a
//la même dimention qu'un byte
Functions.stringToUnsignedByteTable(name, tab, startInd,
startInd += Constants.NAME_LENGTH);
Functions.intToByteTab(class_, startInd,
startInd += Constants.SHORT_LENTH, tab);
Functions.intToByteTab(map, startInd,
startInd += Constants.SHORT_LENTH, tab);
Functions.intToByteTab(lv, startInd, startInd += Constants.SHORT_LENTH,
tab);
Functions.intToByteTab(leader ? 1 : 0, startInd, startInd++, tab);
Functions.intToByteTab(online ? 1 : 0, startInd, startInd++, tab);
}
Functions.intToByteTab(int aInt, int startInd, int endInd, byte[] aByteTab) :
public static void intToByteTab(int aInt, int startInd, int endInd, byte[] aByteTab)
{
for (int i = startInd; i < endInd && aInt != 0; i++)
{
//donne le reste de la division de l'entier par 256
aByteTab[i] = (byte) (aInt % 256);
aInt /= 256;
}
}
exemple après l'exécutionde
Functions.intToByteTab(1283402, 0, 4, aByteTab);
aByteTab contiendra : {74, 149, 19, 0}
dans le sens inverse : 74 * 256^0 + 149 * 256^1 + 19 * 256^2 + 0 * 256^3
S'abonner à :
Publier des commentaires (Atom)
Aucun commentaire:
Publier un commentaire