1 /*
2  * Copyright (C) 2018 Julien Viet
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 hunt.database.driver.postgresql.impl.codec.PgCodec;
18 
19 import hunt.database.driver.postgresql.impl.codec.CommandCodec;
20 import hunt.database.driver.postgresql.impl.codec.PgDecoder;
21 import hunt.database.driver.postgresql.impl.codec.PgEncoder;
22 
23 import hunt.database.base.impl.command.CommandBase;
24 import hunt.database.base.impl.command.CommandResponse;
25 
26 import hunt.net.codec.Codec;
27 import hunt.net.codec.Encoder;
28 import hunt.net.codec.Decoder;
29 
30 import std.container.dlist;
31 
32 /**
33 */
34 class PgCodec : Codec { // CombinedChannelDuplexHandler!(PgDecoder, PgEncoder)
35 
36     // private ArrayDeque<CommandCodec<?, ?>> inflight = new ArrayDeque<>();
37     private DList!(CommandCodecBase) inflight;
38     private PgDecoder decoder;
39     private PgEncoder encoder;
40 
41     this() {
42         decoder = new PgDecoder(inflight);
43         encoder = new PgEncoder(decoder, inflight);
44         // init(decoder, encoder);
45     }
46 
47     Encoder getEncoder() {
48         return encoder;
49     }
50 
51     Decoder getDecoder() {
52         return decoder;
53     }
54 
55     // override
56     // void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
57     //     fail(ctx, cause);
58     //     super.exceptionCaught(ctx, cause);
59     // }
60 
61     // private void fail(ChannelHandlerContext ctx, Throwable cause) {
62     //     for  (Iterator<CommandCodec<?, ?>> it = inflight.iterator(); it.hasNext();) {
63     //         CommandCodec<?, ?> codec = it.next();
64     //         it.remove();
65     //         CommandResponse!(Object) failure = CommandResponse.failure(cause);
66     //         failure.cmd = (CommandBase) codec.cmd;
67     //         ctx.fireChannelRead(failure);
68     //     }
69     // }
70 
71     // override
72     // void channelInactive(ChannelHandlerContext ctx) {
73     //     fail(ctx, new VertxException("closed"));
74     //     super.channelInactive(ctx);
75     // }
76 }