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.impl.NullElement; 13 14 import hunt.io.ByteBuffer; 15 import std.conv; 16 import hunt.proton.codec.impl.AtomicElement; 17 import hunt.proton.codec.impl.Element; 18 import hunt.proton.codec.impl.ArrayElement; 19 import hunt.proton.codec.impl.AbstractElement; 20 21 import hunt.proton.codec.Data; 22 import hunt.Object; 23 24 class NullElement : AtomicElement!Void 25 { 26 this(IElement parent, IElement prev) 27 { 28 super(parent, prev); 29 } 30 31 public int size() 32 { 33 return isElementOfArray() ? 0 : 1; 34 } 35 36 public Object getValue() 37 { 38 return null; 39 } 40 41 public Data.DataType getDataType() 42 { 43 return Data.DataType.NULL; 44 } 45 46 public int encode(ByteBuffer b) 47 { 48 if(b.hasRemaining() && !isElementOfArray()) 49 { 50 b.put(cast(byte)0x40); 51 return 1; 52 } 53 return 0; 54 } 55 }