1
0

reference-libobs-util-serializers.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. Serializer
  2. ==========
  3. General programmable serialization functions. (A shared interface to
  4. various reading/writing to/from different inputs/outputs)
  5. .. code:: cpp
  6. #include <serializer.h>
  7. Serializer Structure (struct serializer)
  8. ----------------------------------------
  9. .. type:: struct serializer
  10. .. member:: void *serializer.data
  11. .. member:: size_t (*serializer.read)(void *, void *, size_t)
  12. .. member:: size_t (*serializer.write)(void *, const void *, size_t)
  13. .. member:: int64_t (*serializer.seek)(void *, int64_t, enum serialize_seek_type)
  14. .. member:: int64_t (*serializer.get_pos)(void *)
  15. Serializer Inline Functions
  16. ---------------------------
  17. .. function:: size_t s_read(struct serializer *s, void *data, size_t size)
  18. ---------------------
  19. .. function:: size_t s_write(struct serializer *s, const void *data, size_t size)
  20. ---------------------
  21. .. function:: size_t serialize(struct serializer *s, void *data, size_t len)
  22. ---------------------
  23. .. function:: int64_t serializer_seek(struct serializer *s, int64_t offset, enum serialize_seek_type seek_type)
  24. ---------------------
  25. .. function:: int64_t serializer_get_pos(struct serializer *s)
  26. ---------------------
  27. .. function:: void s_w8(struct serializer *s, uint8_t u8)
  28. ---------------------
  29. .. function:: void s_wl16(struct serializer *s, uint16_t u16)
  30. ---------------------
  31. .. function:: void s_wl32(struct serializer *s, uint32_t u32)
  32. ---------------------
  33. .. function:: void s_wl64(struct serializer *s, uint64_t u64)
  34. ---------------------
  35. .. function:: void s_wlf(struct serializer *s, float f)
  36. ---------------------
  37. .. function:: void s_wld(struct serializer *s, double d)
  38. ---------------------
  39. .. function:: void s_wb16(struct serializer *s, uint16_t u16)
  40. ---------------------
  41. .. function:: void s_wb24(struct serializer *s, uint32_t u24)
  42. ---------------------
  43. .. function:: void s_wb32(struct serializer *s, uint32_t u32)
  44. ---------------------
  45. .. function:: void s_wb64(struct serializer *s, uint64_t u64)
  46. ---------------------
  47. .. function:: void s_wbf(struct serializer *s, float f)
  48. ---------------------
  49. .. function:: void s_wbd(struct serializer *s, double d)
  50. ---------------------
  51. Array Output Serializer
  52. =======================
  53. Provides an output serializer used with dynamic arrays.
  54. .. code:: cpp
  55. #include <util/array-serializer.h>
  56. Array Output Serializer Structure (struct array_output_data)
  57. ------------------------------------------------------------
  58. .. type:: struct array_output_data
  59. .. member:: DARRAY(uint8_t) array_output_data.bytes
  60. Array Output Serializer Functions
  61. ---------------------------------
  62. .. function:: void array_output_serializer_init(struct serializer *s, struct array_output_data *data)
  63. ---------------------
  64. .. function:: void array_output_serializer_free(struct array_output_data *data)
  65. ---------------------
  66. File Input/Output Serializers
  67. =============================
  68. Provides file reading/writing serializers.
  69. .. code:: cpp
  70. #include <util/file-serializer.h>
  71. File Input Serializer Functions
  72. -------------------------------
  73. .. function:: bool file_input_serializer_init(struct serializer *s, const char *path)
  74. Initializes a file input serializer.
  75. :return: *true* if file opened successfully, *false* otherwise
  76. ---------------------
  77. .. function:: void file_input_serializer_free(struct serializer *s)
  78. Frees a file input serializer.
  79. ---------------------
  80. File Output Serializer Functions
  81. --------------------------------
  82. .. function:: bool file_output_serializer_init(struct serializer *s, const char *path)
  83. Initializes a file output serializer.
  84. :return: *true* if file created successfully, *false* otherwise
  85. ---------------------
  86. .. function:: bool file_output_serializer_init_safe(struct serializer *s, const char *path, const char *temp_ext)
  87. Initializes and safely writes to a temporary file (determined by the
  88. temporary extension) until freed.
  89. :return: *true* if file created successfully, *false* otherwise
  90. ---------------------
  91. .. function:: void file_output_serializer_free(struct serializer *s)
  92. Frees the file output serializer and saves the file.