-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathSerializingBinaryWriter.cs
35 lines (30 loc) · 1.01 KB
/
SerializingBinaryWriter.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
using System;
using System.IO;
namespace Synercoding.FormsAuthentication.Encryption
{
// Copied from private sub-class in: https://github.com/Microsoft/referencesource/blob/master/System.Web/Security/FormsAuthenticationTicketSerializer.cs
internal sealed class SerializingBinaryWriter : BinaryWriter
{
public SerializingBinaryWriter(Stream output)
: base(output)
{
}
public override void Write(string value)
{
// should never call this method since it will produce wrong results
throw new NotImplementedException();
}
public void WriteBinaryString(string value)
{
byte[] bytes = new byte[value.Length * 2];
for (int i = 0; i < value.Length; i++)
{
char c = value[i];
bytes[2 * i] = (byte)c;
bytes[2 * i + 1] = (byte)(c >> 8);
}
Write7BitEncodedInt(value.Length);
Write(bytes);
}
}
}