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.transport.CloseType; 14 15 import hunt.collection.Collections; 16 import hunt.collection.List; 17 import hunt.proton.amqp.Symbol; 18 import hunt.proton.amqp.UnsignedLong; 19 import hunt.proton.amqp.transport.Close; 20 import hunt.proton.amqp.transport.ErrorCondition; 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.logging; 26 import hunt.collection.ArrayList; 27 import hunt.collection.Collections; 28 import std.concurrency : initOnce; 29 30 class CloseType : AbstractDescribedType!(Close,List!Object) , DescribedTypeConstructor!(Close) 31 { 32 //private static Object[] DESCRIPTORS = 33 //{ 34 // UnsignedLong.valueOf(0x0000000000000018L), Symbol.valueOf("amqp:close:list"), 35 //}; 36 // 37 //private static UnsignedLong DESCRIPTOR = UnsignedLong.valueOf(0x0000000000000018L); 38 39 40 static Object[] DESCRIPTORS() { 41 __gshared Object[] inst; 42 return initOnce!inst([UnsignedLong.valueOf(0x0000000000000018L), Symbol.valueOf("amqp:close:list")]); 43 } 44 45 static UnsignedLong DESCRIPTOR() { 46 __gshared UnsignedLong inst; 47 return initOnce!inst(UnsignedLong.valueOf(0x0000000000000018L)); 48 } 49 50 this(EncoderImpl encoder) 51 { 52 super(encoder); 53 } 54 55 override 56 public UnsignedLong getDescriptor() 57 { 58 return DESCRIPTOR; 59 } 60 61 override 62 protected List!Object wrap(Close val) 63 { 64 ErrorCondition errorCondition = val.getError(); 65 if (errorCondition is null) { 66 return Collections.emptyList!Object(); 67 } else { 68 List!Object rt = new ArrayList!Object; 69 rt.add(errorCondition); 70 return rt; 71 } 72 } 73 74 public Close newInstance(Object described) 75 { 76 List!Object l = cast(List!Object) described; 77 78 Close o = new Close(); 79 80 if(!l.isEmpty()) 81 { 82 o.setError( cast(ErrorCondition) l.get( 0 ) ); 83 } 84 85 return o; 86 } 87 88 public TypeInfo getTypeClass() 89 { 90 return typeid(Close); 91 } 92 93 public static void register(Decoder decoder, EncoderImpl encoder) 94 { 95 CloseType type = new CloseType(encoder); 96 foreach(Object descriptor ; DESCRIPTORS) 97 { 98 decoder.registerDynamic(descriptor, type); 99 } 100 encoder.register(type); 101 } 102 103 } 104