-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteCollection.cs
128 lines (112 loc) · 3.02 KB
/
ByteCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections;
namespace Be.Windows.Forms
{
/// <summary>
/// Represents a collection of bytes.
/// </summary>
public class ByteCollection : CollectionBase
{
/// <summary>
/// Initializes a new instance of ByteCollection class.
/// </summary>
public ByteCollection()
{}
/// <summary>
/// Initializes a new instance of ByteCollection class.
/// </summary>
/// <param name="bs">an array of bytes to add to collection</param>
public ByteCollection(byte[] bs)
{ AddRange(bs); }
/// <summary>
/// Gets or sets the value of a byte
/// </summary>
public byte this[int index]
{
get { return (byte)List[index]; }
set { List[index] = value; }
}
/// <summary>
/// Adds a byte into the collection.
/// </summary>
/// <param name="b">the byte to add</param>
public void Add(byte b)
{ List.Add(b); }
/// <summary>
/// Adds a range of bytes to the collection.
/// </summary>
/// <param name="bs">the bytes to add</param>
public void AddRange(byte[] bs)
{ InnerList.AddRange(bs); }
/// <summary>
/// Removes a byte from the collection.
/// </summary>
/// <param name="b">the byte to remove</param>
public void Remove(byte b)
{ List.Remove(b); }
/// <summary>
/// Removes a range of bytes from the collection.
/// </summary>
/// <param name="index">the index of the start byte</param>
/// <param name="count">the count of the bytes to remove</param>
public void RemoveRange(int index, int count)
{ InnerList.RemoveRange(index, count); }
/// <summary>
/// Inserts a range of bytes to the collection.
/// </summary>
/// <param name="index">the index of start byte</param>
/// <param name="bs">an array of bytes to insert</param>
public void InsertRange(int index, byte[] bs)
{ InnerList.InsertRange(index, bs); }
/// <summary>
/// Gets all bytes in the array
/// </summary>
/// <returns>an array of bytes.</returns>
public byte[] GetBytes()
{
byte[] bytes = new byte[Count];
InnerList.CopyTo(0, bytes, 0, bytes.Length);
return bytes;
}
/// <summary>
/// Inserts a byte to the collection.
/// </summary>
/// <param name="index">the index</param>
/// <param name="b">a byte to insert</param>
public void Insert(int index, byte b)
{
InnerList.Insert(index, b);
}
/// <summary>
/// Returns the index of the given byte.
/// </summary>
public int IndexOf(byte b)
{
return InnerList.IndexOf(b);
}
/// <summary>
/// Returns true, if the byte exists in the collection.
/// </summary>
public bool Contains(byte b)
{
return InnerList.Contains(b);
}
/// <summary>
/// Copies the content of the collection into the given array.
/// </summary>
public void CopyTo(byte[] bs, int index)
{
InnerList.CopyTo(bs, index);
}
/// <summary>
/// Copies the content of the collection into an array.
/// </summary>
/// <returns>the array containing all bytes.</returns>
public byte[] ToArray()
{
byte[] data = new byte[this.Count];
this.CopyTo(data, 0);
return data;
}
}
}