| 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_capabilities). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([decode/1]). |
| 20 |
|
-export([encode/1]). |
| 21 |
|
-export_type([combined/0]). |
| 22 |
|
-export_type([lower/0]). |
| 23 |
|
-export_type([upper/0]). |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
-type name() :: lower |
| 27 |
|
| upper |
| 28 |
|
| combined. |
| 29 |
|
|
| 30 |
|
-type lower_name() :: reserved2 |
| 31 |
|
| reserved |
| 32 |
|
| transactions |
| 33 |
|
| ignore_sigpipe |
| 34 |
|
| ssl |
| 35 |
|
| interactive |
| 36 |
|
| protocol_41 |
| 37 |
|
| ignore_space |
| 38 |
|
| local_files |
| 39 |
|
| odbc |
| 40 |
|
| compress |
| 41 |
|
| no_schema |
| 42 |
|
| connect_with_db |
| 43 |
|
| long_flag |
| 44 |
|
| found_rows |
| 45 |
|
| long_password. |
| 46 |
|
|
| 47 |
|
-type lower() :: #{lower_name() := boolean()}. |
| 48 |
|
|
| 49 |
|
-type upper_name() :: remember_options |
| 50 |
|
| ssl_verify_cert |
| 51 |
|
| capability_extension |
| 52 |
|
| mfa |
| 53 |
|
| query_attributes |
| 54 |
|
| zstd_compression |
| 55 |
|
| optional_resultset_metadata |
| 56 |
|
| deprecate_eof |
| 57 |
|
| session_track |
| 58 |
|
| can_handle_expired_passwords |
| 59 |
|
| plugin_auth_lenenc_client_data |
| 60 |
|
| connect_attrs |
| 61 |
|
| plugin_auth |
| 62 |
|
| ps_multi_results |
| 63 |
|
| multi_results |
| 64 |
|
| multi_statements. |
| 65 |
|
|
| 66 |
|
-type upper() :: #{upper_name() := boolean()}. |
| 67 |
|
|
| 68 |
|
-type combined_name() :: lower_name() |
| 69 |
|
| upper_name(). |
| 70 |
|
|
| 71 |
|
-type combined() :: #{combined_name() := boolean()}. |
| 72 |
|
|
| 73 |
|
encode(Name) -> |
| 74 |
10 |
fun |
| 75 |
|
(Flags) -> |
| 76 |
8 |
Names = names(Name), |
| 77 |
8 |
Bits = length(Names), |
| 78 |
8 |
<<Encoded:Bits>> = (narcs_bits:into_bitfield(Flags))(Names), |
| 79 |
8 |
<<Encoded:Bits/little>> |
| 80 |
|
end. |
| 81 |
|
|
| 82 |
|
decode(Name) -> |
| 83 |
28 |
fun |
| 84 |
|
(Input) -> |
| 85 |
27 |
Flags = names(Name), |
| 86 |
27 |
(scran_bytes:bitfield( |
| 87 |
|
Flags, |
| 88 |
|
scran_result:into_bits( |
| 89 |
|
msmp_integer_fixed:decode(length(Flags) div 8), |
| 90 |
|
length(Flags))))(Input) |
| 91 |
|
end. |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
-spec names(name()) -> [lower_name()] | [upper_name()] | [combined_name()]. |
| 95 |
|
|
| 96 |
|
names(combined) -> |
| 97 |
19 |
?FUNCTION_NAME(upper) ++ ?FUNCTION_NAME(lower); |
| 98 |
|
|
| 99 |
|
names(lower) -> |
| 100 |
27 |
[reserved2, |
| 101 |
|
reserved, |
| 102 |
|
transactions, |
| 103 |
|
ignore_sigpipe, |
| 104 |
|
ssl, |
| 105 |
|
interactive, |
| 106 |
|
protocol_41, |
| 107 |
|
ignore_space, |
| 108 |
|
local_files, |
| 109 |
|
odbc, |
| 110 |
|
compress, |
| 111 |
|
no_schema, |
| 112 |
|
connect_with_db, |
| 113 |
|
long_flag, |
| 114 |
|
found_rows, |
| 115 |
|
long_password]; |
| 116 |
|
|
| 117 |
|
names(upper) -> |
| 118 |
27 |
[remember_options, |
| 119 |
|
ssl_verify_cert, |
| 120 |
|
capability_extension, |
| 121 |
|
mfa, |
| 122 |
|
query_attributes, |
| 123 |
|
zstd_compression, |
| 124 |
|
optional_resultset_metadata, |
| 125 |
|
deprecate_eof, |
| 126 |
|
session_track, |
| 127 |
|
can_handle_expired_passwords, |
| 128 |
|
plugin_auth_lenenc_client_data, |
| 129 |
|
connect_attrs, |
| 130 |
|
plugin_auth, |
| 131 |
|
ps_multi_results, |
| 132 |
|
multi_results, |
| 133 |
|
multi_statements]. |