-
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.
Merge pull request NixOS#9137 from obsidiansystems/serve-protocol
Introduce separate Serve protocol serialisers
- Loading branch information
Showing
15 changed files
with
344 additions
and
39 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
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,59 @@ | ||
#pragma once | ||
/** | ||
* @file | ||
* | ||
* Template implementations (as opposed to mere declarations). | ||
* | ||
* This file is an exmample of the "impl.hh" pattern. See the | ||
* contributing guide. | ||
*/ | ||
|
||
#include "serve-protocol.hh" | ||
#include "length-prefixed-protocol-helper.hh" | ||
|
||
namespace nix { | ||
|
||
/* protocol-agnostic templates */ | ||
|
||
#define SERVE_USE_LENGTH_PREFIX_SERIALISER(TEMPLATE, T) \ | ||
TEMPLATE T ServeProto::Serialise< T >::read(const Store & store, ServeProto::ReadConn conn) \ | ||
{ \ | ||
return LengthPrefixedProtoHelper<ServeProto, T >::read(store, conn); \ | ||
} \ | ||
TEMPLATE void ServeProto::Serialise< T >::write(const Store & store, ServeProto::WriteConn conn, const T & t) \ | ||
{ \ | ||
LengthPrefixedProtoHelper<ServeProto, T >::write(store, conn, t); \ | ||
} | ||
|
||
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::vector<T>) | ||
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::set<T>) | ||
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename... Ts>, std::tuple<Ts...>) | ||
|
||
#define COMMA_ , | ||
SERVE_USE_LENGTH_PREFIX_SERIALISER( | ||
template<typename K COMMA_ typename V>, | ||
std::map<K COMMA_ V>) | ||
#undef COMMA_ | ||
|
||
/** | ||
* Use `CommonProto` where possible. | ||
*/ | ||
template<typename T> | ||
struct ServeProto::Serialise | ||
{ | ||
static T read(const Store & store, ServeProto::ReadConn conn) | ||
{ | ||
return CommonProto::Serialise<T>::read(store, | ||
CommonProto::ReadConn { .from = conn.from }); | ||
} | ||
static void write(const Store & store, ServeProto::WriteConn conn, const T & t) | ||
{ | ||
CommonProto::Serialise<T>::write(store, | ||
CommonProto::WriteConn { .to = conn.to }, | ||
t); | ||
} | ||
}; | ||
|
||
/* protocol-specific templates */ | ||
|
||
} |
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,15 @@ | ||
#include "serialise.hh" | ||
#include "util.hh" | ||
#include "path-with-outputs.hh" | ||
#include "store-api.hh" | ||
#include "serve-protocol.hh" | ||
#include "serve-protocol-impl.hh" | ||
#include "archive.hh" | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace nix { | ||
|
||
/* protocol-specific definitions */ | ||
|
||
} |
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
Oops, something went wrong.