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.Data;
13 
14 import hunt.io.ByteBuffer;
15 import hunt.time.LocalDateTime;
16 import hunt.collection.List;
17 import hunt.collection.Map;
18 import std.uuid;
19 import hunt.proton.amqp.Binary;
20 import hunt.proton.amqp.Decimal128;
21 import hunt.proton.amqp.Decimal32;
22 import hunt.proton.amqp.Decimal64;
23 import hunt.proton.amqp.DescribedType;
24 import hunt.proton.amqp.Symbol;
25 import hunt.proton.amqp.UnsignedByte;
26 import hunt.proton.amqp.UnsignedInteger;
27 import hunt.proton.amqp.UnsignedLong;
28 import hunt.proton.amqp.UnsignedShort;
29 
30 import hunt.proton.codec.impl.DataImpl;
31 import hunt.Long;
32 import hunt.String;
33 import hunt.Byte;
34 import hunt.Short;
35 import hunt.Double;
36 import hunt.Integer;
37 import hunt.Float;
38 import hunt.Boolean;
39 
40 interface Data
41 {
42 
43     class Factory {
44 
45         static Data create() {
46             return new DataImpl();
47         }
48 
49     }
50 
51 
52     enum DataType
53     {
54         NULL,
55         BOOL,
56         UBYTE,
57         BYTE,
58         USHORT,
59         SHORT,
60         UINT,
61         INT,
62         CHAR,
63         ULONG,
64         LONG,
65         TIMESTAMP,
66         FLOAT,
67         DOUBLE,
68         DECIMAL32,
69         DECIMAL64,
70         DECIMAL128,
71         UUID,
72         BINARY,
73         STRING,
74         SYMBOL,
75         DESCRIBED,
76         ARRAY,
77         LIST,
78         MAP
79     }
80 
81     void free();
82 
83     void clear();
84     long size();
85     void rewind();
86     DataType next();
87     DataType prev();
88     bool enter();
89     bool exit();
90 
91     DataType type();
92 
93     Binary encode();
94     long encodedSize();
95     long encode(ByteBuffer buf);
96     long decode(ByteBuffer buf);
97 
98     void putList();
99     void putMap();
100     void putArray(bool described, DataType type);
101     void putDescribed();
102     void putNull();
103     void putBoolean(bool b);
104     void putUnsignedByte(UnsignedByte ub);
105     void putByte(byte b);
106     void putUnsignedShort(UnsignedShort us);
107     void putShort(short s);
108     void putUnsignedInteger(UnsignedInteger ui);
109     void putInt(int i);
110     void putChar(int c);
111     void putUnsignedLong(UnsignedLong ul);
112     void putLong(long l);
113     void putTimestamp(hunt.time.LocalDateTime.LocalDateTime t);
114     void putFloat(float f);
115     void putDouble(double d);
116     void putDecimal32(Decimal32 d);
117     void putDecimal64(Decimal64 d);
118     void putDecimal128(Decimal128 d);
119     void putUUID(UUID u);
120     void putBinary(Binary bytes);
121     void putBinary(byte[] bytes);
122     void putString(string str);
123     void putSymbol(Symbol symbol);
124     void putObject(Object o);
125     void putJavaMap(Map!(Object, Object) map);
126     void putJavaList(List!(Object) list);
127     void putDescribedType(DescribedType dt);
128 
129     long getList();
130     long getMap();
131     long getArray();
132     bool isArrayDescribed();
133     DataType getArrayType();
134     bool isDescribed();
135     bool isNull();
136     Boolean getBoolean();
137     UnsignedByte getUnsignedByte();
138     Byte getByte();
139     UnsignedShort getUnsignedShort();
140     Short getShort();
141     UnsignedInteger getUnsignedInteger();
142     Integer getInt();
143     Integer getChar();
144     UnsignedLong getUnsignedLong();
145     Long getLong();
146     hunt.time.LocalDateTime.LocalDateTime getTimestamp();
147     Float getFloat();
148     Double getDouble();
149     Decimal32 getDecimal32();
150     Decimal64 getDecimal64();
151     Decimal128 getDecimal128();
152     UUID getUUID();
153     Binary getBinary();
154     String getString();
155     Symbol getSymbol();
156     Object getObject();
157     Map!(Object, Object) getJavaMap();
158     List!(Object) getJavaList();
159     List!(Object) getJavaArray();
160     DescribedType getDescribedType();
161 
162     string format();
163 }