1 module xserial.attribute; 2 3 import std.system : Endian; 4 import std.traits : isIntegral; 5 6 import xbuffer.varint : isVar; 7 8 import xserial.serial : EndianType; 9 10 /** 11 * Excludes the field from both encoding and decoding. 12 */ 13 enum Exclude; 14 15 /** 16 * Includes this even if it would otherwise be excluded. 17 * If Exclude (or other UDA(@)) and Include are present value will be included. 18 * Can also be used on @property methods to include them. (Be sure both the setter and getter exist!) 19 * If used on a value of a base class value will be included. 20 */ 21 enum Include; 22 23 /** 24 * Excludes the field from decoding, encode only. 25 */ 26 enum EncodeOnly; 27 28 /** 29 * Excludes the field from encoding, decode only. 30 */ 31 enum DecodeOnly; 32 33 /** 34 * Only encode/decode the field when the condition is met. 35 * The condition is placed inside an if statement and can access 36 * the variables and functions of the class/struct (without `this`). 37 * 38 * This attribute can be used with EncodeOnly and DecodeOnly. 39 */ 40 struct Condition { string condition; } 41 42 /** 43 * Indicates the endianness for the type and its subtypes. 44 */ 45 enum BigEndian; 46 47 /// ditto 48 enum LittleEndian; 49 50 /** 51 * Encodes and decodes as a Google varint. 52 */ 53 enum Var; 54 55 /** 56 * Indicates that the array has no length. It should only be used 57 * as last field in the class/struct. 58 */ 59 enum NoLength; 60 61 struct LengthImpl { string type; int endianness; } 62 63 template Length(T) if(isIntegral!T) { enum Length = LengthImpl(T.stringof, -1); } 64 65 template Length(T) if(isVar!T) { enum Length = LengthImpl(T.Base.stringof, EndianType.var); } 66 67 LengthImpl EndianLength(T)(Endian endianness) if(isIntegral!T) { return LengthImpl(T.stringof, endianness); } 68 69 struct Custom(T) if(is(T == struct) || is(T == class) || is(T == interface)) { alias C = T; } 70 71 unittest { // for code coverage 72 73 EndianLength!uint(Endian.bigEndian); 74 75 }