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.ApplicationPropertiesType;
14 
15 import hunt.Object;
16 import hunt.collection.Map;
17 import hunt.proton.amqp.Symbol;
18 import hunt.proton.amqp.UnsignedLong;
19 import hunt.proton.amqp.messaging.ApplicationProperties;
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 import hunt.Exceptions;
25 import std.concurrency : initOnce;
26 import hunt.String;
27 
28 class ApplicationPropertiesType  : AbstractDescribedType!(ApplicationProperties,Map!(String, Object)) , DescribedTypeConstructor!(ApplicationProperties)
29 {
30     //private static Object[] DESCRIPTORS =
31     //{
32     //    UnsignedLong.valueOf(0x0000000000000074L), Symbol.valueOf("amqp:application-properties:map"),
33     //};
34 
35     //private static UnsignedLong DESCRIPTOR = UnsignedLong.valueOf(0x0000000000000074L);
36 
37 
38     static  Object[] DESCRIPTORS() {
39         __gshared  Object[] inst;
40         return initOnce!inst([ UnsignedLong.valueOf(0x0000000000000074L), Symbol.valueOf("amqp:application-properties:map")]);
41     }
42 
43     static UnsignedLong DESCRIPTOR() {
44         __gshared UnsignedLong inst;
45         return initOnce!inst(UnsignedLong.valueOf(0x0000000000000074L));
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  Map!(String, Object) wrap(ApplicationProperties val)
62     {
63         return val.getValue();
64     }
65 
66 
67     public ApplicationProperties newInstance(Object described)
68     {
69         return new ApplicationProperties( cast( Map!(String, Object)) described );
70     }
71 
72     public TypeInfo getTypeClass()
73     {
74         return typeid(ApplicationProperties);
75     }
76 
77       
78 
79     public static void register(Decoder decoder, EncoderImpl encoder)
80     {
81         ApplicationPropertiesType type = new ApplicationPropertiesType(encoder);
82         //implementationMissing(false);
83         foreach(Object descriptor ; DESCRIPTORS)
84         {
85             decoder.registerDynamic(descriptor, type);
86         }
87         encoder.register!ApplicationProperties(type);
88     }
89 }
90