@@ -68,7 +68,7 @@ bool ReadFileToProto(absl::string_view filename,
68
68
if (proto->ParseFromString (data)) {
69
69
// NOTE(user): When using ParseFromString() from a generic
70
70
// google::protobuf::Message, like we do here, all fields are stored, even
71
- // if their are unknown in the underlying proto type. Unless we explicitly
71
+ // if they are unknown in the underlying proto type. Unless we explicitly
72
72
// discard those 'unknown fields' here, our call to ByteSizeLong() will
73
73
// still count the unknown payload.
74
74
proto->DiscardUnknownFields ();
@@ -124,7 +124,7 @@ bool WriteProtoToFile(absl::string_view filename,
124
124
return false ;
125
125
}
126
126
break ;
127
- case ProtoWriteFormat::kJson :
127
+ case ProtoWriteFormat::kJson : {
128
128
google::protobuf::util::JsonPrintOptions options;
129
129
options.add_whitespace = true ;
130
130
options.always_print_primitive_fields = true ;
@@ -137,6 +137,18 @@ bool WriteProtoToFile(absl::string_view filename,
137
137
}
138
138
file_type_suffix = " .json" ;
139
139
break ;
140
+ }
141
+ case ProtoWriteFormat::kCanonicalJson :
142
+ google::protobuf::util::JsonPrintOptions options;
143
+ options.add_whitespace = true ;
144
+ if (!google::protobuf::util::MessageToJsonString (proto, &output_string,
145
+ options)
146
+ .ok ()) {
147
+ LOG (WARNING) << " Printing to stream failed." ;
148
+ return false ;
149
+ }
150
+ file_type_suffix = " .json" ;
151
+ break ;
140
152
}
141
153
if (gzipped) {
142
154
std::string gzip_string;
0 commit comments