_site/cover/msmp_status_variable.COVER.html

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_status_variable).
17
18
19 -feature(maybe_expr, enable).
20
21
22 -export([decode/0]).
23 -import(scran_branch, [alt/1]).
24 -import(scran_bytes, [tag/1]).
25 -import(scran_bytes, [take/1]).
26 -import(scran_combinator, [rest/0]).
27 -import(scran_multi, [many1/1]).
28 -import(scran_result, [into_map/1]).
29 -import(scran_result, [kv/2]).
30 -import(scran_sequence, [preceded/2]).
31 -import(scran_sequence, [sequence/1]).
32 -include_lib("kernel/include/logger.hrl").
33 -on_load(on_load/0).
34
35
36 decode() ->
37 11 fun
38 (<<>>) ->
39 3 {<<>>, #{}};
40
41 (Input) ->
42 6 (variables(
43 alt([flags2(),
44 sql_mode(),
45 catalog_nz(),
46 charset(),
47
48 table_map_for_update(),
49
50 ddl_xid(),
51 default_collation_for_utf8mb4(),
52
53 %% mariadb
54 xid(),
55
56 %% catch all
57 unknown()])))(Input)
58 end.
59
60
61 variables(Parser) ->
62 6 fun
63 (Input) ->
64 6 (into_map(many1(Parser)))(Input)
65 end.
66
67
68 flags2() ->
69 6 fun
70 (Input) ->
71 40 (variable(?FUNCTION_NAME, take(4)))(Input)
72 end.
73
74
75 sql_mode() ->
76 6 fun
77 (Input) ->
78 34 (variable(?FUNCTION_NAME, take(8)))(Input)
79 end.
80
81
82 catalog_nz() ->
83 6 fun
84 (Input) ->
85 28 (variable(?FUNCTION_NAME, take(msmp_integer_fixed:decode(1))))(Input)
86 end.
87
88
89 ddl_xid() ->
90 6 fun
91 (Input) ->
92 15 (variable(?FUNCTION_NAME, msmp_integer_fixed:decode(8)))(Input)
93 end.
94
95 table_map_for_update() ->
96 6 fun
97 (Input) ->
98 16 (variable(?FUNCTION_NAME, msmp_integer_fixed:decode(8)))(Input)
99 end.
100
101
102 default_collation_for_utf8mb4() ->
103 6 fun
104 (Input) ->
105 12 (variable(?FUNCTION_NAME, msmp_integer_fixed:decode(2)))(Input)
106 end.
107
108
109 xid() ->
110 6 fun
111 (Input) ->
112 7 (variable(?FUNCTION_NAME, msmp_integer_fixed:decode(8)))(Input)
113 end.
114
115
116 unknown() ->
117 6 fun
118 (Input) ->
119 6 (kv(?FUNCTION_NAME,
120 into_map(
121 sequence(
122 [kv(type, msmp_integer_fixed:decode(1)),
123 kv(data, rest())]))))(Input)
124 end.
125
126
127 charset() ->
128 6 fun
129 (Input) ->
130 22 (variable(
131 ?FUNCTION_NAME,
132 into_map(
133 sequence(
134 [kv(character_set_client, msmp_integer_fixed:decode(2)),
135 kv(collation_connection, msmp_integer_fixed:decode(2)),
136 kv(collation_server, msmp_integer_fixed:decode(2))]))))(Input)
137 end.
138
139
140 variable(Name, Parser) ->
141 174 fun
142 (Input) ->
143 174 (kv(Name, preceded(type(Name), Parser)))(Input)
144 end.
145
146
147 type(Type) ->
148 174 fun
149 (Input) ->
150 174 (tag(<<(cache(Type)):8>>))(Input)
151 end.
152
153
154 cache(Type) ->
155 174 maps:get(Type, persistent_term:get(?MODULE)).
156
157
158 on_load() ->
159 1 persistent_term:put(
160 ?MODULE,
161 msmp_enum:priv_consult("status-variable-type.terms")).
Line Hits Source