cyson.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #pragma once
  2. #include <library/cpp/yson_pull/cyson_enums.h>
  3. #include <util/system/types.h>
  4. #include <stddef.h>
  5. #include <stdio.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef struct yson_string {
  10. const char* ptr;
  11. size_t length;
  12. } yson_string;
  13. typedef yson_input_stream_result (*yson_input_stream_func)(
  14. void* ctx,
  15. const char** ptr,
  16. size_t* length);
  17. typedef yson_output_stream_result (*yson_output_stream_func)(
  18. void* ctx,
  19. const char* ptr,
  20. size_t length);
  21. /* Abstract types */
  22. typedef struct yson_input_stream yson_input_stream;
  23. typedef struct yson_output_stream yson_output_stream;
  24. typedef struct yson_reader yson_reader;
  25. typedef struct yson_writer yson_writer;
  26. /* Input stream */
  27. yson_input_stream*
  28. yson_input_stream_from_string(const char* ptr, size_t length);
  29. yson_input_stream*
  30. yson_input_stream_from_file(FILE* file, size_t buffer_size);
  31. yson_input_stream*
  32. yson_input_stream_from_fd(int fd, size_t buffer_size);
  33. yson_input_stream*
  34. yson_input_stream_new(void* ctx, yson_input_stream_func callback);
  35. void yson_input_stream_delete(yson_input_stream* stream);
  36. /* Output stream */
  37. yson_output_stream*
  38. yson_output_stream_from_file(FILE* file, size_t buffer_size);
  39. yson_output_stream*
  40. yson_output_stream_from_fd(int fd, size_t buffer_size);
  41. yson_output_stream*
  42. yson_output_stream_new(void* ctx, yson_output_stream_func callback, size_t buffer_size);
  43. void yson_output_stream_delete(yson_output_stream* stream);
  44. /* Reader */
  45. yson_reader*
  46. yson_reader_new(yson_input_stream* stream, yson_stream_type mode);
  47. void yson_reader_delete(yson_reader* reader);
  48. yson_event_type
  49. yson_reader_get_next_event(yson_reader* reader);
  50. const char*
  51. yson_reader_get_error_message(yson_reader* reader);
  52. yson_scalar_type
  53. yson_reader_get_scalar_type(yson_reader* reader);
  54. int yson_reader_get_boolean(yson_reader* reader);
  55. i64 yson_reader_get_int64(yson_reader* reader);
  56. ui64 yson_reader_get_uint64(yson_reader* reader);
  57. double
  58. yson_reader_get_float64(yson_reader* reader);
  59. const yson_string*
  60. yson_reader_get_string(yson_reader* reader);
  61. /* Writer */
  62. yson_writer*
  63. yson_writer_new_binary(
  64. yson_output_stream* stream,
  65. yson_stream_type mode);
  66. yson_writer*
  67. yson_writer_new_text(
  68. yson_output_stream* stream,
  69. yson_stream_type mode);
  70. yson_writer*
  71. yson_writer_new_pretty_text(
  72. yson_output_stream* stream,
  73. yson_stream_type mode,
  74. size_t indent);
  75. void yson_writer_delete(yson_writer* writer);
  76. const char*
  77. yson_writer_get_error_message(yson_writer* writer);
  78. yson_writer_result
  79. yson_writer_write_begin_stream(yson_writer* writer);
  80. yson_writer_result
  81. yson_writer_write_end_stream(yson_writer* writer);
  82. yson_writer_result
  83. yson_writer_write_begin_list(yson_writer* writer);
  84. yson_writer_result
  85. yson_writer_write_end_list(yson_writer* writer);
  86. yson_writer_result
  87. yson_writer_write_begin_map(yson_writer* writer);
  88. yson_writer_result
  89. yson_writer_write_end_map(yson_writer* writer);
  90. yson_writer_result
  91. yson_writer_write_begin_attributes(yson_writer* writer);
  92. yson_writer_result
  93. yson_writer_write_end_attributes(yson_writer* writer);
  94. yson_writer_result
  95. yson_writer_write_entity(yson_writer* writer);
  96. yson_writer_result
  97. yson_writer_write_key(yson_writer* writer, const char* ptr, size_t length);
  98. yson_writer_result
  99. yson_writer_write_string(yson_writer* writer, const char* ptr, size_t length);
  100. yson_writer_result
  101. yson_writer_write_int64(yson_writer* writer, i64 value);
  102. yson_writer_result
  103. yson_writer_write_uint64(yson_writer* writer, ui64 value);
  104. yson_writer_result
  105. yson_writer_write_boolean(yson_writer* writer, int value);
  106. yson_writer_result
  107. yson_writer_write_float64(yson_writer* writer, double value);
  108. #ifdef __cplusplus
  109. } /* extern "C" */
  110. #endif