1 module fdb.tuple.tupletype; 2 3 import 4 std.exception, 5 std.uuid; 6 7 static const uint floatSignMask = 0x80_00_00_00U; 8 static const ulong doubleSignMask = 0x80_00_00_00_00_00_00_00UL; 9 static const ulong byteArrayEndMarker = 0xff; 10 11 enum TupleType : ubyte 12 { 13 /** 14 * Null/Empty/Void 15 */ 16 Nil = 0, 17 18 /** 19 * ASCII String 20 */ 21 Bytes = 1, 22 23 /** 24 * UTF-8 String 25 */ 26 Utf8 = 2, 27 28 IntNeg8 = 12, 29 IntNeg7 = 13, 30 IntNeg6 = 14, 31 IntNeg5 = 15, 32 IntNeg4 = 16, 33 IntNeg3 = 17, 34 IntNeg2 = 18, 35 IntNeg1 = 19, 36 37 /** 38 * Base value for integer types (20 +/- n) 39 */ 40 IntBase = 20, 41 IntZero = IntBase, 42 43 IntPos1 = 21, 44 IntPos2 = 22, 45 IntPos3 = 23, 46 IntPos4 = 24, 47 IntPos5 = 25, 48 IntPos6 = 26, 49 IntPos7 = 27, 50 IntPos8 = 28, 51 52 /** 53 * Single precision decimals (32-bit, Big-Endian) [DRAFT] 54 */ 55 Single = 32, 56 57 /** 58 * Double precision decimals (64-bit, Big-Endian) [DRAFT] 59 */ 60 Double = 33, 61 62 /** 63 * RFC4122 UUID (128 bits) [DRAFT] 64 */ 65 Uuid128 = 48, 66 } 67 68 auto FDBsizeof(in TupleType type) pure 69 in 70 { 71 enforce( 72 type == TupleType.Nil || 73 type.isFDBIntegral || 74 type.isFDBFloat || 75 type.isFDBDouble || 76 type.isFDBUUID); 77 } 78 body 79 { 80 if (type == TupleType.Nil) 81 return 0; 82 else if (type.isFDBIntegral) 83 { 84 if (type > TupleType.IntZero) 85 return type - TupleType.IntZero; 86 return TupleType.IntZero - type; 87 } 88 else if (type.isFDBFloat) 89 return float.sizeof; 90 else if (type.isFDBDouble) 91 return double.sizeof; 92 else if (type.isFDBUUID) 93 return UUID.sizeof; 94 95 assert(0, "Type " ~ type ~ " is not supported"); 96 } 97 98 bool isFDBIntegral(in TupleType type) pure @nogc 99 { 100 return type >= TupleType.IntNeg8 && type <= TupleType.IntPos8; 101 } 102 103 bool isFDBFloat(in TupleType type) pure @nogc 104 { 105 return type == TupleType.Single; 106 } 107 108 bool isFDBDouble(in TupleType type) pure @nogc 109 { 110 return type == TupleType.Double; 111 } 112 113 bool isFDBUUID(in TupleType type) pure @nogc 114 { 115 return type == TupleType.Uuid128; 116 } 117 118 unittest 119 { 120 with (TupleType) 121 { 122 assert(IntNeg8.FDBsizeof == 8); 123 assert(IntNeg7.FDBsizeof == 7); 124 assert(IntNeg6.FDBsizeof == 6); 125 assert(IntNeg5.FDBsizeof == 5); 126 assert(IntNeg4.FDBsizeof == 4); 127 assert(IntNeg3.FDBsizeof == 3); 128 assert(IntNeg2.FDBsizeof == 2); 129 assert(IntNeg1.FDBsizeof == 1); 130 131 assert(IntZero.FDBsizeof == 0); 132 133 assert(IntPos1.FDBsizeof == 1); 134 assert(IntPos2.FDBsizeof == 2); 135 assert(IntPos3.FDBsizeof == 3); 136 assert(IntPos4.FDBsizeof == 4); 137 assert(IntPos5.FDBsizeof == 5); 138 assert(IntPos6.FDBsizeof == 6); 139 assert(IntPos7.FDBsizeof == 7); 140 assert(IntPos8.FDBsizeof == 8); 141 } 142 }