Skip to content

Commit

Permalink
schema_registry/proto: Support encoded proto
Browse files Browse the repository at this point in the history
Support decoding a protobuf FileDescriptor as encoded protobuf.

Fix redpanda-data#3633

Signed-off-by: Ben Pope <ben@vectorized.io>
(cherry picked from commit d74b9e5)
  • Loading branch information
BenPope committed Feb 2, 2022
1 parent f8c9066 commit a1a3eb9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/v/pandaproxy/schema_registry/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#include "pandaproxy/logger.h"
#include "pandaproxy/schema_registry/errors.h"
#include "pandaproxy/schema_registry/sharded_store.h"
#include "utils/base64.h"
#include "vlog.h"

#include <seastar/core/coroutine.hh>

#include <fmt/ostream.h>
#include <google/protobuf/compiler/parser.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream.h>

Expand Down Expand Up @@ -136,10 +138,19 @@ class parser {
pb::io::Tokenizer t{&is, &error_collector};
_parser.RecordErrorsTo(&error_collector);

// Attempt parse a .proto file
if (!_parser.Parse(&t, &_fdp)) {
throw as_exception(error_collector.error());
// base64 decode the schema
std::string_view b64_def{
schema.def().raw()().data(), schema.def().raw()().size()};
auto bytes_def = base64_to_bytes(b64_def);

// Attempt parse as an encoded FileDescriptorProto.pb
if (!_fdp.ParseFromArray(
bytes_def.data(), static_cast<int>(bytes_def.size()))) {
throw as_exception(error_collector.error());
}
}

_fdp.set_name(schema.sub()());
return _fdp;
}
Expand Down

0 comments on commit a1a3eb9

Please sign in to comment.