Need some help converting ushort to short, uint to int and ulong to long from a byte List which holds the byte[] packet for reading...
Any help would be great will donate couple of $ to the right person :) :awesome:
Printable View
Need some help converting ushort to short, uint to int and ulong to long from a byte List which holds the byte[] packet for reading...
Any help would be great will donate couple of $ to the right person :) :awesome:
Why would you need to do this?
The packet which are received are in unsigned form
c#
Quote:
public ushort ReadInt16()
{
ushort tmp = (ushort)BitConverter.ToInt16(this.Data.ToArray(), this.Position);
this.Position += 2;
return tmp;
}
public uint ReadInt32()
{
uint tmp = (uint)BitConverter.ToInt32(this.Data.ToArray(), this.Position);
this.Position += 4;
return tmp;
}
public ulong ReadInt64()
{
ulong tmp = (ulong)BitConverter.ToInt64(this.Data.ToArray(), this.Position);
this.Position += 8;
return tmp;
}
What I have so far for my helper...
This is not for the rs protocol, I need to convert the above to Java simple... Paying :)Code:import java.util.ArrayList;
import java.util.List;
public class AresPacketReader {
public int position = 0;
private List<Byte> buffer = new ArrayList<Byte>();
public AresPacketReader() {
}
public AresPacketReader(byte bytes[])
{
buffer.clear();
position = 0;
for(int i = 0; i < bytes.length; i++) {
buffer.add(bytes[i]);
}
}
public int getByteCount() {
return buffer.size();
}
public byte peekByte() {
return buffer.get(position);
}
public int indexOf(byte b) {
return buffer.indexOf(b);
}
public int remaining() {
return buffer.size() - position;
}
public void setPosition(int p) {
position = p;
}
public void skipByte() {
position++;
}
public void skipBytes(int b) {
position += b;
}
public void positionReaderAfterHeader() {
this.position = 3;
}
public byte readByte() {
byte tmp = buffer.get(position);
position++;
return tmp;
}
public byte lastByte() {
return buffer.get(buffer.size() - 1);
}
public byte[] readBytes(int count) {
byte[] tmp = new byte[count];
System.arraycopy(buffer.toArray(), position, tmp, 0, tmp.length);
position += count;
return tmp;
}
public byte[] readBytes() {
byte[] tmp = new byte[buffer.size() - position];
System.arraycopy(buffer.toArray(), position, tmp, 0, tmp.length);
position += tmp.length;
return tmp;
}
public String readGuid() {
byte[] tmp = new byte[16];
System.arraycopy(buffer.toArray(), position, tmp, 0, tmp.length);
position += 16;
return tmp.toString();
}
public short ReadInt16() {
return 1;
}
public int ReadInt32() {
return 1;
}
public long ReadInt64() {
return 1;
}
}