summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs
new file mode 100644
index 00000000..2bae502e
--- /dev/null
+++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/BufferExtension.cs
@@ -0,0 +1,72 @@
+using System;
+using System.IO;
+
+namespace ProtoBuf
+{
+ public sealed class BufferExtension : IExtension
+ {
+ private byte[] buffer;
+
+ int IExtension.GetLength()
+ {
+ return (this.buffer == null) ? 0 : this.buffer.Length;
+ }
+
+ Stream IExtension.BeginAppend()
+ {
+ return new MemoryStream();
+ }
+
+ void IExtension.EndAppend(Stream stream, bool commit)
+ {
+ try
+ {
+ int num = 0;
+ bool flag = commit && (num = (int)stream.Length) > 0;
+ if (flag)
+ {
+ MemoryStream memoryStream = (MemoryStream)stream;
+ bool flag2 = this.buffer == null;
+ if (flag2)
+ {
+ this.buffer = memoryStream.ToArray();
+ }
+ else
+ {
+ int num2 = this.buffer.Length;
+ byte[] to = new byte[num2 + num];
+ Helpers.BlockCopy(this.buffer, 0, to, 0, num2);
+ Helpers.BlockCopy(memoryStream.GetBuffer(), 0, to, num2, num);
+ this.buffer = to;
+ }
+ }
+ }
+ finally
+ {
+ if (stream != null)
+ {
+ ((IDisposable)stream).Dispose();
+ }
+ }
+ }
+
+ Stream IExtension.BeginQuery()
+ {
+ return (this.buffer == null) ? Stream.Null : new MemoryStream(this.buffer);
+ }
+
+ void IExtension.EndQuery(Stream stream)
+ {
+ try
+ {
+ }
+ finally
+ {
+ if (stream != null)
+ {
+ ((IDisposable)stream).Dispose();
+ }
+ }
+ }
+ }
+}