blob: 2bae502e7f305d0b7494db9ffa122c5ec8140e4b (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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();
}
}
}
}
}
|