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.Decimal32Type;
13 
14 /*
15 import hunt.proton.amqp.Decimal32;
16 
17 import hunt.collection.Collection;
18 import hunt.collection.Collections;
19 
20 class Decimal32Type : AbstractPrimitiveType!(Decimal32)
21 {
22     private Decimal32Encoding _decimal32Encoder;
23 
24     Decimal32Type(EncoderImpl encoder, DecoderImpl decoder)
25     {
26         _decimal32Encoder = new Decimal32Encoding(encoder, decoder);
27         encoder.register(Decimal32.class, this);
28         decoder.register(this);
29     }
30 
31     public Class!(Decimal32) getTypeClass()
32     {
33         return Decimal32.class;
34     }
35 
36     public Decimal32Encoding getEncoding(Decimal32 val)
37     {
38         return _decimal32Encoder;
39     }
40 
41 
42     public Decimal32Encoding getCanonicalEncoding()
43     {
44         return _decimal32Encoder;
45     }
46 
47     public Collection!(Decimal32Encoding) getAllEncodings()
48     {
49         return Collections.singleton(_decimal32Encoder);
50     }
51 
52     private class Decimal32Encoding : FixedSizePrimitiveTypeEncoding!(Decimal32)
53     {
54 
55         public Decimal32Encoding(EncoderImpl encoder, DecoderImpl decoder)
56         {
57             super(encoder, decoder);
58         }
59 
60         override
61         protected int getFixedSize()
62         {
63             return 4;
64         }
65 
66         override
67         public byte getEncodingCode()
68         {
69             return EncodingCodes.DECIMAL32;
70         }
71 
72         public Decimal32Type getType()
73         {
74             return Decimal32Type.this;
75         }
76 
77         public void writeValue(Decimal32 val)
78         {
79             getEncoder().writeRaw(val.getBits());
80         }
81 
82         public bool encodesSuperset(TypeEncoding!(Decimal32) encoding)
83         {
84             return (getType() == encoding.getType());
85         }
86 
87         public Decimal32 readValue()
88         {
89             return new Decimal32(getDecoder().readRawInt());
90         }
91     }
92 }
93 */