本文整理汇总了C#中CircularBuffer.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.GetString方法的具体用法?C# CircularBuffer.GetString怎么用?C# CircularBuffer.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CircularBufferExt_DecoderConvert3_CircularFull2
public void CircularBufferExt_DecoderConvert3_CircularFull2()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] b = new byte[] {
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
CircularBuffer<byte> cb = new CircularBuffer<byte>(b, 16, b.Length);
char[] c = new char[30];
CircularBuffer<char> cc = new CircularBuffer<char>(c, 28, 0);
int bu;
int cu;
bool complete;
d.Convert(cb, cc, false, out bu, out cu, out complete);
Assert.IsTrue(complete);
Assert.AreEqual(b.Length, bu);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(28, cu);
Assert.AreEqual("OPQRSTUVWXYZ€@ABCDEFGHIJKLMN", cc.GetString());
}
示例2: CircularBufferExt_DecoderConvert2_Utf16Chars1b
public void CircularBufferExt_DecoderConvert2_Utf16Chars1b()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x82, 0x84, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xF3, 0xA0
};
char[] c = new char[30];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, 16);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 17, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_Utf16Chars1"
// - We force the 2 chars to wrap
d.Convert(cb, cc, 14, true, out bu, out cu, out complete);
Assert.IsTrue(complete);
Assert.AreEqual(16, bu);
Assert.AreEqual(14, cu);
Assert.AreEqual("OPQRSTUVWXYZ\uDB40\uDC84", cc.GetString());
Assert.AreEqual(0, cb.Length);
}
示例3: CircularBufferExt_DecoderConvert2_Utf16Chars2
public void CircularBufferExt_DecoderConvert2_Utf16Chars2()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x82, 0x84, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xF3, 0xA0
};
char[] c = new char[30];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, 16);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_Utf16Chars2"
d.Convert(cb, cc, 13, false, out bu, out cu, out complete);
Assert.IsFalse(complete);
//Assert.AreEqual(12, bu);
Assert.AreEqual(12, cu);
Assert.AreEqual("OPQRSTUVWXYZ", cc.GetString());
//Assert.AreEqual(4, cb.Length);
// This particular test is hard. The decoder consumes 12 bytes, but our function
// consumes more (because the 4-bytes cross a boundary). The decoder needs to see
// all four bytes to decide not to convert it. There is nothing in the documentation
// to say that the decoder should behave this way. So we can't simulate the original
// behaviour in this case.
}
示例4: CircularBufferExt_DecoderConvert2_MultiChar1
public void CircularBufferExt_DecoderConvert2_MultiChar1()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] b = new byte[] {
0xF3, 0xA0, 0x82, 0x84, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41,
0x42, 0x43, 0x44, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55
};
CircularBuffer<byte> cb = new CircularBuffer<byte>(b, 0, b.Length);
char[] c = new char[30];
CircularBuffer<char> cc = new CircularBuffer<char>(c, 29, 0);
int bu;
int cu;
bool complete;
d.Convert(cb, cc, cc.Capacity, false, out bu, out cu, out complete);
//Assert.IsFalse(complete);
Assert.AreEqual(30, cu);
Assert.AreEqual(32, bu);
Assert.AreEqual(0, cc.Free);
Assert.AreEqual("\uDB40\[email protected]", cc.GetString());
}
示例5: CircularBufferExt_DecoderConvert2_MultiChar2
public void CircularBufferExt_DecoderConvert2_MultiChar2()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] b = new byte[] {
0xF3, 0xA0, 0x82, 0x84, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41,
0x42, 0x43, 0x44, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55
};
CircularBuffer<byte> cb = new CircularBuffer<byte>(b, 4, b.Length);
char[] c = new char[29];
CircularBuffer<char> cc = new CircularBuffer<char>(c, 0, 0);
int bu;
int cu;
bool complete;
d.Convert(cb, cc, cc.Capacity, false, out bu, out cu, out complete);
// The character buffer doesn't contain enough space to capture the last two-byte character. Just like
// the real decoder, it should capture as much as possible and return without an error.
Assert.IsFalse(complete);
Assert.AreEqual(28, cu);
Assert.AreEqual(28, bu);
Assert.AreEqual(1, cc.Free);
Assert.AreEqual("[email protected]", cc.GetString());
// There are no bytes to convert, an exception should be raised like the real decoder in a char[].
try {
d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
} catch (System.ArgumentException e) {
if (!e.ParamName.Equals("chars")) throw;
}
}
示例6: CircularBufferExt_DecoderConvert2_IncompleteBuffFlush2
public void CircularBufferExt_DecoderConvert2_IncompleteBuffFlush2()
{
Encoding enc = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback("."), new DecoderReplacementFallback("."));
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
char[] c = new char[30];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, 14);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_IncompleteBuffFlush2"
d.Convert(cb, cc, 12, true, out bu, out cu, out complete);
Assert.IsFalse(complete);
Assert.AreEqual(12, bu);
Assert.AreEqual(12, cu);
Assert.AreEqual("OPQRSTUVWXYZ", cc.GetString());
Assert.AreEqual(2, cb.Length);
}
示例7: CircularBufferExt_DecoderConvert2_InsufficientCharSpaceMbcs1
public void CircularBufferExt_DecoderConvert2_InsufficientCharSpaceMbcs1()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
char[] c = new char[13];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, m.Length);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_InsufficientCharSpaceMbcs1"
d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
Assert.IsFalse(complete);
Assert.AreEqual(15, bu);
Assert.AreEqual(cc.Capacity, cu);
Assert.AreEqual("OPQRSTUVWXYZ€", cc.GetString());
}
示例8: CircularBufferExt_DecoderConvert2_BoundariesFlush
public void CircularBufferExt_DecoderConvert2_BoundariesFlush()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
char[] c = new char[28];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, m.Length);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_Boundaries"
d.Convert(cb, cc, cc.Free, true, out bu, out cu, out complete);
Assert.IsTrue(complete);
Assert.AreEqual(m.Length, bu);
Assert.AreEqual(cc.Capacity, cu);
Assert.AreEqual("OPQRSTUVWXYZ€@ABCDEFGHIJKLMN", cc.GetString());
}
示例9: CircularBufferExt_DecoderConvert2_IncompleteBuff
public void CircularBufferExt_DecoderConvert2_IncompleteBuff()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
char[] c = new char[30];
CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, 13);
CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_IncompleteBuff"
d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
Assert.IsTrue(complete);
Assert.AreEqual(13, bu);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(12, cu);
Assert.AreEqual("OPQRSTUVWXYZ", cc.GetString());
cc.Consume(cu);
cb.Produce(17);
d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
Assert.IsTrue(complete);
Assert.AreEqual(17, bu);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(16, cu);
Assert.AreEqual("€@ABCDEFGHIJKLMN", cc.GetString());
}
示例10: CircularBuffer_AppendArray
public void CircularBuffer_AppendArray()
{
CircularBuffer<char> cb = new CircularBuffer<char>(20);
cb.Produce(10);
cb.Consume(9);
Assert.AreEqual(1, cb.Length);
Assert.AreEqual(19, cb.Free);
cb.Append("ABCDEFGHIJKLMN".ToCharArray(), 0, 14);
Assert.AreEqual(15, cb.Length);
Assert.AreEqual(5, cb.Free);
Assert.AreEqual("ABCDEFGHIJKLMN", cb.GetString(1, 14));
cb.Consume(15);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(20, cb.Free);
cb.Append("12345678901234567890".ToCharArray());
Assert.AreEqual(0, cb.Free);
Assert.AreEqual(20, cb.Length);
Assert.AreEqual("12345678901234567890", cb.GetString());
}
示例11: CircularBuffer_AppendBuffer
public void CircularBuffer_AppendBuffer()
{
CircularBuffer<char> cb1 = new CircularBuffer<char>(20);
CircularBuffer<char> cb2 = new CircularBuffer<char>(20);
// Read is one chunk, write is one chunk
cb2.Produce(3);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(3);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is one chunk, but read is two chunks
cb1.Reset();
cb2.Reset();
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is one chunk
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Append("123456789012345".ToCharArray());
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength < writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength > writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(7);
cb2.Consume(6);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
}
示例12: CircularBufferExt_GetStringSimple
public void CircularBufferExt_GetStringSimple()
{
CircularBuffer<char> cb = new CircularBuffer<char>(15);
for (int i = 0; i < cb.Capacity; i++) {
cb.Array[i] = (char)((int)'A' + i);
}
cb.Produce(10);
Assert.AreEqual("ABCDEFGHIJ", cb.GetString());
cb.Consume(5);
Assert.AreEqual("FGHIJ", cb.GetString());
cb.Produce(8);
Assert.AreEqual("FGHIJKLMNOABC", cb.GetString());
cb.Consume(13);
Assert.AreEqual("", cb.GetString());
cb = null;
Assert.IsNull(cb.GetString());
}
示例13: CircularBufferExt_GetStringOffsetLength
public void CircularBufferExt_GetStringOffsetLength()
{
CircularBuffer<char> cb = new CircularBuffer<char>(15);
for (int i = 0; i < cb.Capacity; i++) {
cb.Array[i] = (char)((int)'A' + i);
}
cb.Produce(10);
Assert.AreEqual("ABCDEFGHIJ", cb.GetString(0, 10));
Assert.AreEqual("ABCDEFGHIJ", cb.GetString(0, 20));
Assert.AreEqual("", cb.GetString(0, 0));
Assert.AreEqual("FGHIJ", cb.GetString(5, 5));
Assert.AreEqual("BCDEFGHIJ", cb.GetString(1, 9));
Assert.AreEqual("BCDEFGH", cb.GetString(1, 7));
Assert.AreEqual("", cb.GetString(5, 0));
cb.Consume(5);
Assert.AreEqual("FGHIJ", cb.GetString(0, 10));
Assert.AreEqual("FGHIJ", cb.GetString(0, 5));
Assert.AreEqual("HIJ", cb.GetString(2, 3));
Assert.AreEqual("", cb.GetString(5, 0));
Assert.AreEqual("", cb.GetString(5, 1));
cb.Produce(8);
Assert.AreEqual("FGHIJKLMNOABC", cb.GetString(0, 13));
Assert.AreEqual("FGHIJ", cb.GetString(0, 5));
Assert.AreEqual("KLMNOABC", cb.GetString(5, 13));
Assert.AreEqual("KLMNOABC", cb.GetString(5, 8));
Assert.AreEqual("KLMNO", cb.GetString(5, 5));
Assert.AreEqual("ABC", cb.GetString(10, 3));
cb.Consume(13);
Assert.AreEqual("", cb.GetString(0, 0));
Assert.AreEqual("", cb.GetString(5, 15));
Assert.AreEqual("", cb.GetString(10, 20));
Assert.AreEqual("", cb.GetString(10, 1));
cb = null;
Assert.IsNull(cb.GetString(0, 5));
Assert.IsNull(cb.GetString(10, 0));
Assert.IsNull(cb.GetString(5, 15));
Assert.IsNull(cb.GetString(2, 20));
}
示例14: CircularBufferExt_DecoderConvert4_Utf16Chars2
public void CircularBufferExt_DecoderConvert4_Utf16Chars2()
{
Encoding enc = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback("."), new DecoderReplacementFallback("."));
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xF3, 0xA0, 0x82, 0x84,
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
};
char[] c = new char[13];
CircularBuffer<char> cc = new CircularBuffer<char>(c, 11, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_Utf16Chars2"
d.Convert(m, 0, 16, cc, false, out bu, out cu, out complete);
Assert.IsFalse(complete);
Assert.AreEqual(12, bu);
Assert.AreEqual(12, cu);
Assert.AreEqual(12, cc.Length);
Assert.AreEqual("OPQRSTUVWXYZ", cc.GetString());
}
示例15: CircularBufferExt_DecoderConvert4_InsufficientCharSpaceFlush
public void CircularBufferExt_DecoderConvert4_InsufficientCharSpaceFlush()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82,
0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
};
char[] c = new char[20];
CircularBuffer<char> cc = new CircularBuffer<char>(c, 15, 0);
int bu;
int cu;
bool complete;
// Based on the test "Decoder_InsufficientCharSpaceFlush"
d.Convert(m, 0, m.Length, cc, true, out bu, out cu, out complete);
Assert.IsFalse(complete);
Assert.AreEqual(22, bu);
Assert.AreEqual(20, cu);
Assert.AreEqual(20, cc.Length);
Assert.AreEqual("OPQRSTUVWXYZ€@ABCDEF", cc.GetString());
}