@@ -253,35 +253,6 @@ constexpr std::string_view kReferencedDataFile = "referenced-data-file";
253253constexpr std::string_view kContentOffset = " content-offset" ;
254254constexpr std::string_view kContentSizeInBytes = " content-size-in-bytes" ;
255255
256- // Decode a base64-encoded string to raw bytes.
257- std::vector<uint8_t > Base64Decode (std::string_view encoded) {
258- static const std::array<int , 256 > kDecodeTable = [] {
259- std::array<int , 256 > table;
260- table.fill (-1 );
261- for (int i = 0 ; i < 26 ; i++) table[static_cast <unsigned char >(' A' ) + i] = i;
262- for (int i = 0 ; i < 26 ; i++) table[static_cast <unsigned char >(' a' ) + i] = 26 + i;
263- for (int i = 0 ; i < 10 ; i++) table[static_cast <unsigned char >(' 0' ) + i] = 52 + i;
264- table[static_cast <unsigned char >(' +' )] = 62 ;
265- table[static_cast <unsigned char >(' /' )] = 63 ;
266- return table;
267- }();
268-
269- std::vector<uint8_t > decoded;
270- decoded.reserve (encoded.size () * 3 / 4 );
271- int val = 0 , bits = -8 ;
272- for (unsigned char c : encoded) {
273- if (c == ' =' ) break ;
274- const int d = kDecodeTable [c];
275- if (d == -1 ) continue ;
276- val = (val << 6 ) + d;
277- bits += 6 ;
278- if (bits >= 0 ) {
279- decoded.push_back (static_cast <uint8_t >((val >> bits) & 0xFF ));
280- bits -= 8 ;
281- }
282- }
283- return decoded;
284- }
285256
286257} // namespace
287258
@@ -1866,21 +1837,20 @@ Result<DataFile> DataFileFromJson(
18661837 ICEBERG_RETURN_UNEXPECTED (parse_int_map (kNullValueCounts , df.null_value_counts ));
18671838 ICEBERG_RETURN_UNEXPECTED (parse_int_map (kNanValueCounts , df.nan_value_counts ));
18681839
1869- // Parse BinaryMap: {"keys": [int, ...], "values": [base64string , ...]}
1840+ // Parse BinaryMap: {"keys": [int, ...], "values": [base64 binary , ...]}
18701841 auto parse_binary_map = [&](std::string_view key,
18711842 std::map<int32_t , std::vector<uint8_t >>& target) -> Status {
18721843 if (!json.contains (key) || json.at (key).is_null ()) return {};
18731844 ICEBERG_ASSIGN_OR_RAISE (auto map_json, GetJsonValue<nlohmann::json>(json, key));
18741845 ICEBERG_ASSIGN_OR_RAISE (auto keys,
1875- GetTypedJsonValue<std::vector<int32_t >>(map_json.at (" keys" )));
1876- ICEBERG_ASSIGN_OR_RAISE (
1877- auto values,
1878- GetTypedJsonValue<std::vector<std::string>>(map_json.at (" values" )));
1846+ GetJsonValue<std::vector<int32_t >>(map_json, " keys" ));
1847+ ICEBERG_ASSIGN_OR_RAISE (auto values,
1848+ GetJsonValue<std::vector<std::vector<uint8_t >>>(map_json, " values" ));
18791849 if (keys.size () != values.size ()) {
18801850 return JsonParseError (" '{}' binary map keys and values have different lengths" , key);
18811851 }
18821852 for (size_t i = 0 ; i < keys.size (); ++i) {
1883- target[keys[i]] = Base64Decode ( values[i]) ;
1853+ target[keys[i]] = values[i];
18841854 }
18851855 return {};
18861856 };
@@ -1889,9 +1859,8 @@ Result<DataFile> DataFileFromJson(
18891859 ICEBERG_RETURN_UNEXPECTED (parse_binary_map (kUpperBounds , df.upper_bounds ));
18901860
18911861 if (json.contains (kKeyMetadata ) && !json.at (kKeyMetadata ).is_null ()) {
1892- ICEBERG_ASSIGN_OR_RAISE (auto key_meta_str,
1893- GetJsonValue<std::string>(json, kKeyMetadata ));
1894- df.key_metadata = Base64Decode (key_meta_str);
1862+ ICEBERG_ASSIGN_OR_RAISE (df.key_metadata ,
1863+ GetJsonValue<std::vector<uint8_t >>(json, kKeyMetadata ));
18951864 }
18961865 if (json.contains (kSplitOffsets ) && !json.at (kSplitOffsets ).is_null ()) {
18971866 ICEBERG_ASSIGN_OR_RAISE (df.split_offsets ,
0 commit comments