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

Function DecodeMetadata

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

Source from the content-addressed store, hash-verified

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