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.NullType;
13 
14 import hunt.collection.Collection;
15 import hunt.collection.Collections;
16 
17 import hunt.Nullable;
18 import hunt.proton.codec.AbstractPrimitiveType;
19 import hunt.proton.codec.EncoderImpl;
20 import hunt.proton.codec.DecoderImpl;
21 import hunt.proton.codec.FixedSizePrimitiveTypeEncoding;
22 import hunt.proton.codec.TypeEncoding;
23 import hunt.proton.codec.EncodingCodes;
24 import hunt.Object;
25 import hunt.logging;
26 
27 class Null
28 {
29 
30 }
31 
32 class NullEncoding : FixedSizePrimitiveTypeEncoding!(Null)
33 {
34 
35     this(EncoderImpl encoder, DecoderImpl decoder)
36     {
37         super(encoder, decoder);
38     }
39 
40     override
41     public int getFixedSize()
42     {
43         return 0;
44     }
45 
46     override
47     public byte getEncodingCode()
48     {
49         return EncodingCodes.NULL;
50     }
51 
52     public NullType getType()
53     {
54       //  return this.outer;
55         return null;
56     }
57 
58     public void writeValue(Object val)
59     {
60     }
61 
62     public void writeValue()
63     {
64     }
65 
66     public bool encodesSuperset(TypeEncoding!(Null) encoding)
67     {
68         return encoding == this;
69     }
70 
71     public Object readValue()
72     {
73         return null;
74     }
75 
76     public void write()
77     {
78         writeConstructor();
79     }
80 }
81 
82 class NullType : AbstractPrimitiveType!(Null)
83 {
84     private NullEncoding _nullEncoding;
85 
86     this(EncoderImpl encoder, DecoderImpl decoder)
87     {
88         _nullEncoding = new NullEncoding(encoder, decoder);
89         encoder.register(typeid(Null), this);
90         decoder.register(this);
91     }
92 
93     public TypeInfo getTypeClass()
94     {
95         return typeid(Null);
96     }
97 
98     public ITypeEncoding getEncoding(Object val)
99     {
100         return _nullEncoding;
101     }
102 
103 
104     public NullEncoding getCanonicalEncoding()
105     {
106         return _nullEncoding;
107     }
108 
109     public Collection!(TypeEncoding!Null) getAllEncodings()
110     {
111         return Collections.singleton!(TypeEncoding!Null)(_nullEncoding);
112     }
113 
114     public void write()
115     {
116         _nullEncoding.write();
117     }
118 
119 
120 }