+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+void DecodeSignal::get_annotation_subset(
+ vector<pv::data::decode::Annotation> &dest,
+ uint32_t segment_id, uint64_t start_sample, uint64_t end_sample) const
+{
+ // Note: We put all vectors and lists on the heap, not the stack
+
+ const vector<Row> rows = get_rows(true);
+
+ // Use forward_lists for faster merging
+ forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
+
+ for (const Row& row : rows) {
+ vector<Annotation> *ann_vector = new vector<Annotation>();
+ get_annotation_subset(*ann_vector, row, segment_id, start_sample, end_sample);
+
+ forward_list<Annotation> *ann_list =
+ new forward_list<Annotation>(ann_vector->begin(), ann_vector->end());
+ delete ann_vector;
+
+ all_ann_list->merge(*ann_list);
+ delete ann_list;
+ }
+
+ move(all_ann_list->begin(), all_ann_list->end(), back_inserter(dest));
+ delete all_ann_list;
+}
+
+uint32_t DecodeSignal::get_binary_data_chunk_count(uint32_t segment_id) const
+{
+ uint32_t count = 0;
+
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+ count = segment->binary_data.size();
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+
+ return count;
+}
+
+void DecodeSignal::get_binary_data_chunk(uint32_t segment_id, uint32_t chunk_id,
+ const vector<uint8_t> **dest, uint64_t *size)
+{
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+ if (dest)
+ *dest = &(segment->binary_data.at(chunk_id).data);
+ if (size)
+ *size = segment->binary_data.at(chunk_id).data.size();
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+void DecodeSignal::get_binary_data_chunks_merged(uint32_t segment_id,
+ uint64_t start_sample, uint64_t end_sample, vector<uint8_t> *dest) const
+{
+ assert(dest != nullptr);
+
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+
+ // Determine overall size before copying to resize dest vector only once
+ uint64_t size = 0;
+ for (const DecodeBinaryData& d : segment->binary_data)
+ if ((d.sample >= start_sample) && (d.sample < end_sample))
+ size += d.data.size();
+ dest->reserve(size);
+
+ uint64_t index = 0;
+ for (const DecodeBinaryData& d : segment->binary_data)
+ if ((d.sample >= start_sample) && (d.sample < end_sample)) {
+ memcpy(dest->data() + index, d.data.data(), d.data.size());
+ index += d.data.size();
+ }
+ } catch (out_of_range&) {