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