1 module cerealed.attrs; 2 3 4 import std.typetuple; 5 6 7 template getNumBits(T) { 8 static if(is(T:Bits!N, int N)) { 9 enum getNumBits = N; 10 } else { 11 enum getNumBits = 0; 12 } 13 } 14 15 16 enum isABitsStruct(alias T) = is(T) && is(T:Bits!N, int N); 17 18 19 struct Bits(int N) if(N > 0 && N <= 32) { 20 } 21 22 /** 23 Exclude this member from serialization 24 */ 25 enum NoCereal; 26 27 28 /** 29 Do not encode array length before the array. 30 This consumes the remaining bytes when deserializing 31 */ 32 enum RawArray; 33 alias RestOfPacket = RawArray; 34 alias Rest = RawArray; 35 36 37 /** 38 Inform the library about which member variable contains 39 the length for an array measured in number of elements, not bytes 40 */ 41 struct ArrayLength { 42 string member; 43 } 44 45 46 enum isArrayLengthStruct(alias T) = is(typeof(T)) && is(typeof(T) == ArrayLength); 47 48 unittest { 49 auto l = ArrayLength(); 50 static assert(isArrayLengthStruct!l); 51 } 52 53 /** 54 Specifies the length of an array by the number of bytes, not elements 55 */ 56 struct LengthInBytes { 57 string member; 58 } 59 60 61 enum isLengthInBytesStruct(alias T) = is(typeof(T)) && is(typeof(T) == LengthInBytes); 62 63 unittest { 64 auto l = LengthInBytes(); 65 static assert(isLengthInBytesStruct!l); 66 } 67 68 69 struct LengthType(T) { 70 alias Type = T; 71 } 72 enum isLengthType(alias T) = is(T) && is(T:LengthType!U, U); 73 74 unittest { 75 static assert(isLengthType!(LengthType!ushort)); 76 }