ResultOk

Undocumented in source.
@safe
@recordType("OK")
struct ResultOk {}

Members

Mixins

__anonymous
mixin HiBONRecord!()
Undocumented in source.

Mixed In Members

From mixin HiBONRecord!()

check
alias check = Check!(HiBONRecordException)
Undocumented in source.
__anonymous
mixin JSONString
Undocumented in source.
__anonymous
mixin HiBONRecordType
Undocumented in source.
isRecord
alias isRecord = HiBONRecord.isRecord!ThisType
Undocumented in source.
HAS_TYPE
enum HAS_TYPE;
Undocumented in source.
less_than
bool less_than(Key a, Key b)
Undocumented in source. Be warned that the author may not have intended to support it.
toHiBON
inout(HiBON) toHiBON()
Undocumented in source. Be warned that the author may not have intended to support it.
NO_DEFAULT_CTOR
enum NO_DEFAULT_CTOR;
Undocumented in source.
GetKeyName
template GetKeyName(uint i)
Undocumented in source.
_keys
string[] _keys()
keys
enum keys;
Undocumented in source.
this
this(HiBON hibon)
Undocumented in source.
this
this(Document doc)
Undocumented in source.
serialize
immutable(ubyte[]) serialize()
Undocumented in source. Be warned that the author may not have intended to support it.
toDoc
const(Document) toDoc()
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

1 import tagion.crypto.SecureNet : BadSecureNet, StdSecureNet;
2 import tagion.hibon.HiBONRecord;
3 import tagion.crypto.secp256k1.NativeSecp256k1;
4 
5 class HiRPCNet : StdSecureNet {
6     this(string passphrase) {
7         super();
8         generateKeyPair(passphrase);
9     }
10 }
11 
12 immutable passphrase = "Very secret password for the server";
13 enum func_name = "func_name";
14 
15 {
16     HiRPC hirpc = HiRPC(new HiRPCNet(passphrase));
17     HiRPC bad_hirpc = HiRPC(new BadSecureNet(passphrase));
18     auto params = new HiBON;
19     params["test"] = 42;
20     // Create a send method name func_name and argument params
21     const sender = hirpc.action(func_name, params);
22     // Sender with bad credetials
23     const invalid_sender = bad_hirpc.action(func_name, params, sender.method.id);
24 
25     const doc = sender.toDoc;
26     const invalid_doc = invalid_sender.toDoc;
27 
28     // Convert the do to a received HiRPC
29     const receiver = hirpc.receive(doc);
30     const invalid_receiver = hirpc.receive(invalid_doc);
31 
32     assert(receiver.method.id is sender.method.id);
33     assert(receiver.method.name == sender.method.name);
34     // Check that the received HiRPC is sigen correctly
35     assert(receiver.signed is HiRPC.SignedState.VALID);
36 
37     assert(invalid_receiver.method.id is sender.method.id);
38     assert(invalid_receiver.method.name == sender.method.name);
39     assert(invalid_receiver.signed is HiRPC.SignedState.INVALID);
40 
41     static struct ResultStruct {
42         int x;
43         mixin HiBONRecord;
44     }
45 
46     { // Response
47         auto hibon = new HiBON;
48         hibon["x"] = 42;
49         const send_back = hirpc.result(receiver, hibon);
50         const result = ResultStruct(send_back.response.result);
51         assert(result.x is 42);
52     }
53 
54     { // Error
55         const send_error = hirpc.error(receiver, "Some error", -1);
56         assert(send_error.error.message == "Some error");
57         assert(send_error.error.code == -1);
58         assert(send_error.isSigned);
59     }
60 }
61 
62 {
63     HiRPC hirpc;
64     { /// Unsigend message (no permission)
65         HiBON t = new HiBON();
66         t["$test"] = 5;
67 
68         const sender = hirpc.action("action", t);
69 
70         auto test2 = sender.toDoc;
71         // writeln(test2.toJSON);
72         // writefln("sender.isSigned=%s", sender.isSigned);
73         assert(!sender.isSigned, "This message is un-sigend, which is fine because the HiRPC does not contain a SecureNet");
74         {
75             const receiver = hirpc.receive(sender.toDoc);
76             // writefln("receiver=%s", receiver);
77             assert(receiver.method.id is sender.method.id);
78             // writefln("receiver.method.name is sender.method.name", receiver.method.name, sender.method.name);
79             assert(receiver.method.name == sender.method.name);
80             assert(receiver.signed is HiRPC.SignedState.NOSIGN);
81 
82             const params = receiver.method.params;
83             assert(params["$test"].get!int  is 5);
84         }
85     }
86     // writefln("recever.verified=%s", recever.verified);
87 }

Meta