BinaryDataReader.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. using System.Text;
  2. using System.IO;
  3. namespace DragonBones
  4. {
  5. internal class BinaryDataReader : BinaryReader
  6. {
  7. private int i;
  8. private int readLength;
  9. internal BinaryDataReader(Stream stream) : base(stream)
  10. {
  11. }
  12. internal BinaryDataReader(Stream stream, Encoding encoding) : base(stream, encoding)
  13. {
  14. }
  15. public virtual void Seek(int offset, SeekOrigin origin = SeekOrigin.Current)
  16. {
  17. if (offset == 0)
  18. {
  19. return;
  20. }
  21. BaseStream.Seek(offset, origin);
  22. }
  23. public virtual bool[] ReadBooleans(int offset, int readLength)
  24. {
  25. Seek(offset);
  26. this.readLength = readLength;
  27. bool[] flagArray = new bool[this.readLength];
  28. this.i = 0;
  29. while (this.i < this.readLength)
  30. {
  31. flagArray[this.i] = base.ReadBoolean();
  32. this.i++;
  33. }
  34. return flagArray;
  35. }
  36. public virtual byte[] ReadBytes(int offset, int readLength)
  37. {
  38. Seek(offset);
  39. this.readLength = readLength;
  40. byte[] buffer = new byte[this.readLength];
  41. this.i = 0;
  42. while (this.i < this.readLength)
  43. {
  44. buffer[this.i] = base.ReadByte();
  45. this.i++;
  46. }
  47. return buffer;
  48. }
  49. public virtual char[] ReadChars(int offset, int readLength)
  50. {
  51. Seek(offset);
  52. this.readLength = readLength;
  53. char[] chArray = new char[this.readLength];
  54. this.i = 0;
  55. while (this.i < this.readLength)
  56. {
  57. chArray[this.i] = base.ReadChar();
  58. this.i++;
  59. }
  60. return chArray;
  61. }
  62. public virtual decimal[] ReadDecimals(int offset, int readLength)
  63. {
  64. Seek(offset);
  65. this.readLength = readLength;
  66. decimal[] numArray = new decimal[this.readLength];
  67. this.i = 0;
  68. while (this.i < this.readLength)
  69. {
  70. numArray[this.i] = base.ReadDecimal();
  71. this.i++;
  72. }
  73. return numArray;
  74. }
  75. public virtual double[] ReadDoubles(int offset, int readLength)
  76. {
  77. Seek(offset);
  78. this.readLength = readLength;
  79. double[] numArray = new double[this.readLength];
  80. this.i = 0;
  81. while (this.i < this.readLength)
  82. {
  83. numArray[this.i] = base.ReadDouble();
  84. this.i++;
  85. }
  86. return numArray;
  87. }
  88. public virtual short[] ReadInt16s(int offset, int readLength)
  89. {
  90. Seek(offset);
  91. this.readLength = readLength;
  92. short[] numArray = new short[this.readLength];
  93. this.i = 0;
  94. while (this.i < this.readLength)
  95. {
  96. numArray[this.i] = base.ReadInt16();
  97. this.i++;
  98. }
  99. return numArray;
  100. }
  101. public virtual int[] ReadInt32s(int offset, int readLength)
  102. {
  103. Seek(offset);
  104. this.readLength = readLength;
  105. int[] numArray = new int[this.readLength];
  106. this.i = 0;
  107. while (this.i < this.readLength)
  108. {
  109. numArray[this.i] = base.ReadInt32();
  110. this.i++;
  111. }
  112. return numArray;
  113. }
  114. public virtual long[] ReadInt64s(int offset, int readLength)
  115. {
  116. Seek(offset);
  117. this.readLength = readLength;
  118. long[] numArray = new long[this.readLength];
  119. this.i = 0;
  120. while (this.i < this.readLength)
  121. {
  122. numArray[this.i] = base.ReadInt64();
  123. this.i++;
  124. }
  125. return numArray;
  126. }
  127. public virtual sbyte[] ReadSBytes(int offset, int readLength)
  128. {
  129. Seek(offset);
  130. this.readLength = readLength;
  131. sbyte[] numArray = new sbyte[this.readLength];
  132. this.i = 0;
  133. while (this.i < this.readLength)
  134. {
  135. numArray[this.i] = base.ReadSByte();
  136. this.i++;
  137. }
  138. return numArray;
  139. }
  140. public virtual float[] ReadSingles(int offset, int readLength)
  141. {
  142. Seek(offset);
  143. this.readLength = readLength;
  144. float[] numArray = new float[this.readLength];
  145. this.i = 0;
  146. while (this.i < this.readLength)
  147. {
  148. numArray[this.i] = base.ReadSingle();
  149. this.i++;
  150. }
  151. return numArray;
  152. }
  153. public virtual string[] ReadStrings(int offset, int readLength)
  154. {
  155. Seek(offset);
  156. this.readLength = readLength;
  157. string[] strArray = new string[this.readLength];
  158. this.i = 0;
  159. while (this.i < this.readLength)
  160. {
  161. strArray[this.i] = base.ReadString();
  162. this.i++;
  163. }
  164. return strArray;
  165. }
  166. public virtual ushort[] ReadUInt16s(int offset, int readLength)
  167. {
  168. Seek(offset);
  169. this.readLength = readLength;
  170. ushort[] numArray = new ushort[this.readLength];
  171. this.i = 0;
  172. while (this.i < this.readLength)
  173. {
  174. numArray[this.i] = base.ReadUInt16();
  175. this.i++;
  176. }
  177. return numArray;
  178. }
  179. public virtual uint[] ReadUInt32s(int offset, int readLength)
  180. {
  181. Seek(offset);
  182. this.readLength = readLength;
  183. uint[] numArray = new uint[this.readLength];
  184. this.i = 0;
  185. while (this.i < this.readLength)
  186. {
  187. numArray[this.i] = base.ReadUInt32();
  188. this.i++;
  189. }
  190. return numArray;
  191. }
  192. public virtual ulong[] ReadUInt64s(int offset, int readLength)
  193. {
  194. Seek(offset);
  195. this.readLength = readLength;
  196. ulong[] numArray = new ulong[this.readLength];
  197. this.i = 0;
  198. while (this.i < this.readLength)
  199. {
  200. numArray[this.i] = base.ReadUInt64();
  201. this.i++;
  202. }
  203. return numArray;
  204. }
  205. private long Length
  206. {
  207. get
  208. {
  209. return this.BaseStream.Length;
  210. }
  211. }
  212. }
  213. }