字节集基于类似与ByteBuffer的从Java [英] byte collection based similar with ByteBuffer from java
问题描述
我需要用的ByteBuffer从Java类似一个C#实现。感兴趣
方法 - .remaining() - 返回的当前位置和限制之间的元素的数量。
- .array()
- .clear()
- 。把(字节[],INT,INT)
I need a C# implementation of something similar with ByteBuffer from Java. Methods of interest - .remaining() - returns the number of elements between the current position and the limit. - .array() - .clear() - .put(byte[], int, int)
我开始一些与的MemoryStream
..但没有清()
,很多即兴
的同时,我在Koders发现C#实现: http://www.koders.com/csharp/fid2F8CB1B540E646746D3ADCB2B0AC867A0A8DCB06.aspx ?S =插座#L2 ..这我会用..但也许你们知道更好的东西。
I started something with MemoryStream
.. but no clear()
, and a lot of improvisation
Also, i found a c# implementation on Koders: http://www.koders.com/csharp/fid2F8CB1B540E646746D3ADCB2B0AC867A0A8DCB06.aspx?s=socket#L2.. which I will use.. but maybe you guys know something better
推荐答案
的MemoryStream
可以做你想要的一切:
MemoryStream
can do everything you want:
-
.array ()
=>.ToArray()
-
.clear()
=>.SetLength(0)
-
。把(字节[], INT,INT)
=>.WRITE(字节[],INT,INT)
-
.remaining()
=>。长度 - .POSITION
.array()
=>.ToArray()
.clear()
=>.SetLength(0)
.put(byte[], int, int)
=>.Write(byte[], int, int)
.remaining()
=>.Length - .Position
如果你愿意,你可以创建清除
和剩余
扩展方法:
If you want, you can create extension methods for Clear
and Remaining
:
public static class MemoryStreamExtensions
{
public static void Clear(this MemoryStream stream)
{
stream.SetLength(0);
}
public static int Remaining(this MemoryStream stream)
{
return stream.Length - stream.Position;
}
}
这篇关于字节集基于类似与ByteBuffer的从Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!