A game about forced loneliness, made by TACStudios
1/*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
5using System.IO;
6using System.Text;
7
8namespace Microsoft.Unity.VisualStudio.Editor.Messaging
9{
10 internal class Serializer
11 {
12 private readonly MemoryStream _stream;
13 private readonly BinaryWriter _writer;
14
15 public Serializer()
16 {
17 _stream = new MemoryStream();
18 _writer = new BinaryWriter(_stream);
19 }
20
21 public void WriteInt32(int i)
22 {
23 _writer.Write(i);
24 }
25
26 public void WriteString(string s)
27 {
28 var bytes = Encoding.UTF8.GetBytes(s ?? "");
29 if (bytes.Length > 0)
30 {
31 _writer.Write(bytes.Length);
32 _writer.Write(bytes);
33 }
34 else
35 _writer.Write(0);
36 }
37
38 public byte[] Buffer()
39 {
40 return _stream.ToArray();
41 }
42 }
43}