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 |
:-( |
init(_, _) -> []. |
28 |
|
|
29 |
|
names() -> |
30 |
:-( |
[bool]. |
31 |
|
|
32 |
:-( |
encode(true, bool, State) -> encode(1, bool, State); |
33 |
:-( |
encode(false, bool, State) -> encode(0, bool, State); |
34 |
:-( |
encode(1, bool, _) -> <<1:1/big-signed-unit:8>>; |
35 |
:-( |
encode(0, bool, _) -> <<0:1/big-signed-unit:8>>. |
36 |
|
|
37 |
:-( |
decode(<<1:1/big-signed-unit:8>>, bool, _) -> true; |
38 |
:-( |
decode(<<0:1/big-signed-unit:8>>, bool, _) -> false. |
39 |
|
|
40 |
:-( |
decode_text(V, _, _) -> V. |