sharp-cryptonote-tool/streams/ExtendedStreamReader.cs

52 lines
748 B
C#

using System;
using System.IO;
namespace sharp.cryptonote.streams
{
public class ExtendedStreamReader
{
Stream stream;
public ExtendedStreamReader(Stream stream)
{
this.stream = stream;
}
public Int64 readVarInt(){
Int64 result = 0;
int t, s;
s = 0;
do
{
t = stream.ReadByte();
if (t == 0){
break;
}
//result *= 128;
//result += t & 0x7F;
result |= (t & 0x7F) << s;
s += 7;
} while (t >= 128);
return result;
}
public byte[] readBytes(int len){
byte[] buffer = new byte[len];
stream.Read(buffer,0,len);
return buffer;
}
public UInt32 readUInt32()
{
byte[] t = new byte[4];
stream.Read(t,0,4);
return BitConverter.ToUInt32(t, 0);
}
}
}