/
NotifierTypes.d
173 lines (118 loc) · 5.12 KB
/
NotifierTypes.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*******************************************************************************
DHT-specific types passed to client request notifier delegates.
Copyright:
Copyright (c) 2017 sociomantic labs GmbH. All rights reserved.
License:
Boost Software License Version 1.0. See LICENSE.txt for details.
*******************************************************************************/
module dhtproto.client.NotifierTypes;
import ocean.transition;
import Formatter = ocean.text.convert.Formatter;
/*******************************************************************************
A chunk of untyped data along with a key.
*******************************************************************************/
public struct RequestRecordInfo
{
import swarm.neo.protocol.Message : RequestId;
import swarm.neo.client.mixins.DeserializeMethod;
/// ID of the request for which the notification is occurring.
RequestId request_id;
/// Record key.
hash_t key;
/// Record value.
Const!(void)[] value;
/// Template method to deserialize `value` as a given struct.
mixin DeserializeMethod!(value);
/***************************************************************************
Formats a description of the notification to the provided sink delegate.
Params:
sink = delegate to feed formatted strings to
***************************************************************************/
public void toString ( scope void delegate ( cstring chunk ) sink )
{
Formatter.sformat(
sink,
"Request #{} provided the record 0x{:x16}:{}",
(&this).request_id, (&this).key, (&this).value);
}
}
/*******************************************************************************
A chunk of untyped data along with a pointer to a buffer to receive a
modified version.
*******************************************************************************/
public struct RequestDataUpdateInfo
{
import swarm.neo.protocol.Message : RequestId;
import swarm.neo.client.mixins.DeserializeMethod;
/// ID of the request for which the notification is occurring.
RequestId request_id;
/// Record value.
Const!(void)[] value;
/// Buffer to receive updated value.
void[]* updated_value;
/// Template method to deserialize `value` as a given struct.
mixin DeserializeMethod!(value);
/// Template method to serialize a given struct into `updated_value`.
mixin SerializeMethod!(updated_value);
/***************************************************************************
Formats a description of the notification to the provided sink delegate.
Params:
sink = delegate to feed formatted strings to
***************************************************************************/
public void toString ( scope void delegate ( cstring chunk ) sink )
{
Formatter.sformat(
sink,
"Request #{} provided the record {} to be updated",
(&this).request_id, (&this).value);
}
}
/*******************************************************************************
A record key.
*******************************************************************************/
public struct RequestKeyInfo
{
import swarm.neo.protocol.Message : RequestId;
/// ID of the request for which the notification is occurring.
RequestId request_id;
/// Record key.
hash_t key;
/***************************************************************************
Formats a description of the notification to the provided sink delegate.
Params:
sink = delegate to feed formatted strings to
***************************************************************************/
public void toString ( scope void delegate ( cstring chunk ) sink )
{
Formatter.sformat(
sink,
"Request #{} provided the key 0x{:x16}",
(&this).request_id, (&this).key);
}
}
/*******************************************************************************
Mixin for method to serialize a record value.
Params:
dst = pointer to the buffer to be serialized into
TODO: deprecated, replace with implementation in swarm
*******************************************************************************/
template SerializeMethod ( alias dst )
{
import ocean.util.serialize.contiguous.Contiguous;
import ocean.util.serialize.Version;
import ocean.util.serialize.contiguous.Serializer;
import ocean.util.serialize.contiguous.MultiVersionDecorator;
/***************************************************************************
Serializes `src` into `dst`, using a version decorater, if required.
Params:
T = type of struct to serialize
src = instance to serialize
***************************************************************************/
public void serialize ( T ) ( T src )
{
static if ( Version.Info!(T).exists )
VersionDecorator.store!(T)(src, *dst);
else
Serializer.serialize(src, *dst);
}
}