UserlistRequest.java :  » Client » android-gadu » pl » szpadel » android » gadu » packets » Android Open Source

Android Open Source » Client » android gadu 
android gadu » pl » szpadel » android » gadu » packets » UserlistRequest.java
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
    }
    
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.