1 module cassandra.internal.utils; 2 3 import std.array : appender; 4 import std.format : formattedWrite; 5 6 string hex(T)(T v) { 7 auto buf = appender!string(); 8 ubyte* ptr = cast(ubyte*)&v; 9 foreach (b; ptr[0..v.sizeof]) { 10 formattedWrite(buf, "%x ", b); 11 } 12 return buf.data; 13 } 14 15 void enforceValidIdentifier(string text) 16 { 17 foreach (ch; text) { 18 switch (ch) { 19 default: throw new Exception("Invalid identifier, '"~text~"'."); 20 case 'a': .. case 'z': 21 case 'A': .. case 'Z': 22 case '0': .. case '9': 23 case '_': 24 break; 25 } 26 } 27 } 28 29 void log(ARGS...)(string format, ARGS args) 30 { 31 version (Have_vibe_core) { 32 import vibe.core.log; 33 logDebug(format, args); 34 } 35 } 36 37 /*void print(ubyte[] data) { 38 import std.ascii; 39 foreach (d1; data) { 40 auto d = cast(char)d1; 41 if (isPrintable(d)) { 42 writef("%c ", d); 43 } else { 44 writef("%2x ", d); 45 } 46 } 47 writeln(); 48 } 49 */ 50 51 52 53 /*ubyte[] toBytes(string[string] sm) { 54 return null; 55 } 56 ubyte[] toBytes(int i) { 57 return null; 58 } 59 /*void write(Socket s, StringMap data) { 60 assert(data.length < short.max); 61 write(s, cast(short)data.length); 62 foreach (k,v; data) { 63 writeln("kv:", k, v); 64 write(s, k); 65 write(s, v); 66 } 67 writeln("wrote StringMap"); 68 } 69 70 /// This implementation even seems to use the compilers implicit casts 71 bool hasUFCSmember(T, string member)() { 72 T v; 73 return __traits(compiles, mixin("v."~ member)); 74 }*/