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.CharElement; 13 14 import hunt.collection.Map; 15 import hunt.io.ByteBuffer; 16 import std.conv; 17 import hunt.proton.codec.impl.AtomicElement; 18 import hunt.proton.codec.impl.Element; 19 import hunt.proton.codec.impl.ArrayElement; 20 import hunt.proton.codec.impl.AbstractElement; 21 22 import hunt.Integer; 23 import hunt.proton.codec.Data; 24 25 class CharElement : AtomicElement!Integer 26 { 27 28 private int _value; 29 30 this(IElement parent, IElement prev, int i) 31 { 32 super(parent, prev); 33 _value = i; 34 } 35 36 public int size() 37 { 38 return isElementOfArray() ? 4 : 5; 39 } 40 41 public Object getValue() 42 { 43 return new Integer( _value); 44 } 45 46 public Data.DataType getDataType() 47 { 48 return Data.DataType.CHAR; 49 } 50 51 public int encode(ByteBuffer b) 52 { 53 int size = size(); 54 if(size <= b.remaining()) 55 { 56 if(size == 5) 57 { 58 b.put(cast(byte)0x73); 59 } 60 b.putInt(_value); 61 } 62 return 0; 63 } 64 }