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

Function DecodeMetadata

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

Source from the content-addressed store, hash-verified

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