sapling/eden/fs/store/SerializedBlobMetadata.h
Barys Skarabahaty 3ae264c71c Add blake3 support to Serialized blob metadata
Summary:
Adding blake3 support to SerializedBlobMetadata.

* The serialized data is stored as:
   * - version (1 byte, big endian)
   * - blob_size (up to 10 bytes, big endian)
   * - used_hashes (1 byte, big-endian)
   * - hashes stored in order of their type values e.g. from less significant
   to more significant
   * - hash (N bytes)
   ...
   * - hash (M bytes)

Reviewed By: chadaustin

Differential Revision: D44500908

fbshipit-source-id: d64081db8591f85be5cdf3fd98ff9839c028d5fb
2023-06-05 23:41:35 -07:00

55 lines
1.3 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <optional>
#include <folly/Range.h>
#include "eden/fs/model/BlobMetadata.h"
#include "eden/fs/model/Hash.h"
#include "eden/fs/model/ObjectId.h"
#include "eden/fs/store/StoreResult.h"
namespace facebook::eden {
class SerializedBlobMetadata {
public:
explicit SerializedBlobMetadata(const BlobMetadata& metadata);
SerializedBlobMetadata(
const Hash20& sha1,
const std::optional<Hash32>& blake3,
uint64_t blobSize);
folly::ByteRange slice() const;
static BlobMetadataPtr parse(
const ObjectId& blobID,
const StoreResult& result);
private:
void serialize(
const Hash20& sha1,
const std::optional<Hash32>& blake3,
uint64_t blobSize);
/**
* The serialized data is stored as:
* - version (1 byte)
* - blob_size (varint, little endian)
* - used_hashes (varint, little endian)
* - hashes stored in order of their type values e.g. from less significant
to more significant
* - hash (N bytes)
...
* - hash (M bytes)
*/
std::pair<std::unique_ptr<uint8_t[]>, size_t> dataAndSize_;
};
} // namespace facebook::eden