icqpacket.h
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. #ifndef _ICQ_PACKET_H
  12. #define _ICQ_PACKET_H
  13. #include "packet.h"
  14. #define MAX_PACKET_SIZE 4096
  15. class IcqOutPacket : public OutPacket {
  16. public:
  17. IcqOutPacket() {
  18. cursor = data;
  19. }
  20. const char *getData() {
  21. return data;
  22. }
  23. int getSize() {
  24. return (cursor - data);
  25. }
  26. int setCursor(int off);
  27. OutPacket &operator <<(string &str) {
  28. return operator <<(str.c_str());
  29. }
  30. virtual OutPacket &operator <<(uint8 b);
  31. virtual OutPacket &operator <<(uint16 w);
  32. virtual OutPacket &operator <<(uint32 dw);
  33. virtual OutPacket &operator <<(const char *str);
  34. virtual void writeData(const char *buf, int n);
  35. protected:
  36. char data[MAX_PACKET_SIZE];
  37. char *cursor;
  38. };
  39. class IcqInPacket : public InPacket {
  40. public:
  41. IcqInPacket(const char *d, int len) {
  42. cursor = data = d;
  43. datalen = len;
  44. }
  45. virtual const char *getData() {
  46. return data;
  47. }
  48. virtual int getSize() {
  49. return datalen;
  50. }
  51. virtual InPacket &operator >>(uint8 &b);
  52. virtual InPacket &operator >>(uint16 &w);
  53. virtual InPacket &operator >>(uint32 &dw);
  54. virtual InPacket &operator >>(const char *&str);
  55. InPacket &operator >>(string &str);
  56. const char *readData(int &n);
  57. protected:
  58. const char *data;
  59. int datalen;
  60. const char *cursor;
  61. };
  62. #endif