@@ -8,7 +8,7 @@ namespace Kaitai
8
8
{
9
9
/// <summary>
10
10
/// The base Kaitai stream which exposes an API for the Kaitai Struct framework.
11
- /// It's based off a <code >BinaryReader</code >, which is a little-endian reader.
11
+ /// It's based off a <c >BinaryReader</c >, which is a little-endian reader.
12
12
/// </summary>
13
13
public partial class KaitaiStream : BinaryReader
14
14
{
@@ -36,23 +36,26 @@ public KaitaiStream(byte[] data) : base(new MemoryStream(data))
36
36
}
37
37
38
38
/// <summary>
39
- /// Used internally.
39
+ /// Temporary 64-bit buffer for leftover bits left from an unaligned bit
40
+ /// read operation. Following unaligned bit operations would consume bits
41
+ /// left in this buffer first, and then, if needed, would continue
42
+ /// consuming bytes from the stream.
40
43
/// </summary>
41
44
private ulong Bits = 0 ;
42
45
/// <summary>
43
- /// Used internally .
46
+ /// Number of bits left in <c>Bits</c> buffer .
44
47
/// </summary>
45
48
private int BitsLeft = 0 ;
46
49
47
50
/// <summary>
48
- /// Used internally .
49
- /// Caches the current plaftorm endianness and allows emited bytecode to be optimised. Thanks to @Arlorean.
51
+ /// Caches the current platform endianness and allows emitted bytecode to be optimized. Thanks to @Arlorean .
52
+ /// https://github.com/kaitai-io/kaitai_struct_csharp_runtime/pull/9
50
53
/// </summary>
51
54
static readonly bool IsLittleEndian = BitConverter . IsLittleEndian ;
52
55
53
56
static KaitaiStream ( )
54
57
{
55
- compute_single_rotations ( ) ;
58
+ computeSingleRotations ( ) ;
56
59
}
57
60
58
61
#endregion
@@ -518,7 +521,7 @@ public byte[] ProcessXor(byte[] data, byte[] key)
518
521
{
519
522
if ( key . Length == 1 )
520
523
return ProcessXor ( data , key [ 0 ] ) ;
521
- if ( key . Length <= 64 && ByteArrayZero ( key ) )
524
+ if ( key . Length <= 64 && IsByteArrayZero ( key ) )
522
525
return data ;
523
526
524
527
int dl = data . Length ;
@@ -535,14 +538,14 @@ public byte[] ProcessXor(byte[] data, byte[] key)
535
538
/// <summary>
536
539
/// Used internally.
537
540
/// </summary>
538
- private static byte [ ] [ ] precomputed_single_rotations ;
541
+ private static byte [ ] [ ] precomputedSingleRotations ;
539
542
540
543
/// <summary>
541
544
/// Used internally.
542
545
/// </summary>
543
- private static void compute_single_rotations ( )
546
+ private static void computeSingleRotations ( )
544
547
{
545
- precomputed_single_rotations = new byte [ 8 ] [ ] ;
548
+ precomputedSingleRotations = new byte [ 8 ] [ ] ;
546
549
for ( int amount = 1 ; amount < 8 ; amount ++ )
547
550
{
548
551
byte [ ] translate = new byte [ 256 ] ;
@@ -551,7 +554,7 @@ private static void compute_single_rotations()
551
554
// formula taken from: http://stackoverflow.com/a/812039
552
555
translate [ i ] = ( byte ) ( ( i << amount ) | ( i >> ( 8 - amount ) ) ) ;
553
556
}
554
- precomputed_single_rotations [ amount ] = translate ;
557
+ precomputedSingleRotations [ amount ] = translate ;
555
558
}
556
559
}
557
560
@@ -566,7 +569,7 @@ private static void compute_single_rotations()
566
569
public byte [ ] ProcessRotateLeft ( byte [ ] data , int amount , int groupSize )
567
570
{
568
571
if ( groupSize < 1 )
569
- throw new Exception ( "group size must be at least 1 to be valid" ) ;
572
+ throw new ArgumentException ( "group size must be at least 1 to be valid" , "groupSize ") ;
570
573
571
574
amount = Mod ( amount , groupSize * 8 ) ;
572
575
if ( amount == 0 )
@@ -578,7 +581,7 @@ public byte[] ProcessRotateLeft(byte[] data, int amount, int groupSize)
578
581
579
582
if ( groupSize == 1 )
580
583
{
581
- byte [ ] translate = precomputed_single_rotations [ amount ] ;
584
+ byte [ ] translate = precomputedSingleRotations [ amount ] ;
582
585
583
586
for ( int i = 0 ; i < dl ; i ++ )
584
587
{
@@ -751,7 +754,7 @@ public static bool ByteArrayEqual(byte[] a, byte[] b)
751
754
/// <summary>
752
755
/// Check if byte array is all zeroes.
753
756
/// </summary>
754
- public static bool ByteArrayZero ( byte [ ] a )
757
+ public static bool IsByteArrayZero ( byte [ ] a )
755
758
{
756
759
foreach ( byte x in a )
757
760
if ( x != 0 )
0 commit comments