aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-01-09 20:55:43 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-01-09 21:09:19 +0300
commit667707fa06732f2943922d08ef77a2c9a52cbd47 (patch)
tree87eb9978b23ed47f105c5efba3a91cc35330be3a /library/cpp
parent7740c9ef0cd954624d51f1fc8c8ff4426edcc9ab (diff)
downloadydb-667707fa06732f2943922d08ef77a2c9a52cbd47.tar.gz
Intermediate changes
commit_hash:c97917e5fe0a2f094b8f7a50cf183357e8d07096
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/protobuf/yql/descriptor.cpp22
-rw-r--r--library/cpp/protobuf/yql/descriptor.h5
2 files changed, 25 insertions, 2 deletions
diff --git a/library/cpp/protobuf/yql/descriptor.cpp b/library/cpp/protobuf/yql/descriptor.cpp
index 2d5a154fc1..e5e1c8e28b 100644
--- a/library/cpp/protobuf/yql/descriptor.cpp
+++ b/library/cpp/protobuf/yql/descriptor.cpp
@@ -19,6 +19,7 @@
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+#include <google/protobuf/io/coded_stream.h>
using namespace NProtoBuf;
@@ -73,6 +74,7 @@ TDynamicInfoRef TDynamicInfo::Create(const TStringBuf& typeConfig) {
info->SkipBytes_ = data.SkipBytes;
info->OptionalLists_ = data.OptionalLists;
info->SyntaxAware_ = data.SyntaxAware;
+ info->Deterministic_ = data.Deterministic;
return info;
}
@@ -146,7 +148,16 @@ TString TDynamicInfo::Serialize(const Message& proto) {
switch (ProtoFormat_) {
case PF_PROTOBIN: {
result.ReserveAndResize(proto.ByteSize());
- if (!proto.SerializeToArray(result.begin(), result.size())) {
+ bool success = false;
+ if (Deterministic_) {
+ io::ArrayOutputStream arrOut(result.begin(), result.size());
+ io::CodedOutputStream codedOut(&arrOut);
+ codedOut.SetSerializationDeterministic(true);
+ success = proto.SerializeToCodedStream(&codedOut);
+ } else {
+ success = proto.SerializeToArray(result.begin(), result.size());
+ }
+ if (!success) {
ythrow yexception() << "can't serialize protobin message";
}
break;
@@ -159,7 +170,9 @@ TString TDynamicInfo::Serialize(const Message& proto) {
}
case PF_JSON: {
NJson::TJsonValue value;
- NProtobufJson::Proto2Json(proto, value);
+ NProtobufJson::TProto2JsonConfig config;
+ config.SetSortMapKeys(Deterministic_);
+ NProtobufJson::Proto2Json(proto, value, config);
result = NJson::WriteJson(value);
break;
}
@@ -225,6 +238,10 @@ TString GenerateProtobufTypeConfig(
ret["view"]["yt_mode"] = true;
}
+ if (options.Deterministic) {
+ ret["view"]["deterministic"] = true;
+ }
+
return NJson::WriteJson(ret, false);
}
@@ -268,6 +285,7 @@ TProtoTypeConfig ParseTypeConfig(const TStringBuf& config) {
result.OptionalLists = value["lists"]["optional"].GetBooleanSafe(true);
result.SyntaxAware = value["syntax"]["aware"].GetBooleanSafe(false);
result.YtMode = value["view"]["yt_mode"].GetBooleanSafe(false);
+ result.Deterministic = value["view"]["deterministic"].GetBooleanSafe(false);
if (protoFormat == "protobin") {
result.ProtoFormat = PF_PROTOBIN;
diff --git a/library/cpp/protobuf/yql/descriptor.h b/library/cpp/protobuf/yql/descriptor.h
index bbed6850ec..f5f51add0b 100644
--- a/library/cpp/protobuf/yql/descriptor.h
+++ b/library/cpp/protobuf/yql/descriptor.h
@@ -50,6 +50,8 @@ struct TProtoTypeConfig {
bool OptionalLists = false;
//! Заполнять ли пустые Optional типы дефолтным значением (только для proto3).
bool SyntaxAware = false;
+ //! Использовать ли детерминированную сериализацию
+ bool Deterministic = false;
};
struct TProtoTypeConfigOptions {
@@ -69,6 +71,8 @@ struct TProtoTypeConfigOptions {
bool OptionalLists = false;
//! Заполнять ли пустые Optional типы дефолтным значением (только для proto3).
bool SyntaxAware = false;
+ //! Использовать ли детерминированную сериализацию
+ bool Deterministic = false;
TProtoTypeConfigOptions& SetProtoFormat(EProtoFormat value) {
ProtoFormat = value;
@@ -158,4 +162,5 @@ private:
ui32 SkipBytes_;
bool OptionalLists_;
bool SyntaxAware_;
+ bool Deterministic_;
};