您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tcobs.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*! \file tcobs.h
  2. \author thomas.hoehenleitner [at] seerose.net
  3. \details See ./TCOBSv1Specification.md.
  4. *******************************************************************************/
  5. #ifndef TCOBS_H_
  6. #define TCOBS_H_
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stddef.h>
  11. //! TCOBSEncode stuffs "length" bytes of data beginning at the location pointed to by "input" and writes the output to the
  12. //! location pointed to by "output". Returns the number of bytes written to "output" or a negative value in error case.
  13. //! A 0-delimiter is NOT added as last byte allowing concatenating TCOBS encoded buffers to one bigger buffer before the
  14. //! 00-byte delimiting. Buffer overlapping is allowed, when input lays inside output with a sufficient offset. The offset
  15. //! should be >= next large whole number of length/31. because in the worst case for each 31 bytes an additional sigil byte
  16. //! is inserted. The provided output buffer size should be >= length + next large whole number of length/31. This is a
  17. //! responsibility of the caller and not checked for efficiency.
  18. //! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
  19. int TCOBSEncode(void* __restrict output, const void* __restrict input, size_t length);
  20. //! TCOBSDecode decodes data ending at the location pointed to by "input" backwards (starting with the last byte)
  21. //! and writes the output also backwards to the location pointed to by "output" with a maximum size of max.
  22. //! Returns the number of bytes written to "output". Only max bytes are written. If the returned value is
  23. //! > max, this is an error "output buffer too small". In case of an error, a negative value is returned.
  24. //! THIS IS **IMPORTANT**: The decoded data start at output+max-returned, because output is filled from the end.
  25. //! Buffer overlapping is partially possible if output limit is _behind_ input limit with sufficient distance,
  26. //! but data can get much longer.
  27. //! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
  28. int TCOBSDecode(void* __restrict output, size_t max, const void* __restrict input, size_t length);
  29. #define OUT_BUFFER_TOO_SMALL -1000000 //!< OUT_BUFFER_TOO_SMALL is TCOBSDecode return error code.
  30. #define INPUT_DATA_CORRUPTED -2000000 //!< INPUT_DATA_CORRUPTED is TCOBSDecode return error code.
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #endif // TCOBS_H_