Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55807e2c authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Automerger Merge Worker
Browse files

Merge "Adding block kind to protocol for future streaming of a tree." into...

Merge "Adding block kind to protocol for future streaming of a tree." into rvc-dev am: c0a5aff0 am: c422da86 am: 6a3be071

Change-Id: I772c5c473c36d1e6b8077cf51d5c7dc9f5558751
parents 60374e22 6a3be071
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -46,8 +46,9 @@ namespace incremental {


static constexpr int kBlockSize = 4096;
static constexpr int kBlockSize = 4096;
static constexpr int kCompressedSizeMax = kBlockSize * 0.95;
static constexpr int kCompressedSizeMax = kBlockSize * 0.95;
static constexpr short kCompressionNone = 0;
static constexpr int8_t kTypeData = 0;
static constexpr short kCompressionLZ4 = 1;
static constexpr int8_t kCompressionNone = 0;
static constexpr int8_t kCompressionLZ4 = 1;
static constexpr int kCompressBound = std::max(kBlockSize, LZ4_COMPRESSBOUND(kBlockSize));
static constexpr int kCompressBound = std::max(kBlockSize, LZ4_COMPRESSBOUND(kBlockSize));
static constexpr auto kReadBufferSize = 128 * 1024;
static constexpr auto kReadBufferSize = 128 * 1024;
static constexpr int kPollTimeoutMillis = 300000;  // 5 minutes
static constexpr int kPollTimeoutMillis = 300000;  // 5 minutes
@@ -56,7 +57,8 @@ using BlockSize = int16_t;
using FileId = int16_t;
using FileId = int16_t;
using BlockIdx = int32_t;
using BlockIdx = int32_t;
using NumBlocks = int32_t;
using NumBlocks = int32_t;
using CompressionType = int16_t;
using BlockType = int8_t;
using CompressionType = int8_t;
using RequestType = int16_t;
using RequestType = int16_t;
using ChunkHeader = int32_t;
using ChunkHeader = int32_t;
using MagicType = uint32_t;
using MagicType = uint32_t;
@@ -126,7 +128,8 @@ struct RequestCommand {
// Placed before actual data bytes of each block
// Placed before actual data bytes of each block
struct ResponseHeader {
struct ResponseHeader {
    FileId file_id;                    // 2 bytes
    FileId file_id;                    // 2 bytes
    CompressionType compression_type;  // 2 bytes
    BlockType block_type;              // 1 byte
    CompressionType compression_type;  // 1 byte
    BlockIdx block_idx;                // 4 bytes
    BlockIdx block_idx;                // 4 bytes
    BlockSize block_size;              // 2 bytes
    BlockSize block_size;              // 2 bytes
} __attribute__((packed));
} __attribute__((packed));
@@ -343,14 +346,16 @@ auto IncrementalServer::SendBlock(FileId fileId, BlockIdx blockIdx, bool flush)
        ++compressed_;
        ++compressed_;
        blockSize = compressedSize;
        blockSize = compressedSize;
        header = reinterpret_cast<ResponseHeader*>(data);
        header = reinterpret_cast<ResponseHeader*>(data);
        header->compression_type = toBigEndian(kCompressionLZ4);
        header->compression_type = kCompressionLZ4;
    } else {
    } else {
        ++uncompressed_;
        ++uncompressed_;
        blockSize = bytesRead;
        blockSize = bytesRead;
        header = reinterpret_cast<ResponseHeader*>(raw);
        header = reinterpret_cast<ResponseHeader*>(raw);
        header->compression_type = toBigEndian(kCompressionNone);
        header->compression_type = kCompressionNone;
    }
    }


    header->block_type = kTypeData;

    header->file_id = toBigEndian(fileId);
    header->file_id = toBigEndian(fileId);
    header->block_size = toBigEndian(blockSize);
    header->block_size = toBigEndian(blockSize);
    header->block_idx = toBigEndian(blockIdx);
    header->block_idx = toBigEndian(blockIdx);
@@ -364,6 +369,7 @@ auto IncrementalServer::SendBlock(FileId fileId, BlockIdx blockIdx, bool flush)
bool IncrementalServer::SendDone() {
bool IncrementalServer::SendDone() {
    ResponseHeader header;
    ResponseHeader header;
    header.file_id = -1;
    header.file_id = -1;
    header.block_type = 0;
    header.compression_type = 0;
    header.compression_type = 0;
    header.block_idx = 0;
    header.block_idx = 0;
    header.block_size = 0;
    header.block_size = 0;