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