package pl.szpadel.android.gadu.packets;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
public class UserlistRequest extends SendPacket {
// fields
private boolean mFirst; // is a first packet in series?
private ByteBuffer mData; // data contained by the buffer
// GG constants
static private final int GG_USERLIST_PUT = 0x00;
static private final int GG_USERLIST_PUT_MORE = 0x01;
static private final int GG_USERLIST_GET = 0x02;
/// Creates simple 'send me the list' packet
public UserlistRequest() {
super(TYPE_USERLIST_REQUEST80);
mFirst = true;
mData = null;
}
/// Creates packet containing data
public UserlistRequest(boolean first, ByteBuffer data) {
super(TYPE_USERLIST_REQUEST80);
mFirst = first;
mData = data;
}
@Override
protected void writeToBuffer(ByteBuffer buffer)
throws BufferOverflowException {
// simple 'give me list' packet?
if (mData == null) {
buffer.putInt(GG_USERLIST_GET);
// contact list send to server
} else {
if (mFirst) {
buffer.putInt(GG_USERLIST_PUT);
} else {
buffer.putInt(GG_USERLIST_PUT_MORE);
}
buffer.put(mData);
buffer.flip(); // make ready to read
}
}
}
|