packet.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //---------------------------------------------------------------------------
  2. //
  3. // Packet.h -- File contains the header for the Packet File class
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. #ifndef PACKET_H
  9. #define PACKET_H
  10. //---------------------------------------------------------------------------
  11. // Include Files
  12. #ifndef DPACKET_H
  13. #include "dpacket.h"
  14. #endif
  15. #ifndef FILE_H
  16. #include "file.h"
  17. #endif
  18. #ifndef LZ_H
  19. #include "lz.h"
  20. #endif
  21. //---------------------------------------------------------------------------
  22. // Macro Definitions
  23. #define PACKET_FILE_VERSION 0xFEEDFACE
  24. #define NEW_PACKET_FLAG 0xFEEDFACE
  25. // 3 bits of type info
  26. #define STORAGE_TYPE_RAW 0x00L
  27. #define STORAGE_TYPE_FWF 0x01L // file within file
  28. #define STORAGE_TYPE_LZD 0x02L // LZ Compressed Packet
  29. #define STORAGE_TYPE_HF 0x03L // Huffman Compressed Packet
  30. #define STORAGE_TYPE_ZLIB 0x04L // zLib Compressed Packet
  31. #define STORAGE_TYPE_NUL 0x07L // NULL packet.
  32. #define TYPE_SHIFT 29 // Bit position of masked type
  33. #define DEFAULT_PACKET_TYPE STORAGE_TYPE_RAW
  34. #define ANY_PACKET_TYPE 0x07
  35. #define OFFSET_MASK ((1L << TYPE_SHIFT) - 1L)
  36. #define GetPacketType(offset) (((unsigned long)offset)>>TYPE_SHIFT)
  37. #define GetPacketOffset(offset) (offset&OFFSET_MASK)
  38. #define SetPacketType(offset,type) ((offset)+(long(type)<<TYPE_SHIFT))
  39. #define TABLE_ENTRY(p) ((2+p)<<2) // ((1+p)*sizeof(long))
  40. //---------------------------------------------------------------------------
  41. // Structure and Class Definitions
  42. //---------------------------------------------------------------------------
  43. class PacketFile : public File
  44. {
  45. //Data Members
  46. //-------------
  47. protected:
  48. long numPackets;
  49. long currentPacket;
  50. long packetSize;
  51. long packetBase;
  52. long packetType;
  53. long packetUnpackedSize;
  54. long *seekTable;
  55. bool usesCheckSum;
  56. //Member Functions
  57. //-----------------
  58. protected:
  59. void clear (void);
  60. void atClose (void);
  61. long afterOpen (void);
  62. public:
  63. PacketFile (void);
  64. ~PacketFile (void);
  65. virtual long open (char* fName, FileMode _mode = READ, long numChildren = 50);
  66. virtual long open (FilePtr _parent, unsigned long fileSize, long numChildren = 50);
  67. virtual long create (char* fName);
  68. virtual long createWithCase( char* fName ); // don't strlwr for me please!
  69. virtual void close (void);
  70. void forceUseCheckSum (void)
  71. {
  72. usesCheckSum = TRUE;
  73. }
  74. long readPacketOffset (long packet, long *lastType = 0);
  75. long readPacket (long packet, unsigned char *buffer);
  76. long readPackedPacket (long packet, unsigned char *buffer);
  77. long seekPacket (long packet);
  78. void operator ++ (void);
  79. void operator -- (void);
  80. long getNumPackets (void);
  81. long getCurrentPacket (void);
  82. long getPacketOffset(void);
  83. long getPacketSize (void)
  84. {
  85. return packetUnpackedSize;
  86. }
  87. long getPackedPacketSize (void);
  88. long getStorageType (void);
  89. virtual FileClass getFileClass (void)
  90. {
  91. return PACKETFILE;
  92. }
  93. long checkSumFile (void);
  94. //-------------------------------------------
  95. // Functions to Write Packet Files
  96. void reserve (long count, bool withCheckSum = FALSE);
  97. long writePacket (long packet, MemoryPtr buffer, long nbytes, unsigned char p_type = ANY_PACKET_TYPE);
  98. long insertPacket (long packet, MemoryPtr buffer, long nbytes, unsigned char p_type = ANY_PACKET_TYPE);
  99. long writePacket (long packet, MemoryPtr buffer);
  100. };
  101. //---------------------------------------------------------------------------
  102. #endif
  103. //---------------------------------------------------------------------------
  104. //
  105. // Edit Log
  106. //
  107. // $Log: packetfile.h $
  108. // Revision 1.1 1995/08/09 17:38:22 fsavage
  109. // Initial revision
  110. //
  111. //
  112. //---------------------------------------------------------------------------