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.impl.Decimal32Element;
13
14
15 import hunt.io.ByteBuffer;
16 import std.conv;
17 import hunt.proton.codec.impl.AtomicElement;
18 import hunt.proton.codec.impl.Element;
19 import hunt.proton.codec.impl.ArrayElement;
20 import hunt.proton.codec.impl.AbstractElement;
21
22 import hunt.proton.amqp.Decimal32;
23 import hunt.proton.codec.Data;
24
25 class Decimal32Element : AtomicElement!Decimal32
26 {
27
28 private Decimal32 _value;
29
30 this(Element!Decimal32 parent, Element!Decimal32 prev, Decimal32 d)
31 {
32 super(parent, prev);
33 _value = d;
34 }
35
36 public int size()
37 {
38 return isElementOfArray() ? 4 : 5;
39 }
40
41 public Decimal32 getValue()
42 {
43 return _value;
44 }
45
46 public Data.DataType getDataType()
47 {
48 return Data.DataType.DECIMAL32;
49 }
50
51 public int encode(ByteBuffer b)
52 {
53 int size = size();
54 if(b.remaining()>=size)
55 {
56 if(size == 5)
57 {
58 b.put(cast(byte)0x74);
59 }
60 b.putInt(_value.getBits());
61 return size;
62 }
63 else
64 {
65 return 0;
66 }
67 }
68 }