本文整理汇总了C#中System.IO.MemoryStream.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ReadBytes方法的具体用法?C# MemoryStream.ReadBytes怎么用?C# MemoryStream.ReadBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.ReadBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadContents
public override void ReadContents(byte[] bytes)
{
using (var ms = new MemoryStream(bytes))
{
var typeByte = (byte) ms.ReadByte();
FrameType = (FrameType) (typeByte >> 4);
Codec = (Codec) (typeByte & 0x0f);
AVCType = AvcType.NotSet;
if (Codec == Codec.AVC)
{
AVCType = (AvcType) ms.ReadByte();
if (bytes.Length >= 5)
{
switch (AVCType)
{
case AvcType.Nalu:
CompositionTime = Utils.GetUInt24(ms.ReadBytes(3), 0);
break;
default:
CompositionTime = Utils.GetUInt24(ms.ReadBytes(3), 0);
break;
}
}
}
Payload = new byte[ms.Length - ms.Position];
ms.Read(Payload, 0, Payload.Length);
}
}
示例2: Chunk
internal Chunk(MemoryStream ms)
{
Length = Helper.ConvertEndian(ms.ReadUInt32());
ChunkType = Encoding.ASCII.GetString(ms.ReadBytes(4));
ChunkData = ms.ReadBytes((int)Length);
Crc = Helper.ConvertEndian(ms.ReadUInt32());
ParseData(new MemoryStream(ChunkData));
}
示例3: GetWalletPubKeyResponse
public GetWalletPubKeyResponse(byte[] bytes)
{
MemoryStream ms = new MemoryStream(bytes);
var len = ms.ReadByte();
UncompressedPublicKey = new PubKey(ms.ReadBytes(len));
len = ms.ReadByte();
var addr = Encoding.ASCII.GetString(ms.ReadBytes(len));
Address = BitcoinAddress.GetFromBase58Data(addr);
ChainCode = ms.ReadBytes(32);
}
示例4: Decompress
public static byte[] Decompress(this byte[] buffer)
{
if (buffer.Length > 17 && buffer.IsCompressed())
{
MemoryStream inputStream = new MemoryStream(buffer);
int lzmaID = inputStream.ReadInt();
int acutalSize = inputStream.ReadInt();
int lzmaSize = inputStream.ReadInt();
byte[] props = inputStream.ReadBytes(5);
int lzmaBufferSize = buffer.Length - 17;
if (lzmaBufferSize != lzmaSize)
throw new Exception(string.Format("LZMA data corruption. Expected {0} bytes got {1}", lzmaSize, lzmaBufferSize));
byte[] uncompressedBuffer = new byte[acutalSize];
MemoryStream outputStream = new MemoryStream(uncompressedBuffer);
try
{
LZMADecoder = new Decoder();
LZMADecoder.SetDecoderProperties(props);
LZMADecoder.Code(inputStream, outputStream, inputStream.Length, outputStream.Length, null);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return uncompressedBuffer;
}
else
throw new Exception("Buffer is not compressed!");
}
示例5: ParseAttributes
private static ICollection<Sc2ReplayAttribute> ParseAttributes(IMpqArchive replay)
{
var file = replay.ReadFile("replay.attributes.events");
using (var stream = new MemoryStream(file))
{
stream.Skip(5); // there is a 5-byte header; should we validate this?
var attributeCount = stream.ReadInt32();
var attributes = new List<Sc2ReplayAttribute>();
for (var i = 0; i < attributeCount; i++)
{
var attr = new Sc2ReplayAttribute
{
Header = stream.ReadInt32(),
Type = (Sc2ReplayAttributeType) stream.ReadInt32(),
PlayerIndex = stream.ReadByte(),
Value = stream.ReadBytes(4).Reverse().ToArray(),
};
attributes.Add(attr);
}
return attributes;
}
}
示例6: Decode
public void Decode(byte[] bytes)
{
using (var ms = new MemoryStream(bytes))
{
StreamId = dc.GetInt32(ms.ReadBytes(4), 0);
}
}
示例7: Fill
private static bool Fill(StealthMetadata output, Script metadata, byte[] data)
{
if(data == null || data.Length != 1 + 4 + 33)
return false;
MemoryStream ms = new MemoryStream(data);
output.Version = ms.ReadByte();
if(output.Version != 6)
return false;
output.Nonce = ms.ReadBytes(4);
output.EphemKey = new PubKey(ms.ReadBytes(33));
output.Script = metadata;
output.Hash = Hashes.Hash256(data);
var msprefix = new MemoryStream(output.Hash.ToBytes(false));
output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
return true;
}
示例8: Decode
public void Decode(byte[] bytes)
{
using (var ms = new MemoryStream(bytes))
{
Value = dc.GetInt32(ms.ReadBytes(4), 0);
Type = (LimitType) ms.ReadByte();
}
}
示例9: Decode
public void Decode(byte[] bytes)
{
using (var ms = new MemoryStream(bytes))
{
Type = (ControlType) dc.GetInt16(ms.ReadBytes(2), 0);
switch (Type)
{
case ControlType.STREAM_BEGIN:
case ControlType.STREAM_EOF:
case ControlType.STREAM_DRY:
case ControlType.STREAM_IS_RECORDED:
StreamID = dc.GetInt32(ms.ReadBytes(4), 0);
break;
case ControlType.SET_BUFFER:
StreamID = dc.GetInt32(ms.ReadBytes(4), 0);
BufferLength = dc.GetInt32(ms.ReadBytes(4), 0);
break;
case ControlType.PING_REQUEST:
case ControlType.PING_RESPONSE:
Time = dc.GetInt32(ms.ReadBytes(4), 0);
break;
case ControlType.SWFV_REQUEST:
break;
case ControlType.SWFV_RESPONSE:
Bytes = ms.ReadBytes(42);
break;
case ControlType.BUFFER_FULL:
case ControlType.BUFFER_EMPTY:
StreamID = dc.GetInt32(ms.ReadBytes(4), 0);
break;
}
}
}
示例10: Fill
private static bool Fill(StealthMetadata output, Script metadata)
{
var ops = metadata.ToOps().ToArray();
if(ops.Length != 2 || ops[0].Code != OpcodeType.OP_RETURN)
return false;
var data = ops[1].PushData;
if(data == null || data.Length != 1 + 4 + 33)
return false;
MemoryStream ms = new MemoryStream(data);
output.Version = ms.ReadByte();
if(output.Version != 6)
return false;
output.Nonce = ms.ReadBytes(4);
output.EphemKey = new PubKey(ms.ReadBytes(33));
output.Script = metadata;
output.Hash = Hashes.Hash256(data);
var msprefix = new MemoryStream(output.Hash.ToBytes(false));
output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
return true;
}
示例11: SliceStreamTest
public void SliceStreamTest()
{
MemoryStream MemoryStream = new MemoryStream(Encoding.ASCII.GetBytes("Hello World"));
MemoryStream.ReadBytes(6);
var SliceStream = MemoryStream.ReadStream();
Assert.AreEqual("Wo", Encoding.ASCII.GetString(SliceStream.ReadBytes(2)));
var SliceStream2 = SliceStream.ReadStream();
Assert.AreEqual(0, SliceStream.Available());
Assert.AreEqual("rld", Encoding.ASCII.GetString(SliceStream2.ReadBytes(3)));
Assert.AreEqual(0, SliceStream2.Available());
}
示例12: Parse
public Packet Parse()
{
var p = new Packet();
byte header = _socket.ReceiveByte();
int chunktype = (header & 0xC0) >> 6;
p.ChunkType = chunktype;
p.ChunkStreamId = header & 0x3F;
switch (p.ChunkStreamId)
{
case 0:
p.ChunkStreamId = 64 + _socket.ReceiveByte();
break;
case 1:
p.ChunkStreamId = 64 + _socket.ReceiveByte() + (_socket.ReceiveByte()*256);
break;
}
switch (p.ChunkType)
{
case 3:
p.TimeStamp = _previousReadPacket[p.ChunkStreamId].TimeStamp;
p.Length = _previousReadPacket[p.ChunkStreamId].Length;
p.Type = _previousReadPacket[p.ChunkStreamId].Type;
p.MessageStreamId = _previousReadPacket[p.ChunkStreamId].MessageStreamId;
break;
case 2:
p.Length = _previousReadPacket[p.ChunkStreamId].Length;
p.Type = _previousReadPacket[p.ChunkStreamId].Type;
p.MessageStreamId = _previousReadPacket[p.ChunkStreamId].MessageStreamId;
break;
case 1:
p.MessageStreamId = _previousReadPacket[p.ChunkStreamId].MessageStreamId;
break;
case 0:
break;
}
_previousReadPacket[p.ChunkStreamId] = p;
int headersize = HeaderSizes[p.ChunkType];
if (headersize == MaxHeaderSize)
{
p.HasAbsTimestamp = true;
}
if (!Operations.ContainsKey(p.ChunkStreamId))
{
Operations[p.ChunkStreamId] = new Operation();
}
if (Operations[p.ChunkStreamId].Response != null)
{
p = Operations[p.ChunkStreamId].Response;
headersize = 0;
}
else
{
Operations[p.ChunkStreamId].CreateResponse(p);
}
headersize--;
var headerbytes = new byte[0];
if (headersize > 0)
{
headerbytes = new byte[headersize];
_socket.Receive(headerbytes, 0, headersize);
}
using (var headerstream = new MemoryStream(headerbytes))
{
if (headersize >= 3)
{
p.TimeStamp = (int) Utils.GetUInt24(headerstream.ReadBytes(3), 0);
if (!p.HasAbsTimestamp)
{
if (!_streamTimestamps.ContainsKey(p.ChunkStreamId)) _streamTimestamps[p.ChunkStreamId] = 0;
p.TimeStamp += _streamTimestamps[p.ChunkStreamId];
_streamTimestamps[p.ChunkStreamId] = p.TimeStamp;
}
}
if (headersize >= 6)
{
p.Length = (int) Utils.GetUInt24(headerstream.ReadBytes(3), 0);
p.BytesRead = 0;
p.BytePayload = null;
}
if (headersize > 6)
{
p.Type = (PayloadType) headerstream.ReadByte();
}
if (headersize == 11)
{
p.MessageStreamId = DataConverter.LittleEndian.GetInt32(headerstream.ReadBytes(4), 0);
}
}
int ntoread = p.Length - p.BytesRead;
//.........这里部分代码省略.........
示例13: DecryptDatabase
public async Task<Stream> DecryptDatabase(byte[] source, byte[] aesKey)
{
var unreadData = source;
byte[] decryptedDatabase = null;
try
{
_encryptionEngine.AlgorithmType = CryptoAlgoritmType.AES_CBC_PKCS7;
decryptedDatabase = await _encryptionEngine.Decrypt(source, aesKey, file.pbEncryptionIV);
}
catch (Exception e)
{
throw new SecurityException("There was a problem opening your database", e);
}
var startBytes = new byte[32];
var databaseReader = new MemoryStream(decryptedDatabase);
databaseReader.ReadBytes(startBytes);
var headerStartBytes = file.pbStreamStartBytes;
for (int iStart = 0; iStart < 32; ++iStart)
{
if (startBytes[iStart] != headerStartBytes[iStart])
throw new Exception();
}
return databaseReader;
}
示例14: ParseData
protected override void ParseData(MemoryStream ms)
{
SequenceNumber = Helper.ConvertEndian(ms.ReadUInt32());
FrameData = ms.ReadBytes((int) Length - 4);
}
示例15: ME2Texture2D
//.........这里部分代码省略.........
if (String.Compare(exp.ClassName, className) != 0 && String.Compare(exp.ClassName, class2) != 0 && String.Compare(exp.ClassName, class3) != 0)
{
throw new FormatException("Export is not a texture");
}
Class = exp.ClassName;
exportOffset = exp.DataOffset;
FullPackage = exp.PackageFullName;
texName = exp.ObjectName;
pccFileName = pcc.pccFileName;
allPccs = new List<string>();
allPccs.Add(pcc.pccFileName);
properties = new Dictionary<string, SaltPropertyReader.Property>();
byte[] rawData = (byte[])exp.Data.Clone();
Compression = "No Compression";
int propertiesOffset = SaltPropertyReader.detectStart(pcc, rawData);
headerData = new byte[propertiesOffset];
Buffer.BlockCopy(rawData, 0, headerData, 0, propertiesOffset);
pccOffset = (uint)exp.DataOffset;
UnpackNum = 0;
List<SaltPropertyReader.Property> tempProperties = SaltPropertyReader.getPropList(pcc, rawData);
for (int i = 0; i < tempProperties.Count; i++)
{
SaltPropertyReader.Property property = tempProperties[i];
if (property.Name == "UnpackMin")
UnpackNum++;
if (!properties.ContainsKey(property.Name))
properties.Add(property.Name, property);
switch (property.Name)
{
case "Format": texFormat = property.Value.StringValue; break;
case "TextureFileCacheName": arcName = property.Value.StringValue; break;
case "LODGroup": LODGroup = property.Value.StringValue; break;
case "CompressionSettings": Compression = property.Value.StringValue; break;
case "None": dataOffset = (uint)(property.offsetval + property.Size); break;
}
}
// if "None" property isn't found throws an exception
if (dataOffset == 0)
throw new Exception("\"None\" property not found");
if (!String.IsNullOrEmpty(arcName))
FullArcPath = GetTexArchive(pathBioGame);
imageData = new byte[rawData.Length - dataOffset];
Buffer.BlockCopy(rawData, (int)dataOffset, imageData, 0, (int)(rawData.Length - dataOffset));
//DebugOutput.PrintLn("ImageData size = " + imageData.Length);
pccExpIdx = pccExpID;
MemoryStream dataStream = new MemoryStream(imageData);
privateimgList = new List<ImageInfo>();
dataStream.ReadValueU32(); //Current position in pcc
numMipMaps = dataStream.ReadValueU32();
uint count = numMipMaps;
ArcDataSize = 0;
//DebugOutput.PrintLn(numMipMaps + " derp");
while (dataStream.Position < dataStream.Length && count > 0)
{
ImageInfo imgInfo = new ImageInfo();
imgInfo.storageType = (storage)dataStream.ReadValueS32();
imgInfo.uncSize = dataStream.ReadValueS32();
imgInfo.cprSize = dataStream.ReadValueS32();
imgInfo.offset = dataStream.ReadValueS32();
if (imgInfo.storageType == storage.pccSto)
{
imgInfo.offset = (int)dataStream.Position;
dataStream.Seek(imgInfo.uncSize, SeekOrigin.Current);
}
else if (imgInfo.storageType == storage.arcCpr || imgInfo.storageType == storage.arcUnc)
{
ArcDataSize += imgInfo.uncSize;
}
imgInfo.imgSize = new ImageSize(dataStream.ReadValueU32(), dataStream.ReadValueU32());
if (privateimgList.Exists(img => img.imgSize == imgInfo.imgSize))
{
uint width = imgInfo.imgSize.width;
uint height = imgInfo.imgSize.height;
if (width == 4 && privateimgList.Exists(img => img.imgSize.width == width))
width = privateimgList.Last().imgSize.width / 2;
if (width == 0)
width = 1;
if (height == 4 && privateimgList.Exists(img => img.imgSize.height == height))
height = privateimgList.Last().imgSize.height / 2;
if (height == 0)
height = 1;
imgInfo.imgSize = new ImageSize(width, height);
if (privateimgList.Exists(img => img.imgSize == imgInfo.imgSize))
throw new Exception("Duplicate image size found");
}
privateimgList.Add(imgInfo);
count--;
//DebugOutput.PrintLn("ImgInfo no: " + count + ", Storage Type = " + imgInfo.storageType + ", offset = " + imgInfo.offset);
}
// Grab the rest for the footer
footerData = new byte[dataStream.Length - dataStream.Position];
footerData = dataStream.ReadBytes(footerData.Length);
}