sapling/eden/fs/store/SerializedBlobMetadata.h
Katie Mancini 550400364d introduce tree metadata storage in local store
Summary:
This introduces a class to manipulate the metadata for all the entries in a
tree. This adds serialization and deserialization to this class so that it can
be written to the local store.

Why do we need this? We need some way to easily check when we have already
fetched metadata for a tree and do not need to refetch this from the server to
avoid expensive network requests. Later diffs add functionally to store the metadata
for tree entries in the local store under the tree hash using this class.

Reviewed By: chadaustin

Differential Revision: D21959015

fbshipit-source-id: 0c0e8750737f3076c1f9604d0319cab7f2658656
2020-07-10 16:03:32 -07:00

44 lines
1.1 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <folly/Range.h>
#include "eden/fs/model/Hash.h"
#include "eden/fs/store/BlobMetadata.h"
#include "eden/fs/store/StoreResult.h"
namespace facebook {
namespace eden {
class TreeMetadata;
class SerializedBlobMetadata {
public:
explicit SerializedBlobMetadata(const BlobMetadata& metadata);
SerializedBlobMetadata(const Hash& contentsHash, uint64_t blobSize);
folly::ByteRange slice() const;
static BlobMetadata parse(Hash blobID, const StoreResult& result);
static constexpr size_t SIZE = sizeof(uint64_t) + Hash::RAW_SIZE;
private:
void serialize(const Hash& contentsHash, uint64_t blobSize);
static BlobMetadata unslice(folly::ByteRange bytes);
/**
* The serialized data is stored as stored as:
* - size (8 bytes, big endian)
* - hash (20 bytes)
*/
std::array<uint8_t, SIZE> data_;
friend class TreeMetadata;
};
} // namespace eden
} // namespace facebook