diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yt/yson | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yt/yson')
-rw-r--r-- | library/cpp/yt/yson/consumer.cpp | 16 | ||||
-rw-r--r-- | library/cpp/yt/yson/consumer.h | 111 | ||||
-rw-r--r-- | library/cpp/yt/yson/public.h | 11 | ||||
-rw-r--r-- | library/cpp/yt/yson/ya.make | 11 |
4 files changed, 149 insertions, 0 deletions
diff --git a/library/cpp/yt/yson/consumer.cpp b/library/cpp/yt/yson/consumer.cpp new file mode 100644 index 0000000000..9b68ee8a22 --- /dev/null +++ b/library/cpp/yt/yson/consumer.cpp @@ -0,0 +1,16 @@ +#include "consumer.h" + +#include <library/cpp/yt/yson_string/string.h> + +namespace NYT::NYson { + +//////////////////////////////////////////////////////////////////////////////// + +void IYsonConsumer::OnRaw(const TYsonStringBuf& yson) +{ + OnRaw(yson.AsStringBuf(), yson.GetType()); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT::NYson diff --git a/library/cpp/yt/yson/consumer.h b/library/cpp/yt/yson/consumer.h new file mode 100644 index 0000000000..ea5f586b91 --- /dev/null +++ b/library/cpp/yt/yson/consumer.h @@ -0,0 +1,111 @@ +#pragma once + +#include <util/generic/strbuf.h> + +#include <util/system/defaults.h> + +#include <library/cpp/yt/yson_string/public.h> + +namespace NYT::NYson { + +//////////////////////////////////////////////////////////////////////////////// + +//! A SAX-like interface for parsing a YSON stream. +struct IYsonConsumer +{ + virtual ~IYsonConsumer() = default; + + //! The current item is a string scalar (IStringNode). + /*! + * \param value A scalar value. + */ + virtual void OnStringScalar(TStringBuf value) = 0; + + //! The current item is an integer scalar (IInt64Node). + /*! + * \param value A scalar value. + */ + virtual void OnInt64Scalar(i64 value) = 0; + + //! The current item is an integer scalar (IUint64Node). + /*! + * \param value A scalar value. + */ + virtual void OnUint64Scalar(ui64 scalar) = 0; + + //! The current item is an FP scalar (IDoubleNode). + /*! + * \param value A scalar value. + */ + virtual void OnDoubleScalar(double value) = 0; + + //! The current item is an boolean scalar (IBooleanNode). + /*! + * \param value A scalar value. + */ + virtual void OnBooleanScalar(bool value) = 0; + + //! The current item is an entity (IEntityNode). + virtual void OnEntity() = 0; + + //! Starts a list (IListNode). + /*! + * The events describing a list are raised as follows: + * - #OnBeginList + * - For each item: #OnListItem followed by the description of the item + * - #OnEndList + */ + virtual void OnBeginList() = 0; + + //! Designates a list item. + virtual void OnListItem() = 0; + + //! Ends the current list. + virtual void OnEndList() = 0; + + //! Starts a map (IMapNode). + /*! + * The events describing a map are raised as follows: + * - #OnBeginMap + * - For each item: #OnKeyedItem followed by the description of the item + * - #OnEndMap + */ + virtual void OnBeginMap() = 0; + + //! Designates a keyed item (in map or in attributes). + /*! + * \param key Item key in the map. + */ + virtual void OnKeyedItem(TStringBuf key) = 0; + + //! Ends the current map. + virtual void OnEndMap() = 0; + + //! Starts attributes. + /*! + * An arbitrary node may be preceeded by attributes. + * + * The events describing attributes are raised as follows: + * - #OnBeginAttributes + * - For each item: #OnKeyedItem followed by the description of the item + * - #OnEndAttributes + */ + virtual void OnBeginAttributes() = 0; + + //! Ends the current attribute list. + virtual void OnEndAttributes() = 0; + + //! Inserts YSON-serialized node or fragment. + /*! + * \param yson Serialized data. + * \param type Type of data. + */ + virtual void OnRaw(TStringBuf yson, EYsonType type) = 0; + + // Extension methods. + void OnRaw(const TYsonStringBuf& yson); +}; + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT::NYson diff --git a/library/cpp/yt/yson/public.h b/library/cpp/yt/yson/public.h new file mode 100644 index 0000000000..68cdcd38c1 --- /dev/null +++ b/library/cpp/yt/yson/public.h @@ -0,0 +1,11 @@ +#pragma once + +namespace NYT::NYson { + +//////////////////////////////////////////////////////////////////////////////// + +struct IYsonConsumer; + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT::NYson diff --git a/library/cpp/yt/yson/ya.make b/library/cpp/yt/yson/ya.make new file mode 100644 index 0000000000..d914352c4b --- /dev/null +++ b/library/cpp/yt/yson/ya.make @@ -0,0 +1,11 @@ +LIBRARY() + +SRCS( + consumer.cpp +) + +PEERDIR( + library/cpp/yt/yson_string +) + +END() |