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 
13 module hunt.proton.codec.messaging.DataType;
14 
15 
16 import hunt.proton.amqp.Binary;
17 import hunt.proton.amqp.Symbol;
18 import hunt.proton.amqp.UnsignedLong;
19 import hunt.proton.amqp.messaging.Data;
20 import hunt.proton.codec.AbstractDescribedType;
21 import hunt.proton.codec.Decoder;
22 import hunt.proton.codec.DescribedTypeConstructor;
23 import hunt.proton.codec.EncoderImpl;
24 
25 import hunt.Exceptions;
26 import std.concurrency : initOnce;
27 
28 class DataType : AbstractDescribedType!(Data,Binary) , DescribedTypeConstructor!(Data)
29 {
30     //private static Object[] DESCRIPTORS =
31     //{
32     //    UnsignedLong.valueOf(0x0000000000000075L), Symbol.valueOf("amqp:data:binary"),
33     //};
34 
35     //private static UnsignedLong DESCRIPTOR = UnsignedLong.valueOf(0x0000000000000075L);
36 
37     static Object[] DESCRIPTORS() {
38         __gshared Object[] inst;
39         return initOnce!inst([ UnsignedLong.valueOf(0x0000000000000075L), Symbol.valueOf("amqp:data:binary")]);
40     }
41 
42 
43     static UnsignedLong DESCRIPTOR() {
44         __gshared UnsignedLong inst;
45         return initOnce!inst(UnsignedLong.valueOf(0x0000000000000075L));
46     }
47 
48 
49     this(EncoderImpl encoder)
50     {
51         super(encoder);
52     }
53 
54     override
55     public UnsignedLong getDescriptor()
56     {
57         return DESCRIPTOR;
58     }
59 
60     override
61     protected Binary wrap(Data val)
62     {
63         return val.getValue();
64     }
65 
66     public Data newInstance(Object described)
67     {
68         return new Data( cast(Binary) described );
69     }
70 
71     public TypeInfo getTypeClass()
72     {
73         return typeid(Data);
74     }
75 
76 
77 
78     public static void register(Decoder decoder, EncoderImpl encoder)
79     {
80         DataType type = new DataType(encoder);
81        // implementationMissing(false);
82         foreach(Object descriptor ; DESCRIPTORS)
83         {
84             decoder.registerDynamic(descriptor, type);
85         }
86         encoder.register(type);
87     }
88 }