consumer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. #include <util/system/defaults.h>
  4. #include <library/cpp/yt/yson_string/public.h>
  5. namespace NYT::NYson {
  6. ////////////////////////////////////////////////////////////////////////////////
  7. //! A SAX-like interface for parsing a YSON stream.
  8. struct IYsonConsumer
  9. {
  10. virtual ~IYsonConsumer() = default;
  11. //! The current item is a string scalar (IStringNode).
  12. /*!
  13. * \param value A scalar value.
  14. */
  15. virtual void OnStringScalar(TStringBuf value) = 0;
  16. //! The current item is an integer scalar (IInt64Node).
  17. /*!
  18. * \param value A scalar value.
  19. */
  20. virtual void OnInt64Scalar(i64 value) = 0;
  21. //! The current item is an integer scalar (IUint64Node).
  22. /*!
  23. * \param value A scalar value.
  24. */
  25. virtual void OnUint64Scalar(ui64 value) = 0;
  26. //! The current item is an FP scalar (IDoubleNode).
  27. /*!
  28. * \param value A scalar value.
  29. */
  30. virtual void OnDoubleScalar(double value) = 0;
  31. //! The current item is an boolean scalar (IBooleanNode).
  32. /*!
  33. * \param value A scalar value.
  34. */
  35. virtual void OnBooleanScalar(bool value) = 0;
  36. //! The current item is an entity (IEntityNode).
  37. virtual void OnEntity() = 0;
  38. //! Starts a list (IListNode).
  39. /*!
  40. * The events describing a list are raised as follows:
  41. * - #OnBeginList
  42. * - For each item: #OnListItem followed by the description of the item
  43. * - #OnEndList
  44. */
  45. virtual void OnBeginList() = 0;
  46. //! Designates a list item.
  47. virtual void OnListItem() = 0;
  48. //! Ends the current list.
  49. virtual void OnEndList() = 0;
  50. //! Starts a map (IMapNode).
  51. /*!
  52. * The events describing a map are raised as follows:
  53. * - #OnBeginMap
  54. * - For each item: #OnKeyedItem followed by the description of the item
  55. * - #OnEndMap
  56. */
  57. virtual void OnBeginMap() = 0;
  58. //! Designates a keyed item (in map or in attributes).
  59. /*!
  60. * \param key Item key in the map.
  61. */
  62. virtual void OnKeyedItem(TStringBuf key) = 0;
  63. //! Ends the current map.
  64. virtual void OnEndMap() = 0;
  65. //! Starts attributes.
  66. /*!
  67. * An arbitrary node may be preceded by attributes.
  68. *
  69. * The events describing attributes are raised as follows:
  70. * - #OnBeginAttributes
  71. * - For each item: #OnKeyedItem followed by the description of the item
  72. * - #OnEndAttributes
  73. */
  74. virtual void OnBeginAttributes() = 0;
  75. //! Ends the current attribute list.
  76. virtual void OnEndAttributes() = 0;
  77. //! Inserts YSON-serialized node or fragment.
  78. /*!
  79. * \param yson Serialized data.
  80. * \param type Type of data.
  81. */
  82. virtual void OnRaw(TStringBuf yson, EYsonType type) = 0;
  83. // Extension methods.
  84. void OnRaw(const TYsonStringBuf& yson);
  85. };
  86. ////////////////////////////////////////////////////////////////////////////////
  87. } // namespace NYT::NYson