1 |
|
%% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com> |
2 |
|
%% |
3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
%% you may not use this file except in compliance with the License. |
5 |
|
%% You may obtain a copy of the License at |
6 |
|
%% |
7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
%% |
9 |
|
%% Unless required by applicable law or agreed to in writing, software |
10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
%% See the License for the specific language governing permissions and |
13 |
|
%% limitations under the License. |
14 |
|
|
15 |
|
|
16 |
|
-module(msmp_com_query). |
17 |
|
|
18 |
|
|
19 |
|
-feature(maybe_expr, enable). |
20 |
|
|
21 |
|
|
22 |
|
-export([decode/1]). |
23 |
|
-export([encode/1]). |
24 |
|
|
25 |
|
|
26 |
|
decode(ClientFlags) -> |
27 |
4 |
fun |
28 |
|
(Input) -> |
29 |
13 |
(scran_result:into_map( |
30 |
|
scran_sequence:sequence( |
31 |
|
[scran_result:kv( |
32 |
|
action, |
33 |
|
scran_combinator:value( |
34 |
|
com_query, |
35 |
|
scran_bytes:tag(command()))), |
36 |
|
|
37 |
|
scran_combinator:condition( |
38 |
|
fun |
39 |
|
() -> |
40 |
13 |
maps:get(query_attributes, ClientFlags) |
41 |
|
end, |
42 |
|
scran_sequence:sequence( |
43 |
|
[scran_result:kv( |
44 |
|
parameter_count, |
45 |
|
msmp_integer_fixed:decode(1)), |
46 |
|
|
47 |
|
scran_branch:alt( |
48 |
|
[scran_sequence:sequence( |
49 |
|
[scran_combinator:ignore_result( |
50 |
|
scran_combinator:peek( |
51 |
|
scran_bytes:tag(<<1:8>>))), |
52 |
|
|
53 |
|
scran_result:kv( |
54 |
|
parameter_set, |
55 |
|
msmp_integer_fixed:decode(1)), |
56 |
|
|
57 |
|
scran_result:kv( |
58 |
|
query, |
59 |
|
scran_combinator:rest())]), |
60 |
|
|
61 |
|
scran_sequence:sequence( |
62 |
|
[scran_result:kv( |
63 |
|
parameter_set, |
64 |
|
msmp_integer_fixed:decode(1)), |
65 |
|
|
66 |
|
scran_result:kv( |
67 |
|
unknown_uint4, |
68 |
|
msmp_integer_fixed:decode(4)), |
69 |
|
|
70 |
|
scran_result:kv( |
71 |
|
query, |
72 |
|
msmp_string_length_encoded:decode()), |
73 |
|
|
74 |
|
scran_result:kv( |
75 |
|
rest, |
76 |
|
scran_combinator:rest())])])]), |
77 |
|
|
78 |
|
scran_sequence:sequence( |
79 |
|
[scran_result:kv( |
80 |
|
query, |
81 |
|
scran_combinator:rest())]))])))(Input) |
82 |
|
end. |
83 |
|
|
84 |
|
|
85 |
|
encode(#{query_attributes := QueryAttributes}) -> |
86 |
:-( |
fun |
87 |
|
(Decoded) -> |
88 |
:-( |
(narcs_sequence:sequence( |
89 |
|
[narcs_bytes:tag(command()), |
90 |
|
narcs_combinator:condition( |
91 |
|
QueryAttributes, |
92 |
|
narcs_sequence:sequence( |
93 |
|
[narcs_combinator:v( |
94 |
|
parameter_count, |
95 |
|
msmp_integer_fixed:encode(1)), |
96 |
|
narcs_combinator:v( |
97 |
|
parameter_set, |
98 |
|
msmp_integer_fixed:encode(1))])), |
99 |
|
narcs_combinator:v( |
100 |
|
query, |
101 |
|
narcs_combinator:rest())]))(Decoded) |
102 |
|
end. |
103 |
|
|
104 |
|
|
105 |
|
command() -> |
106 |
13 |
<<3>>. |