CatapultServer  v0.5.0.1 (Elephant)
PatriciaTreeEncoderAdapters.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/crypto/Hashes.h"
24 
25 namespace catapult { namespace cache {
26 
28  template<typename TSerializer>
30  public:
31  using KeyType = typename TSerializer::KeyType;
32  using ValueType = typename TSerializer::ValueType;
33 
34  public:
36  static constexpr const KeyType& EncodeKey(const KeyType& key) {
37  return key;
38  }
39 
41  static Hash256 EncodeValue(const ValueType& value) {
42  auto encodedData = TSerializer::SerializeValue(value);
43 
44  Hash256 valueHash;
45  crypto::Sha3_256({ reinterpret_cast<const uint8_t*>(encodedData.data()), encodedData.size() }, valueHash);
46  return valueHash;
47  }
48  };
49 
51  template<typename TSerializer>
53  public:
56  Hash256 keyHash;
57  crypto::Sha3_256(SerializeKey(key), keyHash);
58  return keyHash;
59  }
60  };
61 }}
KeySerializers.h
catapult::cache::SerializerPlainKeyEncoder::EncodeKey
static constexpr const KeyType & EncodeKey(const KeyType &key)
Encodes key by returning it without modification.
Definition: PatriciaTreeEncoderAdapters.h:36
catapult::cache::SerializerPlainKeyEncoder::KeyType
typename TSerializer::KeyType KeyType
Definition: PatriciaTreeEncoderAdapters.h:31
catapult::crypto::Sha3_256
void Sha3_256(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates the 256-bit SHA3 hash of dataBuffer into hash.
Definition: Hashes.cpp:81
catapult::cache::SerializerPlainKeyEncoder::EncodeValue
static Hash256 EncodeValue(const ValueType &value)
Encodes value by hashing it.
Definition: PatriciaTreeEncoderAdapters.h:41
Hashes.h
catapult::cache::SerializerHashedKeyEncoder
Encoder adapter that hashes values and keys.
Definition: PatriciaTreeEncoderAdapters.h:52
catapult::cache::SerializerPlainKeyEncoder::ValueType
typename TSerializer::ValueType ValueType
Definition: PatriciaTreeEncoderAdapters.h:32
catapult::cache::SerializeKey
RawBuffer SerializeKey(const TValue &value)
Serializes value-based key (value).
Definition: KeySerializers.h:31
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::cache::SerializerPlainKeyEncoder
Encoder adapter that hashes values but not keys.
Definition: PatriciaTreeEncoderAdapters.h:29
catapult::cache::SerializerHashedKeyEncoder::EncodeKey
static Hash256 EncodeKey(const typename SerializerPlainKeyEncoder< TSerializer >::KeyType &key)
Encodes key by hashing it.
Definition: PatriciaTreeEncoderAdapters.h:55