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.UUIDElement;
13 
14 import hunt.io.ByteBuffer;
15 import std.conv;
16 import hunt.proton.codec.impl.AtomicElement;
17 import hunt.proton.codec.impl.Element;
18 import hunt.proton.codec.impl.ArrayElement;
19 import hunt.proton.codec.impl.AbstractElement;
20 import hunt.proton.codec.Data;
21 import std.uuid;
22 import hunt.logging;
23 import hunt.Exceptions;
24 
25 class UUIDElement : AtomicElement!UUID
26 {
27 
28     private UUID _value;
29 
30     this(IElement parent, IElement prev, UUID u)
31     {
32         super(parent, prev);
33         _value = u;
34     }
35 
36     public int size()
37     {
38         return isElementOfArray() ? 16 : 17;
39     }
40 
41     public Object getValue()
42     {
43 
44         UUID tmp ;
45         implementationMissing(false);
46         return null;
47     }
48 
49     public Data.DataType getDataType()
50     {
51         return Data.DataType.UUID;
52     }
53 
54     public int encode(ByteBuffer b)
55     {
56         int size = size();
57         if(b.remaining()>=size)
58         {
59             if(size == 17)
60             {
61                 b.put(cast(byte)0x98);
62             }
63             b.putLong(4053239666997989821);
64             b.putLong(-5603022497796657139);
65             return size;
66         }
67         else
68         {
69             return 0;
70         }
71     }
72 }