-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBitWriter.String.Extensions.cs
More file actions
40 lines (34 loc) · 1015 Bytes
/
Copy pathBitWriter.String.Extensions.cs
File metadata and controls
40 lines (34 loc) · 1015 Bytes
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
namespace NetCode;
public static class BitWriterStringExtensions
{
public static void Write(this BitWriter writer, string value) => writer.WriteUtf8String(value);
public static void WriteValueIfChanged(this BitWriter writer, string baseline, string updated)
{
if (baseline == updated)
{
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(updated);
}
}
public static void WriteUtf8String(this BitWriter writer, string value)
{
writer.WriteCompressed(value.Length);
for (var i = 0; i < value.Length; i++)
{
var byteValue = Convert.ToByte(value[i]);
writer.Write(byteValue);
}
}
public static void WriteUnicodeString(this BitWriter writer, string value)
{
writer.WriteCompressed(value.Length);
for (var i = 0; i < value.Length; i++)
{
writer.Write(value[i]);
}
}
}