-
Notifications
You must be signed in to change notification settings - Fork 22
/
GetAllFilter.d
95 lines (57 loc) · 2.88 KB
/
GetAllFilter.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
/*******************************************************************************
Turtle implementation of DHT `GetAllFilter` request
Copyright:
Copyright (c) 2015-2017 dunnhumby Germany GmbH. All rights reserved.
License:
Boost Software License Version 1.0. See LICENSE.txt for details.
*******************************************************************************/
module fakedht.request.GetAllFilter;
/*******************************************************************************
Imports
*******************************************************************************/
import ocean.transition;
import Protocol = dhtproto.node.request.GetAllFilter;
/*******************************************************************************
Request implementation
*******************************************************************************/
public scope class GetAllFilter : Protocol.GetAllFilter
{
import fakedht.mixins.RequestConstruction;
import fakedht.mixins.ChannelIteration;
import ocean.text.Search;
/***************************************************************************
Sub-string search instance.
***************************************************************************/
private SearchFruct!(Const!(char)) match;
/***************************************************************************
Adds this.resources and constructor to initialize it and forward
arguments to base
***************************************************************************/
mixin RequestConstruction!();
/***************************************************************************
Predicate that accepts records that match filter defined by this.match
Params:
key = record key to check
value = record value to check
Returns:
'true' if record matches (should not be filtered out)
***************************************************************************/
private bool filterPredicate ( cstring key, cstring value )
{
return this.match.forward(value) < value.length;
}
/***************************************************************************
Adds this.iterator and prepareChannel override to initialize it
Defines `getNext` that uses filterPredicate to filter records
***************************************************************************/
mixin ChannelIteration!(IterationKind.KeyValue, filterPredicate);
/***************************************************************************
Initialized regex match based on provided filter string
Params:
filter = filter string
***************************************************************************/
final override protected void prepareFilter ( cstring filter )
{
this.match = search(filter);
}
}