1 module utils.binary.helpers;
2 
3 import
4 		std.meta,
5 		std.array,
6 		std.range,
7 		std.traits;
8 
9 
10 auto checkAttrs(string[] arr...)
11 {
12 	while(arr.length)
13 	{
14 		switch(arr.front)
15 		{
16 		case `default`, `skip`, `length`, `ignoreif`, `validif`:
17 			arr.popFront;
18 			goto case;
19 
20 		case `rest`, `ubyte`, `ushort`, `uint`:
21 			arr.popFront;
22 			break;
23 
24 		default:
25 			return arr.front;
26 		}
27 	}
28 
29 	return null;
30 }
31 
32 template isDataSimple(T)
33 {
34 	static if(isBasicType!T)
35 	{
36 		enum isDataSimple = true;
37 	}
38 	else static if(isStaticArray!T)
39 	{
40 		enum isDataSimple = isDataSimple!(ElementEncodingType!T);
41 	}
42 	else
43 	{
44 		enum isDataSimple = false;
45 	}
46 }
47 
48 auto StructExecuter(alias _expr, D, S, P, R)(ref D CUR, ref S STRUCT, ref P PARENT, ref R READER)
49 {
50 	with(CUR)
51 	{
52 		return mixin(_expr);
53 	}
54 }
55 
56 @property fieldsToProcess(T)()
57 {
58 	int k, sz;
59 
60 	string u;
61 	string[] res;
62 
63 	void add()
64 	{
65 		if(u.length)
66 		{
67 			res ~= u;
68 			u = null;
69 		}
70 	}
71 
72 	foreach(name; __traits(allMembers, T))
73 	{
74 		static if(__traits(getProtection, __traits(getMember, T, name)) == `public`)
75 		{
76 			alias E = Alias!(__traits(getMember, T, name));
77 
78 			static if(!(is(FunctionTypeOf!E == function) || hasUDA!(E, `ignore`)))
79 			{
80 				static if(is(typeof(E.offsetof)) && isAssignable!(typeof(E)))
81 				{
82 					uint x = E.offsetof, s = E.sizeof;
83 
84 					if(k != x)
85 					{
86 						add;
87 						u = name;
88 
89 						k = x;
90 						sz = s;
91 					}
92 					else if(s > sz)
93 					{
94 						u = name;
95 						sz = s;
96 					}
97 				}
98 				else static if(__traits(compiles, &E) && is(typeof(E) == immutable))
99 				{
100 					add;
101 					res ~= name;
102 				}
103 			}
104 		}
105 	}
106 
107 	add;
108 	return res;
109 }