Skip to content

Commit

Permalink
Implement a bi-directional WebSocket based RPC system.
Browse files Browse the repository at this point in the history
This implements a bi-directional alternative to the REST interface system, enabling HTTP based peer-to-peer communication over a unidirectional HTTP/TCP connection.
  • Loading branch information
s-ludwig committed Apr 8, 2024
1 parent 992a638 commit 62717d6
Show file tree
Hide file tree
Showing 3 changed files with 779 additions and 19 deletions.
4 changes: 2 additions & 2 deletions web/vibe/web/internal/rest/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import std.traits : hasUDA;
The given `TImpl` must be an `interface` or a `class` deriving from one.
*/
/*package(vibe.web.web)*/ struct RestInterface(TImpl)
/*package(vibe.web.web)*/ struct RestInterface(TImpl, bool support_webparam_attributes = true)
if (is(TImpl == class) || is(TImpl == interface))
{
@safe:
Expand Down Expand Up @@ -56,7 +56,7 @@ import std.traits : hasUDA;
alias I = TImpl;
else
alias I = BaseInterfaces[0];
static assert(getInterfaceValidationError!I is null, getInterfaceValidationError!(I));
static assert(getInterfaceValidationError!(I, support_webparam_attributes) is null, getInterfaceValidationError!(I, support_webparam_attributes));

/// The name of each interface member
enum memberNames = [__traits(allMembers, I)];
Expand Down
36 changes: 19 additions & 17 deletions web/vibe/web/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ struct Collection(I)
alias ParentIDs = AllIDs[0 .. $-1];
alias ParentIDNames = AllIDNames[0 .. $-1];

private {
package {
I m_interface;
ParentIDs m_parentIDs;
}
Expand Down Expand Up @@ -2359,7 +2359,7 @@ unittest
// Check that the interface is valid. Every checks on the correctness of the
// interface should be put in checkRestInterface, which allows to have consistent
// errors in the server and client.
package string getInterfaceValidationError(I)()
package string getInterfaceValidationError(I, bool support_webparam_attributes = true)()
out (result) { assert((result is null) == !result.length); }
do {
import vibe.web.internal.rest.common : ParameterKind, WebParamUDATuple;
Expand Down Expand Up @@ -2416,21 +2416,23 @@ do {
}

// Check for misplaced out and non-const ref
alias PSC = ParameterStorageClass;
foreach (i, SC; ParameterStorageClassTuple!Func) {
static if (SC & PSC.out_ || (SC & PSC.ref_ && !is(ConstOf!(PT[i]) == PT[i])) ) {
mixin(GenCmp!("Loop", i, PN[i]).Decl);
alias Attr = AliasSeq!(
WebParamUDATuple!(Func, i),
Filter!(mixin(GenCmp!("Loop", i, PN[i]).Name), WPAT),
);
static if (Attr.length != 1) {
if (hack) return "%s: Parameter '%s' cannot be %s"
.format(FuncId, PN[i], SC & PSC.out_ ? "out" : "ref");
} else static if (Attr[0].origin != ParameterKind.header) {
if (hack) return "%s: %s parameter '%s' cannot be %s"
.format(FuncId, Attr[0].origin, PN[i],
SC & PSC.out_ ? "out" : "ref");
static if (support_webparam_attributes) {
alias PSC = ParameterStorageClass;
foreach (i, SC; ParameterStorageClassTuple!Func) {
static if (SC & PSC.out_ || (SC & PSC.ref_ && !is(ConstOf!(PT[i]) == PT[i])) ) {
mixin(GenCmp!("Loop", i, PN[i]).Decl);
alias Attr = AliasSeq!(
WebParamUDATuple!(Func, i),
Filter!(mixin(GenCmp!("Loop", i, PN[i]).Name), WPAT),
);
static if (Attr.length != 1) {
if (hack) return "%s: Parameter '%s' cannot be %s"
.format(FuncId, PN[i], SC & PSC.out_ ? "out" : "ref");
} else static if (Attr[0].origin != ParameterKind.header) {
if (hack) return "%s: %s parameter '%s' cannot be %s"
.format(FuncId, Attr[0].origin, PN[i],
SC & PSC.out_ ? "out" : "ref");
}
}
}
}
Expand Down
Loading

0 comments on commit 62717d6

Please sign in to comment.