@@ -23,11 +23,9 @@ inline TString ProxyFieldNameConverter(const google::protobuf::FieldDescriptor&
23
23
24
24
class TYdsProtoToJsonPrinter : public NProtobufJson ::TProto2JsonPrinter {
25
25
public:
26
- TYdsProtoToJsonPrinter (const google::protobuf::Reflection* reflection,
27
- const NProtobufJson::TProto2JsonConfig& config,
26
+ TYdsProtoToJsonPrinter (const NProtobufJson::TProto2JsonConfig& config,
28
27
bool skipBase64Encode)
29
28
: NProtobufJson::TProto2JsonPrinter(config)
30
- , ProtoReflection(reflection)
31
29
, SkipBase64Encode(skipBase64Encode)
32
30
{}
33
31
@@ -61,14 +59,15 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
61
59
return Base64Encode (str);
62
60
};
63
61
62
+ auto * reflection = proto.GetReflection ();
64
63
if (field.is_repeated ()) {
65
- for (int i = 0 , endI = ProtoReflection ->FieldSize (proto, &field); i < endI; ++i) {
64
+ for (int i = 0 , endI = reflection ->FieldSize (proto, &field); i < endI; ++i) {
66
65
PrintStringValue<false >(field, TStringBuf (),
67
- maybeBase64Encode (proto. GetReflection () ->GetRepeatedString (proto, &field, i)), json);
66
+ maybeBase64Encode (reflection ->GetRepeatedString (proto, &field, i)), json);
68
67
}
69
68
} else {
70
69
PrintStringValue<true >(field, key,
71
- maybeBase64Encode (proto. GetReflection () ->GetString (proto, &field)), json);
70
+ maybeBase64Encode (reflection ->GetString (proto, &field)), json);
72
71
}
73
72
return ;
74
73
}
@@ -82,13 +81,14 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
82
81
key = MakeKey (field);
83
82
}
84
83
84
+ auto * reflection = proto.GetReflection ();
85
85
if (field.is_repeated ()) {
86
- for (int i = 0 , endI = ProtoReflection ->FieldSize (proto, &field); i < endI; ++i) {
87
- double value = proto. GetReflection () ->GetRepeatedInt64 (proto, &field, i) / 1000.0 ;
86
+ for (int i = 0 , endI = reflection ->FieldSize (proto, &field); i < endI; ++i) {
87
+ double value = reflection ->GetRepeatedInt64 (proto, &field, i) / 1000.0 ;
88
88
PrintDoubleValue<false >(TStringBuf (), value, json);
89
89
}
90
90
} else {
91
- double value = proto. GetReflection () ->GetInt64 (proto, &field) / 1000.0 ;
91
+ double value = reflection ->GetInt64 (proto, &field) / 1000.0 ;
92
92
PrintDoubleValue<true >(key, value, json);
93
93
}
94
94
return ;
@@ -103,19 +103,20 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
103
103
key = MakeKey (field);
104
104
}
105
105
106
+ auto * reflection = proto.GetReflection ();
106
107
if (field.is_repeated ()) {
107
- for (int i = 0 , endI = ProtoReflection ->FieldSize (proto, &field); i < endI; ++i) {
108
- auto value = proto. GetReflection () ->GetRepeatedString (proto, &field, i);
108
+ for (int i = 0 , endI = reflection ->FieldSize (proto, &field); i < endI; ++i) {
109
+ auto value = reflection ->GetRepeatedString (proto, &field, i);
109
110
if (!value.empty ()) {
110
111
PrintStringValue<false >(field, TStringBuf (),
111
- proto. GetReflection () ->GetRepeatedString (proto, &field, i), json);
112
+ reflection ->GetRepeatedString (proto, &field, i), json);
112
113
}
113
114
}
114
115
} else {
115
- auto value = proto. GetReflection () ->GetString (proto, &field);
116
+ auto value = reflection ->GetString (proto, &field);
116
117
if (!value.empty ()) {
117
118
PrintStringValue<true >(field, key,
118
- proto. GetReflection () ->GetString (proto, &field), json);
119
+ reflection ->GetString (proto, &field), json);
119
120
}
120
121
}
121
122
return ;
@@ -126,7 +127,6 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
126
127
}
127
128
128
129
private:
129
- const google::protobuf::Reflection* ProtoReflection = nullptr ;
130
130
bool SkipBase64Encode;
131
131
};
132
132
@@ -137,7 +137,7 @@ inline void ProtoToJson(const NProtoBuf::Message& resp, NJson::TJsonValue& value
137
137
.SetNameGenerator (ProxyFieldNameConverter)
138
138
.SetMapAsObject (true )
139
139
.SetEnumMode (NProtobufJson::TProto2JsonConfig::EnumName);
140
- TYdsProtoToJsonPrinter printer (resp. GetReflection (), config, skipBase64Encode);
140
+ TYdsProtoToJsonPrinter printer (config, skipBase64Encode);
141
141
printer.Print (resp, *NProtobufJson::CreateJsonMapOutput (value));
142
142
}
143
143
0 commit comments