|
10 | 10 |
|
11 | 11 | namespace sparrow_ipc |
12 | 12 | { |
13 | | - void deserialize_schema_message( |
14 | | - std::span<const uint8_t> data, |
15 | | - size_t& current_offset, |
16 | | - std::optional<std::string>& name, |
17 | | - std::optional<std::vector<sparrow::metadata_pair>>& metadata |
18 | | - ) |
19 | | - { |
20 | | - if (data.size() < (current_offset + sizeof(uint32_t))) |
21 | | - { |
22 | | - throw std::runtime_error("Data too short to contain schema length."); |
23 | | - } |
24 | | - const uint32_t schema_meta_len = *(reinterpret_cast<const uint32_t*>(data.data() + current_offset)); |
25 | | - if (schema_meta_len == 0 || (data.size() < (current_offset + sizeof(uint32_t) + schema_meta_len))) |
26 | | - { |
27 | | - throw std::runtime_error("Invalid schema length."); |
28 | | - } |
29 | | - current_offset += sizeof(uint32_t); |
30 | | - const auto schema_message = org::apache::arrow::flatbuf::GetMessage(data.data() + current_offset); |
31 | | - if (schema_message->header_type() != org::apache::arrow::flatbuf::MessageHeader::Schema) |
32 | | - { |
33 | | - throw std::runtime_error("Expected Schema message at the start of the buffer."); |
34 | | - } |
35 | | - const auto flatbuffer_schema = static_cast<const org::apache::arrow::flatbuf::Schema*>( |
36 | | - schema_message->header() |
37 | | - ); |
38 | | - const auto fields = flatbuffer_schema->fields(); |
39 | | - if (fields->size() != 1) |
40 | | - { |
41 | | - throw std::runtime_error("Expected schema with exactly one field."); |
42 | | - } |
43 | | - |
44 | | - const auto field = fields->Get(0); |
45 | | - |
46 | | - // Get name |
47 | | - if (const auto fb_name = field->name()) |
48 | | - { |
49 | | - name = fb_name->str(); |
50 | | - } |
51 | | - |
52 | | - // Handle metadata |
53 | | - const auto fb_metadata = field->custom_metadata(); |
54 | | - if (fb_metadata && !fb_metadata->empty()) |
55 | | - { |
56 | | - metadata = std::vector<sparrow::metadata_pair>(); |
57 | | - metadata->reserve(fb_metadata->size()); |
58 | | - for (const auto& kv : *fb_metadata) |
59 | | - { |
60 | | - metadata->emplace_back(kv->key()->str(), kv->value()->str()); |
61 | | - } |
62 | | - } |
63 | | - current_offset += schema_meta_len; |
64 | | - } |
65 | | - |
66 | 13 | const org::apache::arrow::flatbuf::RecordBatch* |
67 | 14 | deserialize_record_batch_message(std::span<const uint8_t> data, size_t& current_offset) |
68 | 15 | { |
|
0 commit comments