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 module hunt.proton.codec.DynamicTypeConstructor;
13 
14 import hunt.proton.codec.TypeConstructor;
15 import hunt.proton.codec.DescribedTypeConstructor;
16 import hunt.logging;
17 import hunt.Exceptions;
18 class DynamicTypeConstructor : ITypeConstructor
19 {
20     private IDescribedTypeConstructor _describedTypeConstructor;
21     private ITypeConstructor _underlyingEncoding;
22 
23     this(IDescribedTypeConstructor dtc,ITypeConstructor underlyingEncoding)
24     {
25         _describedTypeConstructor = dtc;
26         _underlyingEncoding = underlyingEncoding;
27     }
28 
29     public Object readValue()
30     {
31         try
32         {
33             return _describedTypeConstructor.newInstance(_underlyingEncoding.readValue());
34         }
35         catch (NullPointerException npe)
36         {
37            // throw new DecodeException("Unexpected null value - mandatory field not set? ("+npe.getMessage()+")", npe);
38             logError("Unexpected null value");
39         }
40         catch (ClassCastException cce)
41         {
42          //   throw new DecodeException("Incorrect type used", cce);
43             logError("Incorrect type used");
44         }
45         return null;
46     }
47 
48     public bool encodesJavaPrimitive()
49     {
50         return false;
51     }
52 
53     public void skipValue()
54     {
55         _underlyingEncoding.skipValue();
56     }
57 
58     public TypeInfo getTypeClass()
59     {
60 
61         return _describedTypeConstructor.getTypeClass();
62     }
63 }