MCPcopy Create free account
hub / github.com/apache/arrow / DecodeMetadata

Function DecodeMetadata

cpp/src/arrow/c/bridge.cc:940–988  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

938};
939
940Result<DecodedMetadata> DecodeMetadata(const char* metadata) {
941 auto read_int32 = [&](int32_t* out) -> Status {
942 int32_t v;
943 memcpy(&v, metadata, 4);
944 metadata += 4;
945 *out = v;
946 if (*out < 0) {
947 return Status::Invalid("Invalid encoded metadata string");
948 }
949 return Status::OK();
950 };
951
952 auto read_string = [&](std::string* out) -> Status {
953 int32_t len;
954 RETURN_NOT_OK(read_int32(&len));
955 out->resize(len);
956 if (len > 0) {
957 memcpy(&(*out)[0], metadata, len);
958 metadata += len;
959 }
960 return Status::OK();
961 };
962
963 DecodedMetadata decoded;
964
965 if (metadata == nullptr) {
966 return decoded;
967 }
968 int32_t npairs;
969 RETURN_NOT_OK(read_int32(&npairs));
970 if (npairs == 0) {
971 return decoded;
972 }
973 std::vector<std::string> keys(npairs);
974 std::vector<std::string> values(npairs);
975 for (int32_t i = 0; i < npairs; ++i) {
976 RETURN_NOT_OK(read_string(&keys[i]));
977 RETURN_NOT_OK(read_string(&values[i]));
978 if (keys[i] == kExtensionTypeKeyName) {
979 decoded.extension_name = values[i];
980 decoded.extension_name_index = i;
981 } else if (keys[i] == kExtensionMetadataKeyName) {
982 decoded.extension_serialized = values[i];
983 decoded.extension_serialized_index = i;
984 }
985 }
986 decoded.metadata = key_value_metadata(std::move(keys), std::move(values));
987 return decoded;
988}
989
990struct SchemaImporter {
991 Status Import(struct ArrowSchema* src) {

Callers 2

DoImportMethod · 0.85
on_next_taskMethod · 0.85

Calls 4

key_value_metadataFunction · 0.85
resizeMethod · 0.80
InvalidFunction · 0.50
OKFunction · 0.50

Tested by

no test coverage detected