Debian Codegraph @

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

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