|
@@ -378,8 +378,17 @@ google::protobuf::Timestamp GetProtoNow();
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-//! This macro may be used to extract std::optional<T> from protobuf message field of type T.
|
|
|
-#define YT_PROTO_OPTIONAL(message, field) (((message).has_##field()) ? std::make_optional((message).field()) : std::nullopt)
|
|
|
+//! This macro may be used to extract std::optional<T> from protobuf message
|
|
|
+//! field. Macro accepts desired target type as optional third parameter.
|
|
|
+//! Usage:
|
|
|
+//! // Get as is.
|
|
|
+//! int instantInt = YT_PROTO_OPTIONAL(message, instant);
|
|
|
+//! // Get with conversion.
|
|
|
+//! TInstant instant = YT_PROTO_OPTIONAL(message, instant, TInstant);
|
|
|
+#define YT_PROTO_OPTIONAL(message, field, ...) \
|
|
|
+ (((message).has_##field()) \
|
|
|
+ ? std::optional(YT_PROTO_OPTIONAL_CONVERT(__VA_ARGS__)((message).field())) \
|
|
|
+ : std::nullopt)
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|