1 |
|
%%============================================================================== |
2 |
|
%% Copyright 2018 Erlang Solutions Ltd. |
3 |
|
%% |
4 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
|
%% you may not use this file except in compliance with the License. |
6 |
|
%% You may obtain a copy of the License at |
7 |
|
%% |
8 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
9 |
|
%% |
10 |
|
%% Unless required by applicable law or agreed to in writing, software |
11 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
12 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
|
%% See the License for the specific language governing permissions and |
14 |
|
%% limitations under the License. |
15 |
|
%%============================================================================== |
16 |
|
|
17 |
|
-module(mongoose_rdbms_pgsql_codec_boolean). |
18 |
|
-author('konrad.zemek@erlang-solutions.com'). |
19 |
|
-behaviour(epgsql_codec). |
20 |
|
|
21 |
|
-export([init/2, names/0, encode/3, decode/3, decode_text/3]). |
22 |
|
|
23 |
|
-export_type([data/0]). |
24 |
|
|
25 |
|
-type data() :: boolean() | 0 | 1. |
26 |
|
|
27 |
525 |
init(_, _) -> []. |
28 |
|
|
29 |
|
names() -> |
30 |
525 |
[bool]. |
31 |
|
|
32 |
:-( |
encode(true, bool, State) -> encode(1, bool, State); |
33 |
14 |
encode(false, bool, State) -> encode(0, bool, State); |
34 |
338 |
encode(1, bool, _) -> <<1:1/big-signed-unit:8>>; |
35 |
7997 |
encode(0, bool, _) -> <<0:1/big-signed-unit:8>>. |
36 |
|
|
37 |
214 |
decode(<<1:1/big-signed-unit:8>>, bool, _) -> true; |
38 |
850 |
decode(<<0:1/big-signed-unit:8>>, bool, _) -> false. |
39 |
|
|
40 |
8 |
decode_text(V, _, _) -> V. |