hpatch.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //patch.h
  2. //
  3. /*
  4. The MIT License (MIT)
  5. Copyright (c) 2012-2017 HouSisong
  6. Permission is hereby granted, free of charge, to any person
  7. obtaining a copy of this software and associated documentation
  8. files (the "Software"), to deal in the Software without
  9. restriction, including without limitation the rights to use,
  10. copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the
  12. Software is furnished to do so, subject to the following
  13. conditions:
  14. The above copyright notice and this permission notice shall be
  15. included in all copies of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef HPatch_patch_h
  26. #define HPatch_patch_h
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. #define hpatch_BOOL int
  32. #define hpatch_FALSE 0
  33. #define TByte unsigned char
  34. #define TUInt int
  35. //if patch false return hpatch_FALSE
  36. hpatch_BOOL patch(unsigned char* out_newData,unsigned char* out_newData_end,
  37. const unsigned char* oldData,const unsigned char* oldData_end,
  38. const unsigned char* serializedDiff,const unsigned char* serializedDiff_end);
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. //patch_stream() patch by stream , recommended use in limited memory systems
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif
  47. //hpatch_StreamPos_t for support large file
  48. #ifdef _MSC_VER
  49. typedef unsigned __int32 hpatch_StreamPos_t;
  50. #else
  51. typedef unsigned int hpatch_StreamPos_t;
  52. #endif
  53. typedef void* hpatch_TStreamInputHandle;
  54. typedef struct hpatch_TStreamInput{
  55. hpatch_TStreamInputHandle streamHandle;
  56. hpatch_StreamPos_t streamSize;
  57. int (*read) (hpatch_TStreamInputHandle streamHandle,
  58. const hpatch_StreamPos_t readFromPos,
  59. unsigned char* out_data,unsigned char* out_data_end);
  60. //read() must return (out_data_end-out_data), otherwise read error
  61. } hpatch_TStreamInput;
  62. typedef struct hpatch_TStreamOutput{
  63. hpatch_TStreamInputHandle streamHandle;
  64. hpatch_StreamPos_t streamSize;
  65. int (*write)(hpatch_TStreamInputHandle streamHandle,
  66. const hpatch_StreamPos_t writeToPos,
  67. const unsigned char* data,const unsigned char* data_end);
  68. //write() must return (out_data_end-out_data), otherwise write error
  69. //first writeToPos==0; the next writeToPos+=(data_end-data)
  70. } hpatch_TStreamOutput;
  71. //once I/O (read/write) max byte size
  72. #define kStreamCacheSize (512)
  73. //patch by stream , only used 7*kStreamCacheSize stack memory for I/O cache
  74. hpatch_BOOL patch_stream(const struct hpatch_TStreamOutput* out_newData,
  75. const struct hpatch_TStreamInput* oldData,
  76. const struct hpatch_TStreamInput* serializedDiff);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif