reference-libobs-util-serializers.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. .. 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. .. versionchanged:: 30.2
  55. Array output serializer now supports seeking.
  56. .. code:: cpp
  57. #include <util/array-serializer.h>
  58. Array Output Serializer Structure (struct array_output_data)
  59. ------------------------------------------------------------
  60. .. struct:: array_output_data
  61. .. code:: cpp
  62. DARRAY(uint8_t) array_output_data.bytes
  63. Array Output Serializer Functions
  64. ---------------------------------
  65. .. function:: void array_output_serializer_init(struct serializer *s, struct array_output_data *data)
  66. ---------------------
  67. .. function:: void array_output_serializer_free(struct array_output_data *data)
  68. ---------------------
  69. .. function:: void array_output_serializer_reset(struct array_output_data *data)
  70. Resets serializer without freeing data.
  71. .. versionadded:: 30.2
  72. ---------------------
  73. File Input/Output Serializers
  74. =============================
  75. Provides file reading/writing serializers.
  76. .. code:: cpp
  77. #include <util/file-serializer.h>
  78. File Input Serializer Functions
  79. -------------------------------
  80. .. function:: bool file_input_serializer_init(struct serializer *s, const char *path)
  81. Initializes a file input serializer.
  82. :return: *true* if file opened successfully, *false* otherwise
  83. ---------------------
  84. .. function:: void file_input_serializer_free(struct serializer *s)
  85. Frees a file input serializer.
  86. ---------------------
  87. File Output Serializer Functions
  88. --------------------------------
  89. .. function:: bool file_output_serializer_init(struct serializer *s, const char *path)
  90. Initializes a file output serializer.
  91. :return: *true* if file created successfully, *false* otherwise
  92. ---------------------
  93. .. function:: bool file_output_serializer_init_safe(struct serializer *s, const char *path, const char *temp_ext)
  94. Initializes and safely writes to a temporary file (determined by the
  95. temporary extension) until freed.
  96. :return: *true* if file created successfully, *false* otherwise
  97. ---------------------
  98. .. function:: void file_output_serializer_free(struct serializer *s)
  99. Frees the file output serializer and saves the file.
  100. ---------------------
  101. Buffered File Output Serializer
  102. ===============================
  103. Provides a buffered file serializer that writes data asynchronously to prevent stalls due to slow disk I/O.
  104. Writes will only block when the buffer is full.
  105. The buffer and chunk size are configurable with the defaults being 256 MiB and 1 MiB respectively.
  106. .. versionadded:: 30.2
  107. .. code:: cpp
  108. #include <util/buffered-file-serializer.h>
  109. Buffered File Output Serializer Functions
  110. -----------------------------------------
  111. .. function:: bool buffered_file_serializer_init_defaults(struct serializer *s, const char *path)
  112. Initializes a buffered file output serializer with default buffer and chunk sizes.
  113. :return: *true* if file created successfully, *false* otherwise
  114. ---------------------
  115. .. function:: bool buffered_file_serializer_init(struct serializer *s, const char *path, size_t max_bufsize, size_t chunk_size)
  116. Initialize buffered writer with specified buffer and chunk sizes. Setting either to `0` will use the default value.
  117. :return: *true* if file created successfully, *false* otherwise
  118. ---------------------
  119. .. function:: void buffered_file_serializer_free(struct serializer *s)
  120. Frees the file output serializer and saves the file. Will block until I/O thread completes outstanding writes.