11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4- using System . IO . Compression ;
54
65namespace Kaitai
76{
87 /// <summary>
98 /// The base Kaitai stream which exposes an API for the Kaitai Struct framework.
109 /// It's based off a <code>BinaryReader</code>, which is a little-endian reader.
1110 /// </summary>
12- public partial class KaitaiStream : IKaitaiStream
11+ public partial class KaitaiStream : KaitaiStreamBase , IKaitaiStream
1312 {
1413 #region Constructors
15-
16- static readonly bool IsLittleEndian = BitConverter . IsLittleEndian ;
17-
1814 private ulong Bits ;
1915 private int BitsLeft ;
2016 private BinaryReader m_binaryReader ;
@@ -53,7 +49,7 @@ protected BinaryReader BinaryReader
5349 /// <summary>
5450 /// Check if the stream position is at the end of the stream
5551 /// </summary>
56- public bool IsEof
52+ public override bool IsEof
5753 {
5854 get { return BaseStream . Position >= BaseStream . Length && BitsLeft == 0 ; }
5955 }
@@ -70,15 +66,15 @@ public void Seek(long position)
7066 /// <summary>
7167 /// Get the current position in the stream
7268 /// </summary>
73- public long Pos
69+ public override long Pos
7470 {
7571 get { return BaseStream . Position ; }
7672 }
7773
7874 /// <summary>
7975 /// Get the total length of the stream (ie. file size)
8076 /// </summary>
81- public long Size
77+ public override long Size
8278 {
8379 get { return BaseStream . Length ; }
8480 }
@@ -289,7 +285,7 @@ public double ReadF8le()
289285
290286 #region Unaligned bit values
291287
292- public void AlignToByte ( )
288+ public override void AlignToByte ( )
293289 {
294290 Bits = 0 ;
295291 BitsLeft = 0 ;
@@ -361,11 +357,6 @@ public ulong ReadBitsIntLe(int n)
361357 return res ;
362358 }
363359
364- private static ulong GetMaskOnes ( int n )
365- {
366- return n == 64 ? 0xffffffffffffffffUL : ( 1UL << n ) - 1 ;
367- }
368-
369360 #endregion
370361
371362 #region Byte arrays
@@ -441,7 +432,10 @@ public byte[] ReadBytesFull()
441432 /// <param name="consumeTerminator">True to consume the terminator byte before returning</param>
442433 /// <param name="eosError">True to throw an error when the EOS was reached before the terminator</param>
443434 /// <returns></returns>
444- public byte [ ] ReadBytesTerm ( byte terminator , bool includeTerminator , bool consumeTerminator , bool eosError )
435+ public byte [ ] ReadBytesTerm ( byte terminator ,
436+ bool includeTerminator ,
437+ bool consumeTerminator ,
438+ bool eosError )
445439 {
446440 List < byte > bytes = new List < byte > ( ) ;
447441 while ( true )
@@ -492,112 +486,6 @@ public byte[] EnsureFixedContents(byte[] expected)
492486 return bytes ;
493487 }
494488
495- public static byte [ ] BytesStripRight ( byte [ ] src , byte padByte )
496- {
497- return Utilities . BytesStripRight ( src , padByte ) ;
498- }
499-
500- public static byte [ ] BytesTerminate ( byte [ ] src , byte terminator , bool includeTerminator )
501- {
502- return Utilities . BytesTerminate ( src , terminator , includeTerminator ) ;
503- }
504- #endregion
505-
506- #region Byte array processing
507-
508- /// <summary>
509- /// Performs XOR processing with given data, XORing every byte of the input with a single value.
510- /// </summary>
511- /// <param name="value">The data toe process</param>
512- /// <param name="key">The key value to XOR with</param>
513- /// <returns>Processed data</returns>
514- public byte [ ] ProcessXor ( byte [ ] value , int key )
515- {
516- return Utilities . ProcessXor ( value , key ) ;
517- }
518-
519- /// <summary>
520- /// Performs XOR processing with given data, XORing every byte of the input with a key
521- /// array, repeating from the beginning of the key array if necessary
522- /// </summary>
523- /// <param name="value">The data toe process</param>
524- /// <param name="key">The key array to XOR with</param>
525- /// <returns>Processed data</returns>
526- public byte [ ] ProcessXor ( byte [ ] value , byte [ ] key )
527- {
528- return Utilities . ProcessXor ( value , key ) ;
529- }
530-
531- /// <summary>
532- /// Performs a circular left rotation shift for a given buffer by a given amount of bits.
533- /// Pass a negative amount to rotate right.
534- /// </summary>
535- /// <param name="data">The data to rotate</param>
536- /// <param name="amount">The number of bytes to rotate by</param>
537- /// <param name="groupSize"></param>
538- /// <returns></returns>
539- public byte [ ] ProcessRotateLeft ( byte [ ] data , int amount , int groupSize )
540- {
541- return Utilities . ProcessRotateLeft ( data , amount , groupSize ) ;
542- }
543-
544- /// <summary>
545- /// Inflates a deflated zlib byte stream
546- /// </summary>
547- /// <param name="data">The data to deflate</param>
548- /// <returns>The deflated result</returns>
549- public byte [ ] ProcessZlib ( byte [ ] data )
550- {
551- return Utilities . ProcessZlib ( data ) ;
552- }
553-
554- #endregion
555-
556- #region Misc utility methods
557-
558- /// <summary>
559- /// Performs modulo operation between two integers.
560- /// </summary>
561- /// <remarks>
562- /// This method is required because C# lacks a "true" modulo
563- /// operator, the % operator rather being the "remainder"
564- /// operator. We want mod operations to always be positive.
565- /// </remarks>
566- /// <param name="a">The value to be divided</param>
567- /// <param name="b">The value to divide by. Must be greater than zero.</param>
568- /// <returns>The result of the modulo opertion. Will always be positive.</returns>
569- public static int Mod ( int a , int b )
570- {
571- return Utilities . Mod ( a , b ) ;
572- }
573-
574- /// <summary>
575- /// Performs modulo operation between two integers.
576- /// </summary>
577- /// <remarks>
578- /// This method is required because C# lacks a "true" modulo
579- /// operator, the % operator rather being the "remainder"
580- /// operator. We want mod operations to always be positive.
581- /// </remarks>
582- /// <param name="a">The value to be divided</param>
583- /// <param name="b">The value to divide by. Must be greater than zero.</param>
584- /// <returns>The result of the modulo opertion. Will always be positive.</returns>
585- public static long Mod ( long a , long b )
586- {
587- return Utilities . Mod ( a , b ) ;
588- }
589-
590- /// <summary>
591- /// Compares two byte arrays in lexicographical order.
592- /// </summary>
593- /// <returns>negative number if a is less than b, <c>0</c> if a is equal to b, positive number if a is greater than b.</returns>
594- /// <param name="a">First byte array to compare</param>
595- /// <param name="b">Second byte array to compare.</param>
596- public static int ByteArrayCompare ( byte [ ] a , byte [ ] b )
597- {
598- return Utilities . ByteArrayCompare ( a , b ) ;
599- }
600-
601489 #endregion
602490 }
603491}
0 commit comments