| 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_binary). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([decode/1]). |
| 20 |
|
-export([encode/1]). |
| 21 |
|
-export([null_bitmap_bytes/2]). |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
null_bitmap_bytes(NumFields, Offset) -> |
| 25 |
347 |
(NumFields + 7 + Offset) div 8. |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
decode(#{type := var_string}) -> |
| 29 |
1 |
msmp_string_length_encoded:decode(); |
| 30 |
|
|
| 31 |
|
decode(#{type := newdecimal}) -> |
| 32 |
1 |
scran_combinator:map_result( |
| 33 |
|
msmp_string_length_encoded:decode(), |
| 34 |
|
fun binary_to_float/1); |
| 35 |
|
|
| 36 |
|
decode(#{type := tiny, flags := #{unsigned := true}}) -> |
| 37 |
:-( |
scran_number:u(little, 8); |
| 38 |
|
|
| 39 |
|
decode(#{type := tiny}) -> |
| 40 |
:-( |
scran_number:i(little, 8); |
| 41 |
|
|
| 42 |
|
decode(#{type := short, flags := #{unsigned := true}}) -> |
| 43 |
:-( |
scran_number:u(little, 16); |
| 44 |
|
|
| 45 |
|
decode(#{type := short}) -> |
| 46 |
:-( |
scran_number:i(little, 16); |
| 47 |
|
|
| 48 |
|
decode(#{type := long, flags := #{unsigned := true}}) -> |
| 49 |
:-( |
scran_number:u(little, 32); |
| 50 |
|
|
| 51 |
|
decode(#{type := long}) -> |
| 52 |
:-( |
scran_number:i(little, 32); |
| 53 |
|
|
| 54 |
|
decode(#{type := longlong, flags := #{unsigned := true}}) -> |
| 55 |
:-( |
scran_number:u(little, 64); |
| 56 |
|
|
| 57 |
|
decode(#{type := longlong}) -> |
| 58 |
:-( |
scran_number:i(little, 64); |
| 59 |
|
|
| 60 |
|
decode(#{type := datetime}) -> |
| 61 |
:-( |
scran_bytes:take(5); |
| 62 |
|
|
| 63 |
|
decode(#{type := float}) -> |
| 64 |
:-( |
scran_number:f(little, 32); |
| 65 |
|
|
| 66 |
|
decode(#{type := double}) -> |
| 67 |
2 |
scran_number:f(little, 64). |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
encode(#{type := tiny, flags := #{unsigned := true}}) -> |
| 71 |
:-( |
narcs_number:u(little, 8); |
| 72 |
|
|
| 73 |
|
encode(#{type := tiny}) -> |
| 74 |
:-( |
narcs_number:i(little, 8); |
| 75 |
|
|
| 76 |
|
encode(#{type := short, flags := #{unsigned := true}}) -> |
| 77 |
:-( |
narcs_number:u(little, 16); |
| 78 |
|
|
| 79 |
|
encode(#{type := short}) -> |
| 80 |
:-( |
narcs_number:i(little, 16); |
| 81 |
|
|
| 82 |
|
encode(#{type := long, flags := #{unsigned := true}}) -> |
| 83 |
:-( |
narcs_number:u(little, 32); |
| 84 |
|
|
| 85 |
|
encode(#{type := long}) -> |
| 86 |
:-( |
narcs_number:i(little, 32); |
| 87 |
|
|
| 88 |
|
encode(#{type := longlong, flags := #{unsigned := true}}) -> |
| 89 |
:-( |
narcs_number:u(little, 64); |
| 90 |
|
|
| 91 |
|
encode(#{type := longlong}) -> |
| 92 |
:-( |
narcs_number:i(little, 64); |
| 93 |
|
|
| 94 |
|
encode(#{type := float}) -> |
| 95 |
:-( |
narcs_number:f(little, 32); |
| 96 |
|
|
| 97 |
|
encode(#{type := double}) -> |
| 98 |
:-( |
narcs_number:f(little, 64). |