48 std::vector<std::pair<std::string, AttrValue>> out;
52 std::unordered_map<std::uint16_t, const ColumnInfo*> by_index;
53 by_index.reserve(schema.size());
54 for (
const auto& c : schema)
55 by_index.emplace(c.index, &c);
58 while (at < blob.
size()) {
59 need(blob, at, 2,
"column index");
60 const std::uint16_t col_index = get_le<std::uint16_t>(blob, at);
63 auto found = by_index.find(col_index);
64 if (
found == by_index.end()) {
66 "attribute references unknown column index " + std::to_string(col_index));
69 const auto type =
static_cast<::ColumnType
>(col.
type);
73 case ::ColumnType::Bool:
74 need(blob, at, 1,
"Bool");
79 case ::ColumnType::Short:
80 need(blob, at, 2,
"Short");
82 v.i = get_le<std::int16_t>(blob, at);
85 case ::ColumnType::UShort:
86 need(blob, at, 2,
"UShort");
88 v.u = get_le<std::uint16_t>(blob, at);
91 case ::ColumnType::Int:
92 need(blob, at, 4,
"Int");
94 v.i = get_le<std::int32_t>(blob, at);
97 case ::ColumnType::UInt:
98 need(blob, at, 4,
"UInt");
100 v.u = get_le<std::uint32_t>(blob, at);
103 case ::ColumnType::Long:
104 need(blob, at, 8,
"Long");
106 v.i = get_le<std::int64_t>(blob, at);
109 case ::ColumnType::ULong:
110 need(blob, at, 8,
"ULong");
112 v.u = get_le<std::uint64_t>(blob, at);
115 case ::ColumnType::Float:
116 need(blob, at, 4,
"Float");
118 v.d =
static_cast<double>(get_f32(blob, at));
121 case ::ColumnType::Double:
122 need(blob, at, 8,
"Double");
124 v.d = get_f64(blob, at);
128 case ::ColumnType::String:
129 case ::ColumnType::DateTime:
130 case ::ColumnType::Json: {
133 need(blob, at, 4,
"string length");
134 const std::uint32_t len = get_le<std::uint32_t>(blob, at);
136 need(blob, at, len,
"string body");
139 v.s.assign(
reinterpret_cast<const char*
>(blob.
data()) + at, len);
148 case ::ColumnType::Byte:
149 need(blob, at, 1,
"Byte");
151 v.u = get_le<std::uint8_t>(blob, at);
154 case ::ColumnType::UByte:
155 need(blob, at, 1,
"UByte");
157 v.u = get_le<std::uint8_t>(blob, at);
161 case ::ColumnType::Binary: {
164 need(blob, at, 4,
"binary length");
165 const std::uint32_t len = get_le<std::uint32_t>(blob, at);
167 need(blob, at, len,
"binary body");
169 v.s.assign(
reinterpret_cast<const char*
>(blob.
data()) + at, len);
175 out.emplace_back(col.
name, std::move(v));
nlohmann::json attributes_to_json(bytes_view blob, const std::vector< ColumnInfo > &schema)
Same decode, rendered as a JSON object for CityJSON emission.
std::vector< std::pair< std::string, AttrValue > > decode_attributes(bytes_view blob, const std::vector< ColumnInfo > &schema)
Decode a feature's attribute blob against the column schema.