Packet.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. //---------------------------------------------------------------------------
  2. //
  3. // Packet.cpp -- File contains the actual code for the Packet File class
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //---------------------------------------------------------------------------
  9. // Include Files
  10. #ifndef PACKET_H
  11. #include "packet.h"
  12. #endif
  13. #ifndef HEAP_H
  14. #include "heap.h"
  15. #endif
  16. #ifndef LZ_H
  17. #include "lz.h"
  18. #endif
  19. #include "zlib.h"
  20. #ifndef _MBCS
  21. #include <gameos.hpp>
  22. #else
  23. #include <assert.h>
  24. #define gosASSERT assert
  25. #define gos_Malloc malloc
  26. #define gos_Free free
  27. #endif
  28. #include <string.h>
  29. //---------------------------------------------------------------------------
  30. extern MemoryPtr LZPacketBuffer;
  31. extern unsigned long LZPacketBufferSize;
  32. //---------------------------------------------------------------------------
  33. // class PacketFile
  34. void PacketFile::clear (void)
  35. {
  36. currentPacket = -1;
  37. packetSize =
  38. packetBase =
  39. numPackets = 0;
  40. if (seekTable)
  41. systemHeap->Free(seekTable);
  42. seekTable = NULL;
  43. }
  44. //---------------------------------------------------------------------------
  45. void PacketFile::atClose (void)
  46. {
  47. if (isOpen() && fileMode != READ) // update filesize
  48. {
  49. long endPtr = getLength();
  50. //seek(sizeof(long)); //Move Past Version Marker
  51. //writeLong(endPtr); //Write File length
  52. long tableEntry;
  53. currentPacket = numPackets;
  54. if (!seekTable)
  55. {
  56. while (--currentPacket >= 0)
  57. {
  58. seek(TABLE_ENTRY(currentPacket));
  59. tableEntry = readLong();
  60. if (GetPacketType(tableEntry) == STORAGE_TYPE_NUL)
  61. {
  62. seek(TABLE_ENTRY(currentPacket));
  63. writeLong(SetPacketType(endPtr,STORAGE_TYPE_NUL));
  64. }
  65. else
  66. {
  67. endPtr = GetPacketOffset(tableEntry);
  68. }
  69. }
  70. }
  71. else
  72. {
  73. while (--currentPacket >= 0)
  74. {
  75. tableEntry = seekTable[currentPacket];
  76. if (GetPacketType(tableEntry) == STORAGE_TYPE_NUL)
  77. {
  78. seekTable[currentPacket] = SetPacketType(endPtr,STORAGE_TYPE_NUL);
  79. }
  80. else
  81. {
  82. endPtr = GetPacketOffset(tableEntry);
  83. }
  84. }
  85. }
  86. //-----------------------------------------------------
  87. // If seekTable was being used, write it back to file
  88. if (seekTable)
  89. {
  90. seek(sizeof(long)*2); //File Version & File Length
  91. write(MemoryPtr(seekTable),(numPackets*sizeof(long)));
  92. }
  93. //------------------------------------------------------
  94. // Is we were using a checkSum, calc it and write it to
  95. // the beginning of the file.
  96. if (usesCheckSum)
  97. {
  98. long checkSum = checkSumFile();
  99. seek(0);
  100. writeLong(checkSum);
  101. }
  102. }
  103. clear();
  104. }
  105. //---------------------------------------------------------------------------
  106. long PacketFile::checkSumFile (void)
  107. {
  108. //-----------------------------------------
  109. long currentPosition = logicalPosition;
  110. seek(4);
  111. MemoryPtr fileMap = (MemoryPtr)malloc(fileSize());
  112. read(fileMap,fileSize());
  113. long sum = 0;
  114. MemoryPtr curFileByte = fileMap;
  115. for (unsigned long i=4;i<fileSize();i++,curFileByte++)
  116. {
  117. sum += *curFileByte;
  118. }
  119. free(fileMap);
  120. seek (currentPosition);
  121. return sum;
  122. }
  123. //---------------------------------------------------------------------------
  124. long PacketFile::afterOpen (void)
  125. {
  126. if (!numPackets && getLength() >= 12)
  127. {
  128. long firstPacketOffset;
  129. long firstCheck = readLong();
  130. if (firstCheck == PACKET_FILE_VERSION && !usesCheckSum)
  131. {
  132. }
  133. else
  134. {
  135. //---------------------------------------
  136. // This is probably a checksum. Check it
  137. long checkSum = checkSumFile();
  138. if (checkSum != firstCheck)
  139. return PACKET_OUT_OF_RANGE;
  140. }
  141. firstPacketOffset = readLong();
  142. numPackets = (firstPacketOffset/sizeof(long))-2;
  143. }
  144. currentPacket = -1;
  145. if (fileMode == READ || fileMode == RDWRITE)
  146. {
  147. if (numPackets && !seekTable)
  148. {
  149. seekTable = (long *)systemHeap->Malloc(numPackets * sizeof(long));
  150. gosASSERT(seekTable != NULL);
  151. seek(sizeof(long)*2); //File Version & File Length
  152. read(MemoryPtr(seekTable),(numPackets*sizeof(long)));
  153. }
  154. }
  155. return(NO_ERR);
  156. }
  157. //---------------------------------------------------------------------------
  158. PacketFile::PacketFile (void)
  159. {
  160. seekTable = NULL;
  161. usesCheckSum = FALSE;
  162. clear();
  163. }
  164. //---------------------------------------------------------------------------
  165. PacketFile::~PacketFile (void)
  166. {
  167. close();
  168. }
  169. //---------------------------------------------------------------------------
  170. long PacketFile::open (char* fName, FileMode _mode, long numChild)
  171. {
  172. long openResult = File::open(fName,_mode,numChild);
  173. if (openResult != NO_ERR)
  174. {
  175. return(openResult);
  176. }
  177. openResult = afterOpen();
  178. return(openResult);
  179. }
  180. //---------------------------------------------------------------------------
  181. long PacketFile::open (FilePtr _parent, unsigned long fileSize, long numChild)
  182. {
  183. long result = File::open(_parent,fileSize,numChild);
  184. if (result != NO_ERR)
  185. return(result);
  186. result = afterOpen();
  187. return(result);
  188. }
  189. //---------------------------------------------------------------------------
  190. long PacketFile::create (char* fName)
  191. {
  192. long openResult = File::create(fName);
  193. if (openResult != NO_ERR)
  194. {
  195. return(openResult);
  196. }
  197. openResult = afterOpen();
  198. return(openResult);
  199. }
  200. long PacketFile::createWithCase( char* fName )
  201. {
  202. long openResult = File::createWithCase(fName);
  203. if (openResult != NO_ERR)
  204. {
  205. return(openResult);
  206. }
  207. openResult = afterOpen();
  208. return(openResult);
  209. }
  210. //---------------------------------------------------------------------------
  211. void PacketFile::close (void)
  212. {
  213. atClose();
  214. File::close();
  215. }
  216. //---------------------------------------------------------------------------
  217. long PacketFile::readPacketOffset (long packet, long *lastType)
  218. {
  219. long offset = -1;
  220. if (packet < numPackets)
  221. {
  222. if (seekTable)
  223. offset = seekTable[packet];
  224. if (lastType)
  225. *lastType = GetPacketType(offset);
  226. offset = GetPacketOffset(offset);
  227. }
  228. return offset;
  229. }
  230. //---------------------------------------------------------------------------
  231. long PacketFile::readPacket (long packet, unsigned char *buffer)
  232. {
  233. long result = 0;
  234. if ((packet==-1) || (packet == currentPacket) || (seekPacket(packet) == NO_ERR))
  235. {
  236. if ((getStorageType() == STORAGE_TYPE_RAW) || (getStorageType() == STORAGE_TYPE_FWF))
  237. {
  238. seek(packetBase);
  239. result = read(buffer, packetSize);
  240. }
  241. else
  242. {
  243. switch (getStorageType())
  244. {
  245. case STORAGE_TYPE_LZD:
  246. {
  247. seek(packetBase+sizeof(long));
  248. if (!LZPacketBuffer)
  249. {
  250. LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize);
  251. gosASSERT(LZPacketBuffer);
  252. }
  253. if ((long)LZPacketBufferSize < packetSize)
  254. {
  255. LZPacketBufferSize = packetSize;
  256. free(LZPacketBuffer);
  257. LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize);
  258. gosASSERT(LZPacketBuffer);
  259. }
  260. if (LZPacketBuffer)
  261. {
  262. read(LZPacketBuffer,(packetSize-sizeof(long)));
  263. long decompLength = LZDecomp(buffer,LZPacketBuffer,packetSize-sizeof(long));
  264. if (decompLength != packetUnpackedSize)
  265. result = 0;
  266. else
  267. result = decompLength;
  268. }
  269. }
  270. break;
  271. case STORAGE_TYPE_ZLIB:
  272. {
  273. seek(packetBase+sizeof(long));
  274. if (!LZPacketBuffer)
  275. {
  276. LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize);
  277. gosASSERT(LZPacketBuffer);
  278. }
  279. if ((long)LZPacketBufferSize < packetSize)
  280. {
  281. LZPacketBufferSize = packetSize;
  282. free(LZPacketBuffer);
  283. LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize);
  284. gosASSERT(LZPacketBuffer);
  285. }
  286. if (LZPacketBuffer)
  287. {
  288. read(LZPacketBuffer,(packetSize-sizeof(long)));
  289. unsigned long decompLength = LZPacketBufferSize;
  290. long decompResult = uncompress(buffer,&decompLength,LZPacketBuffer,packetSize-sizeof(long));
  291. if ((decompResult != Z_OK) || ((long)decompLength != packetUnpackedSize))
  292. result = 0;
  293. else
  294. result = decompLength;
  295. }
  296. }
  297. break;
  298. case STORAGE_TYPE_HF:
  299. STOP(("Tried to read a Huffman Compressed Packet. No Longer Supported!!"));
  300. break;
  301. }
  302. }
  303. }
  304. return result;
  305. }
  306. //---------------------------------------------------------------------------
  307. long PacketFile::readPackedPacket (long packet, unsigned char *buffer)
  308. {
  309. long result = 0;
  310. if ((packet==-1) || (packet == currentPacket) || (seekPacket(packet) == NO_ERR))
  311. {
  312. if ((getStorageType() == STORAGE_TYPE_RAW) || (getStorageType() == STORAGE_TYPE_FWF))
  313. {
  314. seek(packetBase);
  315. result = read(buffer, packetSize);
  316. }
  317. else
  318. {
  319. switch (getStorageType())
  320. {
  321. case STORAGE_TYPE_LZD:
  322. {
  323. seek(packetBase+sizeof(long));
  324. read(buffer,packetSize);
  325. }
  326. break;
  327. case STORAGE_TYPE_ZLIB:
  328. {
  329. seek(packetBase+sizeof(long));
  330. read(buffer,packetSize);
  331. }
  332. break;
  333. }
  334. }
  335. }
  336. return result;
  337. }
  338. //---------------------------------------------------------------------------
  339. long PacketFile::seekPacket (long packet)
  340. {
  341. long offset, next;
  342. if (packet < 0)
  343. {
  344. return(PACKET_OUT_OF_RANGE);
  345. }
  346. offset = readPacketOffset(packet, &packetType);
  347. currentPacket = packet++;
  348. if (packet == numPackets)
  349. next = getLength();
  350. else
  351. next = readPacketOffset(packet);
  352. packetSize = next-offset;
  353. packetBase = offset; // seek to beginning of packet
  354. seek(packetBase);
  355. switch (getStorageType())
  356. {
  357. case STORAGE_TYPE_LZD:
  358. // the first DWORD of a compressed packet is the unpacked length
  359. packetUnpackedSize = readLong();
  360. break;
  361. case STORAGE_TYPE_ZLIB:
  362. // the first DWORD of a compressed packet is the unpacked length
  363. packetUnpackedSize = readLong();
  364. break;
  365. case STORAGE_TYPE_RAW:
  366. packetUnpackedSize = packetSize;
  367. break;
  368. case STORAGE_TYPE_NUL:
  369. packetUnpackedSize = 0;
  370. break;
  371. default:
  372. return(BAD_PACKET_VERSION);
  373. }
  374. if (offset > 0)
  375. return(NO_ERR);
  376. return (PACKET_OUT_OF_RANGE);
  377. }
  378. //---------------------------------------------------------------------------
  379. void PacketFile::operator ++ (void)
  380. {
  381. if (++currentPacket >= numPackets)
  382. {
  383. currentPacket = numPackets-1;
  384. }
  385. seekPacket(currentPacket);
  386. }
  387. //---------------------------------------------------------------------------
  388. void PacketFile::operator -- (void)
  389. {
  390. if (currentPacket-- <= 0)
  391. {
  392. currentPacket = 0;
  393. }
  394. seekPacket(currentPacket);
  395. }
  396. //---------------------------------------------------------------------------
  397. long PacketFile::getNumPackets (void)
  398. {
  399. return numPackets;
  400. }
  401. //---------------------------------------------------------------------------
  402. long PacketFile::getCurrentPacket (void)
  403. {
  404. return currentPacket;
  405. }
  406. //---------------------------------------------------------------------------
  407. inline long PacketFile::getPacketOffset(void)
  408. {
  409. return packetBase;
  410. }
  411. //---------------------------------------------------------------------------
  412. long PacketFile::getPackedPacketSize (void)
  413. {
  414. return packetSize;
  415. }
  416. //---------------------------------------------------------------------------
  417. long PacketFile::getStorageType (void)
  418. {
  419. return packetType;
  420. }
  421. //---------------------------------------------------------------------------
  422. void PacketFile::reserve (long count, bool useCheckSum)
  423. {
  424. //---------------------------------------------------
  425. // If we already have packets, reserve does nothing.
  426. // Otherwise, reserve sets up the file. Must be
  427. // called before any writing to a newly created file.
  428. if (numPackets)
  429. {
  430. return;
  431. }
  432. usesCheckSum = useCheckSum;
  433. numPackets = count;
  434. long firstPacketOffset = TABLE_ENTRY(numPackets);
  435. writeLong(PACKET_FILE_VERSION);
  436. writeLong(firstPacketOffset);
  437. //----------------------------
  438. // initialize the seek table
  439. while (count-- > 0)
  440. writeLong(SetPacketType(firstPacketOffset,STORAGE_TYPE_NUL));
  441. //-------------------------------------------------------------
  442. // If we called this, chances are we are writing a packet file
  443. // from start to finish. It is MUCH faster if this table is
  444. // updated in memory and flushed when the file is closed.
  445. if (!seekTable)
  446. {
  447. seekTable = (long *)systemHeap->Malloc(numPackets * sizeof(long));
  448. if (seekTable != NULL)
  449. {
  450. seek(sizeof(long)*2); //File Version & File Length
  451. read(MemoryPtr(seekTable),(numPackets*sizeof(long)));
  452. }
  453. }
  454. }
  455. //---------------------------------------------------------------------------
  456. long PacketFile::writePacket (long packet, MemoryPtr buffer, long nbytes, unsigned char pType)
  457. {
  458. //--------------------------------------------------------
  459. // This function writes the packet to the current end
  460. // of file and stores the packet address in the seek
  461. // table. NOTE that this cannot be used to replace
  462. // a packet. That function is writePacket which takes
  463. // a packet number and a buffer. The size cannot change
  464. // and, as such, is irrelevant. You must write the
  465. // same sized packet each time, if the packet already
  466. // exists. In theory, it could be smaller but the check
  467. // right now doesn't allow anything but same size.
  468. long result = 0;
  469. MemoryPtr workBuffer = NULL;
  470. if (pType == ANY_PACKET_TYPE || pType == STORAGE_TYPE_LZD || pType == STORAGE_TYPE_ZLIB)
  471. {
  472. if ((nbytes<<1) < 4096)
  473. workBuffer = (MemoryPtr)malloc(4096);
  474. else
  475. workBuffer = (MemoryPtr)malloc(nbytes<<1);
  476. gosASSERT(workBuffer != NULL);
  477. }
  478. gosASSERT((packet > 0) || (packet < numPackets));
  479. packetBase = getLength();
  480. currentPacket = packet;
  481. packetSize = packetUnpackedSize = nbytes;
  482. //-----------------------------------------------
  483. // Code goes in here to pick the best compressed
  484. // version of the packet. Otherwise, default
  485. // to RAW.
  486. if ((pType == ANY_PACKET_TYPE) || (pType == STORAGE_TYPE_LZD) || (pType == STORAGE_TYPE_ZLIB))
  487. {
  488. if (pType == ANY_PACKET_TYPE)
  489. pType = STORAGE_TYPE_RAW;
  490. //-----------------------------
  491. // Find best compression here.
  492. // This USED to use LZ. Use ZLib from now on.
  493. // Game will ALWAYS be able to READ LZ Packets!!
  494. unsigned long actualSize = nbytes << 1;
  495. if (actualSize < 4096)
  496. actualSize = 4096;
  497. unsigned long workBufferSize = actualSize;
  498. unsigned long oldBufferSize = nbytes;
  499. long compressedResult = compress2(workBuffer,&workBufferSize,buffer,nbytes,Z_DEFAULT_COMPRESSION);
  500. if (compressedResult != Z_OK)
  501. STOP(("Unable to write packet %d to file %s. Error %d",packet,fileName,compressedResult));
  502. compressedResult = uncompress(buffer,&oldBufferSize,workBuffer,nbytes);
  503. if ((long)oldBufferSize != nbytes)
  504. STOP(("Packet size changed after compression. Was %d is now %d",nbytes,oldBufferSize));
  505. if ((pType == STORAGE_TYPE_LZD) || (pType == STORAGE_TYPE_ZLIB) || ((long)workBufferSize < nbytes))
  506. {
  507. pType = STORAGE_TYPE_ZLIB;
  508. packetSize = workBufferSize;
  509. }
  510. }
  511. packetType = pType;
  512. seek(packetBase);
  513. if (packetType == STORAGE_TYPE_ZLIB)
  514. {
  515. writeLong(packetUnpackedSize);
  516. result = write(workBuffer, packetSize);
  517. }
  518. else
  519. {
  520. result = write(buffer, packetSize);
  521. }
  522. if (!seekTable)
  523. {
  524. seek(TABLE_ENTRY(packet));
  525. writeLong(SetPacketType(packetBase,packetType));
  526. }
  527. else
  528. {
  529. seekTable[packet] = SetPacketType(packetBase,packetType);
  530. }
  531. long *currentEntry = NULL;
  532. if (seekTable)
  533. {
  534. packet++;
  535. currentEntry = &(seekTable[packet]);
  536. }
  537. long tableData = SetPacketType(getLength(),STORAGE_TYPE_NUL);
  538. while (packet < (numPackets - 1))
  539. {
  540. if (!seekTable)
  541. {
  542. writeLong(tableData);
  543. }
  544. else
  545. {
  546. *currentEntry = tableData;
  547. currentEntry++;
  548. }
  549. packet++;
  550. }
  551. if (workBuffer)
  552. free(workBuffer);
  553. return result;
  554. }
  555. #define DEFAULT_MAX_PACKET 65535
  556. //---------------------------------------------------------------------------
  557. long PacketFile::insertPacket (long packet, MemoryPtr buffer, long nbytes, unsigned char pType)
  558. {
  559. //--------------------------------------------------------
  560. // This function writes the packet to the current end
  561. // of file and stores the packet address in the seek
  562. // table. Originally, replace was a NONO. No, we check
  563. // for the size and, if it is different, insert the new
  564. // packet into a new file and basically spend many timeparts doing it.
  565. // Necessary for the teditor.
  566. // I Love it.
  567. long result = 0;
  568. if (packet < 0)
  569. {
  570. return result;
  571. }
  572. //---------------------------------------------------------------
  573. // Only used here, so OK if regular WINDOWS(tm) malloc!
  574. MemoryPtr workBuffer = (MemoryPtr)malloc(DEFAULT_MAX_PACKET);
  575. //-------------------------------------------------------------
  576. // All new code here. Basically, open a new packet file,
  577. // write each of the old packets and this new one. Close all
  578. // and copy the new one over the old one. Open the new one and
  579. // set pointers accordingly.
  580. PacketFile tmpFile;
  581. result = tmpFile.create("AF3456AF.788");
  582. if (packet >= numPackets)
  583. {
  584. numPackets++;
  585. }
  586. tmpFile.reserve(numPackets);
  587. for (long i=0;i<numPackets;i++)
  588. {
  589. if (i == packet)
  590. {
  591. if (nbytes >= DEFAULT_MAX_PACKET)
  592. {
  593. //----------------------------------------------------
  594. // Not sure what to do here. We'll try reallocating
  595. ::free(workBuffer);
  596. workBuffer = (MemoryPtr)malloc(packetSize);
  597. }
  598. tmpFile.writePacket(i,buffer,nbytes,pType);
  599. }
  600. else
  601. {
  602. seekPacket(i);
  603. long storageType = getStorageType();
  604. long packetSize = getPacketSize();
  605. if (packetSize >= DEFAULT_MAX_PACKET)
  606. {
  607. //----------------------------------------------------
  608. // Not sure what to do here. We'll try reallocating
  609. ::free(workBuffer);
  610. workBuffer = (MemoryPtr)malloc(packetSize);
  611. }
  612. readPacket(i,workBuffer);
  613. tmpFile.writePacket(i,workBuffer,packetSize,storageType);
  614. }
  615. }
  616. //------------------------------------
  617. // Now close and reassign everything.
  618. char ourFileName[250];
  619. long ourFileMode = 0;
  620. strcpy(ourFileName,fileName);
  621. ourFileMode = fileMode;
  622. tmpFile.close();
  623. close();
  624. remove(ourFileName);
  625. rename("AF3456AF.788",ourFileName);
  626. remove("AF3456AF.788");
  627. open(ourFileName,(FileMode)ourFileMode);
  628. seekPacket(packet);
  629. return result;
  630. }
  631. //---------------------------------------------------------------------------
  632. long PacketFile::writePacket (long packet, MemoryPtr buffer)
  633. {
  634. //--------------------------------------------------------
  635. // This function replaces the packet with the contents
  636. // of buffer. There are two restrictions. The first is
  637. // that the packet must be the same length as the existing
  638. // packet. If not, buffer over/under run will occur.
  639. // The second is that the packet cannot be compressed since
  640. // there is no gaurantee that the new data will compress
  641. // to exactly the same length. Returns NO_ERR if packet
  642. // written successfully. Otherwise returns error.
  643. long result = 0;
  644. if ((packet < 0) || (packet >= numPackets))
  645. {
  646. return 0;
  647. }
  648. seekPacket(packet);
  649. if (packetType == STORAGE_TYPE_LZD || packetType == STORAGE_TYPE_HF || packetType == STORAGE_TYPE_ZLIB)
  650. {
  651. return (PACKET_WRONG_SIZE);
  652. }
  653. else
  654. {
  655. result = write(buffer, packetSize);
  656. }
  657. if (result == packetUnpackedSize)
  658. {
  659. return(NO_ERR);
  660. }
  661. return BAD_WRITE_ERR;
  662. }