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