aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/util/shared_data_rope_backend.h
blob: 2abfcf558472cb59ae715c961ea791c723aad6af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <library/cpp/actors/util/rc_buf.h>

#include "shared_data.h"

namespace NActors {

class TRopeSharedDataBackend : public IContiguousChunk {
    TSharedData Buffer;

public:
    TRopeSharedDataBackend(TSharedData buffer)
        : Buffer(std::move(buffer))
    {}

    TContiguousSpan GetData() const override {
        return {Buffer.data(), Buffer.size()};
    }

    TMutableContiguousSpan GetDataMut() override {
        if(Buffer.IsShared()) {
            Buffer = TSharedData::Copy(Buffer.data(), Buffer.size());
        }
        return {Buffer.mutable_data(), Buffer.size()};
    }

    TMutableContiguousSpan UnsafeGetDataMut() override {
        return {const_cast<char *>(Buffer.data()), Buffer.size()};
    }

    size_t GetOccupiedMemorySize() const override {
        return Buffer.size();
    }
};

} // namespace NActors