1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/files/file_path.h"
6 #include "base/notreached.h"
7 #include "base/path_service.h"
8 #include "base/test/test_proto_loader.h"
9
10 namespace base::test {
11 namespace {
12
EmptyMessageLoader()13 const base::TestProtoSetLoader& EmptyMessageLoader() {
14 // A proto descriptor set with a single "message E{}".
15 const char kEmptyDescriptor[] = {
16 0x0a, 0x08, 0x0a, 0x01, 0x74, 0x22, 0x03, 0x0a, 0x01, 0x45,
17 };
18 static const base::TestProtoSetLoader loader(
19 std::string_view(kEmptyDescriptor, sizeof(kEmptyDescriptor)));
20 return loader;
21 }
22
23 } // namespace
24
BinaryProtoToRawTextProto(const std::string & binary_message)25 std::string BinaryProtoToRawTextProto(const std::string& binary_message) {
26 // This just serializes binary_message into an empty protobuf message. All
27 // content is interpreted as unknown fields, and reflected in the resulting
28 // text format.
29 return EmptyMessageLoader().PrintToText("E", binary_message);
30 }
31
32 } // namespace base::test
33