MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / getReadableData

Method getReadableData

Libraries/AsyncStreams/AsyncStreams.cpp:56–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56Result AsyncBuffersPool::getReadableData(AsyncBufferView::ID bufferID, Span<const char>& data)
57{
58 AsyncBufferView* buffer = getBuffer(bufferID);
59 SC_TRY_MSG(buffer != nullptr, "AsyncBuffersPool::getReadableData - Invalid bufferID");
60 switch (buffer->type)
61 {
62 case AsyncBufferView::Type::Writable: {
63 Span<const char> constWritable = buffer->writableData;
64 SC_TRY(constWritable.sliceStartLength(buffer->offset, buffer->length, data));
65 break;
66 }
67 case AsyncBufferView::Type::ReadOnly:
68 SC_TRY(buffer->readonlyData.sliceStartLength(buffer->offset, buffer->length, data));
69 break;
70 case AsyncBufferView::Type::Growable: {
71 AsyncBufferView::GrowableStorage storage;
72
73 auto da = buffer->getGrowableBuffer(storage, true)->getDirectAccess();
74 Span<const char> fullData = {static_cast<char*>(da.data), da.sizeInBytes};
75 SC_TRY(fullData.sliceStartLength(buffer->offset, buffer->length, data));
76 (void)buffer->getGrowableBuffer(storage, false); // destruct
77 break;
78 }
79 case AsyncBufferView::Type::Child: {
80 AsyncBufferView* parent = getBuffer(buffer->parentID);
81 SC_TRY_MSG(parent != nullptr, "AsyncBuffersPool::getReadableData - Invalid parentID");
82 if (parent->type == AsyncBufferView::Type::Growable)
83 {
84 AsyncBufferView::GrowableStorage storage;
85
86 auto da = parent->getGrowableBuffer(storage, true)->getDirectAccess();
87 Span<const char> rootFullData = {static_cast<const char*>(da.data), da.sizeInBytes};
88 SC_TRY(rootFullData.sliceStartLength(buffer->offset, buffer->length, data));
89 buffer->readonlyData = data; // Update for debugging visibility
90 (void)parent->getGrowableBuffer(storage, false); // destruct
91 }
92 else
93 {
94 data = buffer->readonlyData;
95 }
96 break;
97 }
98 case AsyncBufferView::Type::Empty: AsyncStreamsAssert::unreachable(); break;
99 }
100 return Result(true);
101}
102
103Result AsyncBuffersPool::getWritableData(AsyncBufferView::ID bufferID, Span<char>& data)
104{

Callers 15

onDataMethod · 0.80
onDataMethod · 0.80
onDataMethod · 0.80
asyncWriteMethod · 0.80
onDataMethod · 0.80
onPatchDataMethod · 0.80
onDataMethod · 0.80
onDataMethod · 0.80
flushOneMethod · 0.80
onDataMethod · 0.80
flushOneMethod · 0.80
asyncWriteMethod · 0.80

Calls 1

ResultClass · 0.50

Tested by 15

onDataMethod · 0.64
onDataMethod · 0.64
onDataMethod · 0.64
asyncWriteMethod · 0.64
onDataMethod · 0.64
onPatchDataMethod · 0.64
onDataMethod · 0.64
onDataMethod · 0.64
flushOneMethod · 0.64
onDataMethod · 0.64
flushOneMethod · 0.64
asyncWriteMethod · 0.64