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