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_binlog_dump_gtid). |
17 |
|
|
18 |
|
|
19 |
|
-export([decode/0]). |
20 |
|
-export([encode/0]). |
21 |
|
|
22 |
|
decode() -> |
23 |
3 |
fun |
24 |
|
(Encoded) -> |
25 |
2 |
(scran_result:into_map( |
26 |
|
scran_sequence:sequence( |
27 |
|
[scran_result:kv( |
28 |
|
action, |
29 |
|
scran_combinator:value( |
30 |
|
binlog_dump_gtid, |
31 |
|
scran_bytes:tag(command()))), |
32 |
|
|
33 |
|
scran_result:kv( |
34 |
|
flags, |
35 |
|
msmp_integer_fixed:decode(2)), |
36 |
|
|
37 |
|
scran_result:kv( |
38 |
|
server_id, |
39 |
|
msmp_integer_fixed:decode(4)), |
40 |
|
|
41 |
|
scran_result:kv( |
42 |
|
name, |
43 |
|
scran_bytes:take( |
44 |
|
msmp_integer_fixed:decode(4))), |
45 |
|
|
46 |
|
scran_result:kv( |
47 |
|
position, |
48 |
|
msmp_integer_fixed:decode(8)), |
49 |
|
|
50 |
|
scran_result:kv( |
51 |
|
gtids, |
52 |
|
scran_combinator:map_parser( |
53 |
|
scran_bytes:take( |
54 |
|
msmp_integer_fixed:decode(4)), |
55 |
|
msmp_gtid_set:decode()))])))(Encoded) |
56 |
|
end. |
57 |
|
|
58 |
|
|
59 |
|
encode() -> |
60 |
1 |
fun |
61 |
|
(Decoded) -> |
62 |
2 |
(narcs_sequence:sequence( |
63 |
|
[narcs_bytes:tag(command()), |
64 |
|
narcs_combinator:v(flags, msmp_integer_fixed:encode(2)), |
65 |
|
narcs_combinator:v(server_id, msmp_integer_fixed:encode(4)), |
66 |
|
narcs_combinator:v( |
67 |
|
name, |
68 |
|
narcs_bytes:length_encoded(msmp_integer_fixed:encode(4))), |
69 |
|
narcs_combinator:v(position, msmp_integer_fixed:encode(8)), |
70 |
|
narcs_combinator:v( |
71 |
|
gtids, |
72 |
|
narcs_combinator:map_result( |
73 |
|
msmp_gtid_set:encode(), |
74 |
|
narcs_bytes:length_encoded( |
75 |
|
msmp_integer_fixed:encode(4))))]))(Decoded) |
76 |
|
end. |
77 |
|
|
78 |
|
|
79 |
|
command() -> |
80 |
4 |
<<30>>. |