Skip to content

Commit

Permalink
Makes resource_to_example unpack Any fields.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 321421647
  • Loading branch information
nickgeorge committed Jul 17, 2020
1 parent 3c227be commit ffc87c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cc/google/fhir/seqex/resource_to_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <memory>
#include <string>

#include "google/protobuf/any.pb.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "absl/algorithm/container.h"
Expand Down Expand Up @@ -359,7 +360,17 @@ void Converter::MessageToExample(const Message& message,
// We currently flatten repeated submessages. That could potentially
// be problematic.
// TODO: figure out something better to do here.
MessageToExample(child, name, tokenizer, example, enable_attribution);
if (IsMessageType<protobuf::Any>(child)) {
std::unique_ptr<Message> unpacked_child =
absl::WrapUnique(UnpackAnyAsContainedResource(
dynamic_cast<const protobuf::Any&>(child))
.ValueOrDie());
MessageToExample(*unpacked_child, name, tokenizer, example,
enable_attribution);
} else {
MessageToExample(child, name, tokenizer, example,
enable_attribution);
}
}
} else {
LOG(ERROR) << "Unable to handle field " << name
Expand Down

0 comments on commit ffc87c7

Please sign in to comment.