1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.proton.codec.AbstractPrimitiveTypeEncoding;
13 
14 import hunt.proton.codec.PrimitiveTypeEncoding;
15 import hunt.proton.codec.EncoderImpl;
16 import hunt.proton.codec.DecoderImpl;
17 import hunt.proton.codec.TypeEncoding;
18 import hunt.logging;
19 
20 abstract class AbstractPrimitiveTypeEncoding(T) : PrimitiveTypeEncoding!(T)
21 {
22     private EncoderImpl _encoder;
23     private DecoderImpl _decoder;
24 
25     this(EncoderImpl encoder, DecoderImpl decoder)
26     {
27         _encoder = encoder;
28         _decoder = decoder;
29     }
30 
31     public void writeConstructor()
32     {
33         _encoder.writeRaw(getEncodingCode());
34     }
35 
36     public int getConstructorSize()
37     {
38         return 1;
39     }
40 
41     public abstract byte getEncodingCode();
42 
43     protected EncoderImpl getEncoder()
44     {
45         return _encoder;
46     }
47 
48     public TypeInfo getTypeClass()
49     {
50         return getType().getTypeClass();
51     }
52 
53     protected DecoderImpl getDecoder()
54     {
55         return _decoder;
56     }
57 
58 
59     public bool encodesJavaPrimitive()
60     {
61         return false;
62     }
63 
64     override
65     int opCmp(ITypeEncoding o)
66     {
67         return 1;
68     }
69 
70 }