@@ -50,6 +50,8 @@ import dmd.rootobject;
50
50
import dmd.root.utf;
51
51
import dmd.statement;
52
52
import dmd.tokens;
53
+ import dmd.typesem : mutableOf;
54
+ import dmd.utils : arrayCastBigEndian;
53
55
import dmd.visitor;
54
56
55
57
/* ************************************
@@ -7744,44 +7746,3 @@ private void removeHookTraceImpl(ref CallExp ce, ref FuncDeclaration fd)
7744
7746
if (global.params.v.verbose)
7745
7747
message(" strip %s =>\n %s" , oldCE.toChars(), ce.toChars());
7746
7748
}
7747
-
7748
- /**
7749
- * Cast a `ubyte[]` to an array of larger integers as if we are on a big endian architecture
7750
- * Params:
7751
- * data = array with big endian data
7752
- * size = 1 for ubyte[], 2 for ushort[], 4 for uint[], 8 for ulong[]
7753
- * Returns: copy of `data`, with bytes shuffled if compiled for `version(LittleEndian)`
7754
- */
7755
- ubyte [] arrayCastBigEndian (const ubyte [] data, size_t size)
7756
- {
7757
- ubyte [] impl (T)()
7758
- {
7759
- auto result = new T[](data.length / T.sizeof);
7760
- foreach (i; 0 .. result.length)
7761
- {
7762
- result[i] = 0 ;
7763
- foreach (j; 0 .. T.sizeof)
7764
- {
7765
- result[i] |= T(data[i * T.sizeof + j]) << ((T.sizeof - 1 - j) * 8 );
7766
- }
7767
- }
7768
- return cast (ubyte []) result;
7769
- }
7770
- switch (size)
7771
- {
7772
- case 1 : return data.dup ;
7773
- case 2 : return impl! ushort ;
7774
- case 4 : return impl! uint ;
7775
- case 8 : return impl! ulong ;
7776
- default : assert (0 );
7777
- }
7778
- }
7779
-
7780
- unittest
7781
- {
7782
- ubyte [] data = [0xAA , 0xBB , 0xCC , 0xDD , 0xEE , 0xFF , 0x11 , 0x22 ];
7783
- assert (cast (ulong []) arrayCastBigEndian(data, 8 ) == [0xAABBCCDDEEFF1122 ]);
7784
- assert (cast (uint []) arrayCastBigEndian(data, 4 ) == [0xAABBCCDD , 0xEEFF1122 ]);
7785
- assert (cast (ushort []) arrayCastBigEndian(data, 2 ) == [0xAABB , 0xCCDD , 0xEEFF , 0x1122 ]);
7786
- assert (cast (ubyte []) arrayCastBigEndian(data, 1 ) == data);
7787
- }
0 commit comments