-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
- Loading branch information
Showing
6 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <scale/scale.hpp> | ||
|
||
namespace jam { | ||
using scale::decode; | ||
using scale::encode; | ||
|
||
template <typename T, typename... Configs> | ||
[[nodiscard]] outcome::result<std::vector<uint8_t>> encode_with_config( | ||
T &&value, Configs &&...configs) { | ||
scale::Encoder<scale::backend::ToBytes> encoder{ | ||
std::forward<Configs>(configs)...}; | ||
try { | ||
encode(std::forward<T>(value), encoder); | ||
} catch (std::system_error &e) { | ||
return outcome::failure(e.code()); | ||
} | ||
return std::move(encoder).backend().to_vector(); | ||
} | ||
|
||
template <typename T, typename... Configs> | ||
[[nodiscard]] outcome::result<T> decode_with_config( | ||
scale::ConstSpanOfBytes bytes, Configs &&...configs) { | ||
scale::Decoder<scale::backend::FromBytes> decoder{ | ||
bytes, std::forward<Configs>(configs)...}; | ||
T value; | ||
try { | ||
decode(value, decoder); | ||
} catch (std::system_error &e) { | ||
return outcome::failure(e.code()); | ||
} | ||
return std::move(value); | ||
} | ||
|
||
} // namespace jam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters