Skip to content

Commit 523b8cc

Browse files
author
喵喵大人
authored
Merge pull request #47 from CatLib/feature/1.2.11
Feature/1.2.11
2 parents 56fd221 + afa26f4 commit 523b8cc

File tree

12 files changed

+110
-42
lines changed

12 files changed

+110
-42
lines changed

src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Compile Include="..\CatLib.Core\Support\Util\Enum.cs" Link="Support\Util\Enum.cs" />
122122
<Compile Include="..\CatLib.Core\Support\Util\Extension\IntExtension.cs" Link="Support\Util\Extension\IntExtension.cs" />
123123
<Compile Include="..\CatLib.Core\Support\Util\Extension\StreamExtension.cs" Link="Support\Util\Extension\StreamExtension.cs" />
124+
<Compile Include="..\CatLib.Core\Support\Util\Extension\StringExtension.cs" Link="Support\Util\Extension\StringExtension.cs" />
124125
<Compile Include="..\CatLib.Core\Support\Util\IAwait.cs" Link="Support\Util\IAwait.cs" />
125126
<Compile Include="..\CatLib.Core\Support\Util\Str.cs" Link="Support\Util\Str.cs" />
126127
<Compile Include="..\CatLib.Core\Support\Util\SystemTime.cs" Link="Support\Util\SystemTime.cs" />

src/CatLib.Core.Tests/CatLib.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Support\Util\DictTests.cs" />
6161
<Compile Include="Support\Util\EnumTests.cs" />
6262
<Compile Include="Support\Util\StreamExtensionTests.cs" />
63+
<Compile Include="Support\Util\StringExtensionTests.cs" />
6364
<Compile Include="Support\Util\StrTests.cs" />
6465
<Compile Include="Support\Util\SystemTimeTests.cs" />
6566
<Compile Include="Support\VersionTests.cs" />

src/CatLib.Core.Tests/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]
2727

2828
[assembly: AssemblyVersion("1.2.0.0")]
29-
[assembly: AssemblyFileVersion("1.2.10.0")]
29+
[assembly: AssemblyFileVersion("1.2.11.0")]

src/CatLib.Core.Tests/Support/Stream/PipelineStreamTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public void TestPipeline()
2828
stream = new PipelineStream(256);
2929
ThreadPool.QueueUserWorkItem(WriteThread);
3030

31-
var wrote = false;
32-
stream.OnWrote += (_) =>
31+
var readed = false;
32+
stream.OnRead += (_) =>
3333
{
34-
wrote = true;
34+
readed = true;
3535
};
3636
var data = new byte[100];
3737
int read;
@@ -52,7 +52,7 @@ public void TestPipeline()
5252
}
5353

5454
Assert.AreEqual(expected.ToString(), actual.ToString());
55-
Assert.AreEqual(true, wrote);
55+
Assert.AreEqual(true, readed);
5656
}
5757

5858
public void WriteThread(object obj)
@@ -118,7 +118,6 @@ public void TestSeek()
118118
}
119119

120120
[TestMethod]
121-
[ExpectedException(typeof(NotSupportedException))]
122121
public void TestSetLength()
123122
{
124123
var stream = new PipelineStream(256);
@@ -134,19 +133,17 @@ public void TestSetPosition()
134133
}
135134

136135
[TestMethod]
137-
[ExpectedException(typeof(NotSupportedException))]
138136
public void TestGetPosition()
139137
{
140138
var stream = new PipelineStream(256);
141-
var pos = stream.Position;
139+
Assert.AreEqual(0, stream.Position);
142140
}
143141

144142
[TestMethod]
145-
[ExpectedException(typeof(NotSupportedException))]
146143
public void TestGetLength()
147144
{
148145
var stream = new PipelineStream(256);
149-
var length = stream.Length;
146+
Assert.AreEqual(0, stream.Length);
150147
}
151148
}
152149
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This file is part of the CatLib package.
3+
*
4+
* (c) Yu Bin <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Document: http://catlib.io/
10+
*/
11+
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
13+
14+
namespace CatLib.Core.Tests.Support.Util
15+
{
16+
[TestClass]
17+
public class StringExtensionTests
18+
{
19+
[TestMethod]
20+
public void TestToStream()
21+
{
22+
Assert.AreNotEqual(null, "hello world".ToStream());
23+
}
24+
}
25+
}

src/CatLib.Core/CatLib.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="Support\Util\Arr.cs" />
104104
<Compile Include="Support\Util\Enum.cs" />
105105
<Compile Include="Support\Util\Extension\IntExtension.cs" />
106+
<Compile Include="Support\Util\Extension\StringExtension.cs" />
106107
<Compile Include="Support\Util\IAwait.cs" />
107108
<Compile Include="Support\Util\Str.cs" />
108109
<Compile Include="Support\Util\Extension\StreamExtension.cs" />

src/CatLib.Core/CatLib/Application.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Application : Container, IApplication, IOriginalDispatcher
2323
/// <summary>
2424
/// 版本号
2525
/// </summary>
26-
private readonly Version version = new Version("1.2.10");
26+
private readonly Version version = new Version("1.2.11");
2727

2828
/// <summary>
2929
/// 框架启动流程

src/CatLib.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
[assembly: Guid("4204658e-81fd-4106-a347-890cd369c8a4")]
2828

2929
[assembly: AssemblyVersion("1.2.0.0")]
30-
[assembly: AssemblyFileVersion("1.2.10.0")]
30+
[assembly: AssemblyFileVersion("1.2.11.0")]
3131

3232
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor"),
3333
InternalsVisibleTo("Assembly-CSharp-Editor-firstpass"),

src/CatLib.Core/Support/Stream/PipelineStream.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public class PipelineStream : Stream
4242
private readonly RingBuffer ringBuffer;
4343

4444
/// <summary>
45-
/// 当写入完成后触发
45+
/// 当完成读取后触发
4646
/// </summary>
47-
public event Action<Stream> OnWrote;
47+
public event Action<Stream> OnRead;
4848

4949
/// <summary>
5050
/// 是否已经被释放了
@@ -56,11 +56,6 @@ public class PipelineStream : Stream
5656
/// </summary>
5757
private volatile bool closed;
5858

59-
/// <summary>
60-
/// 总流量
61-
/// </summary>
62-
public long TotalFlow { get; private set; }
63-
6459
/// <summary>
6560
/// 是否可以被读取
6661
/// </summary>
@@ -78,20 +73,30 @@ public override bool CanWrite
7873
}
7974

8075
/// <summary>
81-
/// 偏移位置(不支持)
76+
/// 当前流的位置
77+
/// </summary>
78+
private long position;
79+
80+
/// <summary>
81+
/// 流位置
8282
/// </summary>
8383
public override long Position
8484
{
85-
get { throw new NotSupportedException(); }
85+
get { return position; }
8686
set { throw new NotSupportedException(); }
8787
}
8888

89+
/// <summary>
90+
/// 流的长度
91+
/// </summary>
92+
private long length;
93+
8994
/// <summary>
9095
/// 流的长度
9196
/// </summary>
9297
public override long Length
9398
{
94-
get { throw new NotSupportedException(); }
99+
get { return length; }
95100
}
96101

97102
/// <summary>
@@ -119,7 +124,6 @@ public PipelineStream(int capacity = 4096, int sleep = 1)
119124
{
120125
this.capacity = capacity.ToPrime();
121126
this.sleep = Math.Max(0, sleep);
122-
TotalFlow = 0;
123127
ringBuffer = new RingBuffer(this.capacity, false);
124128
}
125129

@@ -132,7 +136,7 @@ public PipelineStream(int capacity = 4096, int sleep = 1)
132136
}
133137

134138
/// <summary>
135-
/// 偏移位置(不支持)
139+
/// 设定流位置(不支持)
136140
/// </summary>
137141
/// <param name="offset">偏移量</param>
138142
/// <param name="origin">偏移方向</param>
@@ -143,12 +147,12 @@ public override long Seek(long offset, SeekOrigin origin)
143147
}
144148

145149
/// <summary>
146-
/// 设定流的长度(不支持)
150+
/// 设定流的长度
147151
/// </summary>
148152
/// <param name="value">长度</param>
149153
public override void SetLength(long value)
150154
{
151-
throw new NotSupportedException();
155+
length = Math.Max(0, value);
152156
}
153157

154158
/// <summary>
@@ -198,7 +202,13 @@ public override int Read(byte[] buffer, int offset, int count)
198202
{
199203
var read = ringBuffer.Read(buffer, offset, count);
200204
this.count -= read;
201-
TotalFlow += read;
205+
position += read;
206+
207+
if (OnRead != null)
208+
{
209+
OnRead(this);
210+
}
211+
202212
return read;
203213
}
204214
finally
@@ -242,12 +252,6 @@ public override void Write(byte[] buffer, int offset, int count)
242252

243253
Guard.Requires<AssertException>(ringBuffer.Write(buffer, offset, count) == count);
244254
this.count += count;
245-
246-
if (OnWrote != null)
247-
{
248-
OnWrote(this);
249-
}
250-
251255
return;
252256
}
253257
}

src/CatLib.Core/Support/Util/Extension/StreamExtension.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ namespace CatLib
2020
/// </summary>
2121
public static class StreamExtension
2222
{
23-
/// <summary>
24-
/// 编码
25-
/// </summary>
26-
private static Encoding Encoding
27-
{
28-
get { return Encoding.UTF8; }
29-
}
30-
3123
/// <summary>
3224
/// 将当前流追加到目标流中
3325
/// </summary>
@@ -73,7 +65,7 @@ public static string ToText(this Stream source, Encoding encoding = null, bool c
7365
{
7466
try
7567
{
76-
encoding = encoding ?? Encoding;
68+
encoding = encoding ?? Util.Encoding;
7769
if (source is MemoryStream)
7870
{
7971
var memoryStream = (MemoryStream) source;

0 commit comments

Comments
 (0)