-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBinaryWriterBE.cs
50 lines (43 loc) · 1.19 KB
/
BinaryWriterBE.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
using System;
using System.IO;
using System.Text;
public class BinaryWriterBE : BinaryWriter
{
public BinaryWriterBE(Stream stream, Encoding encoding) : base(stream, encoding) { }
public BinaryWriterBE(Stream stream) : base(stream) { }
public override void Write(short value) {
Write((byte) (value >> 8));
Write((byte) value);
}
public override void Write(ushort value) {
Write((byte) (value >> 8));
Write((byte) value);
}
public override void Write(int value) {
Write((byte) (value >> 24));
Write((byte) (value >> 16));
Write((byte) (value >> 8));
Write((byte) (value));
}
public override void Write(uint value) {
Write((byte) (value >> 24));
Write((byte) (value >> 16));
Write((byte) (value >> 8));
Write((byte) (value));
}
public void WriteFixed(double value) {
int i = (int) Math.Truncate(value * 65536.0);
Write(i);
}
public void WriteMacString(string s, int length) {
Encoding macRoman = Encoding.GetEncoding(10000);
byte[] bytes = macRoman.GetBytes(s);
if (bytes.Length > length - 1) {
Write(bytes, 0, length - 1);
Write((byte) 0);
} else {
Write(bytes);
Write(new byte[length - bytes.Length]);
}
}
}