1 module packetmaker.attributes;
2 
3 import std.system : Endian;
4 import std.traits : isIntegral;
5 
6 import packetmaker.maker : EndianType;
7 
8 import xbuffer.varint : isVar;
9 
10 /**
11  * Excludes the field from both encoding and decoding.
12  */
13 enum Exclude;
14 
15 /**
16  * Excludes the field from decoding, encode only.
17  */
18 enum EncodeOnly;
19 
20 /**
21  * Excludes the field from encoding, decode only.
22  */
23 enum DecodeOnly;
24 
25 /**
26  * Only encode/decode the field when the condition is met.
27  * The condition is placed inside an if statement and can access
28  * the variables and functions of the class/struct (without `this`).
29  * 
30  * This attribute can be used with EncodeOnly and DecodeOnly.
31  */
32 struct Condition { string condition; }
33 
34 /**
35  * Indicates the endianness for the type and its subtypes.
36  */
37 enum BigEndian;
38 
39 /// ditto
40 enum LittleEndian;
41 
42 enum Var;
43 
44 enum Bytes;
45 
46 struct LengthImpl { string type; int endianness; }
47 
48 LengthImpl EndianLength(T)(Endian endianness) if(isIntegral!T) { return LengthImpl(T.stringof, endianness); }
49 
50 template Length(T) if(isIntegral!T) { enum Length = LengthImpl(T.stringof, -1); }
51 
52 template Length(T) if(isVar!T) { enum Length = LengthImpl(T.Base.stringof, EndianType.var); }