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.EndType; 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.End; 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 std.concurrency : initOnce; 26 import hunt.collection.ArrayList; 27 28 class EndType : AbstractDescribedType!(End,List!Object) , DescribedTypeConstructor!(End) 29 { 30 //private static Object[] DESCRIPTORS = 31 //{ 32 // UnsignedLong.valueOf(0x0000000000000017L), Symbol.valueOf("amqp:end:list"), 33 //}; 34 // 35 //private static UnsignedLong DESCRIPTOR = UnsignedLong.valueOf(0x0000000000000017L); 36 37 38 39 static Object[] DESCRIPTORS() { 40 __gshared Object[] inst; 41 return initOnce!inst([UnsignedLong.valueOf(0x0000000000000017L), Symbol.valueOf("amqp:end:list")]); 42 } 43 44 static UnsignedLong DESCRIPTOR() { 45 __gshared UnsignedLong inst; 46 return initOnce!inst(UnsignedLong.valueOf(0x0000000000000017L)); 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 List!Object wrap(End val) 62 { 63 ErrorCondition errorCondition = val.getError(); 64 if (errorCondition !is null) 65 { 66 List!Object rt = new ArrayList!Object; 67 rt.add(errorCondition); 68 return rt; 69 } 70 return null; 71 //return errorCondition is null ? null : Collections.singletonList(errorCondition); 72 } 73 74 75 public End newInstance(Object described) 76 { 77 List!Object l = cast(List!Object) described; 78 79 End o = new End(); 80 81 if(l !is null && !l.isEmpty()) 82 { 83 o.setError( cast(ErrorCondition) l.get( 0 ) ); 84 } 85 86 87 return o; 88 } 89 90 public TypeInfo getTypeClass() 91 { 92 return typeid(End); 93 } 94 95 96 public static void register(Decoder decoder, EncoderImpl encoder) 97 { 98 EndType type = new EndType(encoder); 99 foreach(Object descriptor ; DESCRIPTORS) 100 { 101 decoder.registerDynamic(descriptor, type); 102 } 103 encoder.register(type); 104 } 105 106 }