Debian Codegraph @

external/cecil/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 using System;
5 using System.IO;
6
7 namespace Microsoft.Cci.Pdb {
8 internal class DataStream {
9 internal DataStream() {
10 }
11
12 internal DataStream(int contentSize, BitAccess bits, int count) {
13 this.contentSize = contentSize;
14 if (count > 0) {
15 this.pages = new int[count];
16 bits.ReadInt32(this.pages);
17 }
18 }
19
20 internal void Read(PdbReader reader, BitAccess bits) {
21 bits.MinCapacity(contentSize);
22 Read(reader, 0, bits.Buffer, 0, contentSize);
23 }
24
25 internal void Read(PdbReader reader, int position,
26 byte[] bytes, int offset, int data) {
27 if (position + data > contentSize) {
28 throw new PdbException("DataStream can't read off end of stream. " +
29 "(pos={0},siz={1})",
30 position, data);
31 }
32 if (position == contentSize) {
33 return;
34 }
35
36 int left = data;
37 int page = position / reader.pageSize;
38 int rema = position % reader.pageSize;
39
40 // First get remained of first page.
41 if (rema != 0) {
42 int todo = reader.pageSize - rema;
43 if (todo > left) {
44 todo = left;
45 }
46
47 reader.Seek(pages[page], rema);
48 reader.Read(bytes, offset, todo);
49
50 offset += todo;
51 left -= todo;
52 page++;
53 }
54
55 // Now get the remaining pages.
56 while (left > 0) {
57 int todo = reader.pageSize;
58 if (todo > left) {
59 todo = left;
60 }
61
62 reader.Seek(pages[page], 0);
63 reader.Read(bytes, offset, todo);
64
65 offset += todo;
66 left -= todo;
67 page++;
68 }
69 }
70
71 //private void AddPages(int page0, int count) {
72 // if (pages == null) {
73 // pages = new int[count];
74 // for (int i = 0; i < count; i++) {
75 // pages[i] = page0 + i;
76 // }
77 // } else {
78 // int[] old = pages;
79 // int used = old.Length;
80
81 // pages = new int[used + count];
82 // Array.Copy(old, pages, used);
83 // for (int i = 0; i < count; i++) {
84 // pages[used + i] = page0 + i;
85 // }
86 // }
87 //}
88
89 //internal int Pages {
90 // get { return pages == null ? 0 : pages.Length; }
91 //}
92
93 internal int Length {
94 get { return contentSize; }
95 }
96
97 //internal int GetPage(int index) {
98 // return pages[index];
99 //}
100
101 internal int contentSize;
102 internal int[] pages;
103 }
104 }