_site/cover/msmp_packet_ok.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_packet_ok).
17
18
19 -feature(maybe_expr, enable).
20
21 -export([decode/1]).
22 -import(scran_bytes, [tag/1]).
23 -import(scran_combinator, [condition/2]).
24 -import(scran_combinator, [condition/3]).
25 -import(scran_combinator, [value/2]).
26 -import(scran_result, [into_map/1]).
27 -import(scran_result, [kv/2]).
28 -import(scran_sequence, [combined_with/2]).
29 -import(scran_sequence, [sequence/1]).
30 -include_lib("kernel/include/logger.hrl").
31
32
33 decode(ClientFlags) ->
34 3 fun
35 (Input) ->
36 3 ?LOG_DEBUG(#{client_flags => ClientFlags, input => Input}),
37
38 3 (combined_with(
39 into_map(
40 sequence(
41 [kv(action, value(ok, tag(<<16#00>>))),
42 kv(affected_rows, msmp_integer_variable:decode()),
43 kv(last_insert_id, msmp_integer_variable:decode()),
44
45 condition(
46 fun
47 () ->
48 3 maps:get(protocol_41, ClientFlags)
49 end,
50 sequence(
51 [kv(status_flags, msmp_server_status:decode()),
52 kv(warnings, msmp_integer_fixed:decode(1))]),
53
54 condition(
55 maps:get(transactions, ClientFlags),
56 kv(status_flags, msmp_server_status:decode())))])),
57 fun
58 (#{status_flags := #{session_state_changed := StateChanged}}) ->
59 3 into_map(
60 sequence(
61 [condition(
62 fun
63 () ->
64 3 maps:get(session_track, ClientFlags)
65 end,
66
67 sequence(
68 [kv(info, msmp_string_length_encoded:decode()),
69 condition(
70 StateChanged,
71 kv(session_state_info, msmp_string_length_encoded:decode()))]),
72
73 sequence(
74 [kv(info, msmp_string_rest_of_packet:decode())]))]))
75 end))(Input)
76 end.
Line Hits Source