public override void Decode(byte[] buffer, int offset, int length) { BEncodedValue val; using (RawReader reader = new RawReader(new MemoryStream(buffer, offset, length, false), false)) { BEncodedDictionary d = BEncodedDictionary.Decode <BEncodedDictionary>(reader); int totalSize = 0; if (d.TryGetValue(MessageTypeKey, out val)) { messageType = (eMessageType)((BEncodedNumber)val).Number; } if (d.TryGetValue(PieceKey, out val)) { piece = (int)((BEncodedNumber)val).Number; } if (d.TryGetValue(TotalSizeKey, out val)) { totalSize = (int)((BEncodedNumber)val).Number; metadata = new byte[Math.Min(totalSize - piece * BlockSize, BlockSize)]; reader.Read(metadata, 0, metadata.Length); } } }
unsafe void LoadTestData(string path, out NativeArray <SampleData> samples, out NativeArray <StackFrameData> stackFrames, Allocator allocator = Allocator.Persistent) { using (var stream = File.OpenRead(path)) { var reader = new RawReader(stream); int numSamples = 0; reader.Read(&numSamples); samples = new NativeArray <SampleData>(numSamples, allocator); reader.ReadBytes(samples.GetUnsafePtr(), numSamples * sizeof(SampleData)); int numStackFrames = 0; reader.Read(&numStackFrames); stackFrames = new NativeArray <StackFrameData>(numStackFrames, allocator); reader.ReadBytes(stackFrames.GetUnsafePtr(), numStackFrames * sizeof(StackFrameData)); } }
private static void ConvertFile(string fileName) { var reader = new RawReader(fileName); RawData file = null; try { file = reader.Read(); } catch (RawReaderException e) { _hasErrored = true; Console.WriteLine("File: {0}", fileName); Console.WriteLine(e.Message); Console.WriteLine("Reason: {0}", e.InnerException.Message); return; } string data = ""; switch (file.Type) { case RawType.UnitData: data = UnitDataConverter.GetString((UnitData)file); break; case RawType.SkillData: data = SkillDataConverter.GetString((SkillData)file); break; case RawType.AffixData: data = AffixDataConverter.GetString((AffixData)file); break; case RawType.MissileData: data = MissileDataConverter.GetString((MissileData)file); break; case RawType.RoomPieceData: data = RoomPieceDataConverter.GetString((RoomPieceData)file); break; case RawType.TriggerableData: data = TriggerableDataConverter.GetString((TriggerableData)file); break; case RawType.UserInterfaceData: data = UserInterfaceDataConverter.GetString((UserInterfaceData)file); break; } string outputPath = _outputDir != "" ? Path.Combine(_outputDir, Path.GetFileNameWithoutExtension(fileName) + ".txt") : fileName.Replace(Path.GetExtension(fileName), ".txt"); File.WriteAllText(outputPath, data); Console.WriteLine("Converted {0} into a human readable format", Path.GetFileName(fileName)); }
public override void Decode(byte[] buffer, int offset, int length) { using (var reader = new RawReader(new MemoryStream(buffer, offset, length, false), false)) { var decode = BEncodedValue.Decode <BEncodedDictionary>(reader); BEncodedValue val; if (decode.TryGetValue(MessageTypeKey, out val)) { _messageType = (eMessageType)((BEncodedNumber)val).Number; } if (decode.TryGetValue(PieceKey, out val)) { Piece = (int)((BEncodedNumber)val).Number; } if (decode.TryGetValue(TotalSizeKey, out val)) { var totalSize = (int)((BEncodedNumber)val).Number; MetadataPiece = new byte[Math.Min(totalSize - Piece * BlockSize, BlockSize)]; reader.Read(MetadataPiece, 0, MetadataPiece.Length); } } }
public override void Decode(byte[] buffer, int offset, int length) { using (var reader = new RawReader(new MemoryStream(buffer, offset, length, false), false)) { var decode = BEncodedValue.Decode<BEncodedDictionary>(reader); BEncodedValue val; if (decode.TryGetValue(MessageTypeKey, out val)) _messageType = (eMessageType) ((BEncodedNumber) val).Number; if (decode.TryGetValue(PieceKey, out val)) Piece = (int) ((BEncodedNumber) val).Number; if (decode.TryGetValue(TotalSizeKey, out val)) { var totalSize = (int) ((BEncodedNumber) val).Number; MetadataPiece = new byte[Math.Min(totalSize - Piece*BlockSize, BlockSize)]; reader.Read(MetadataPiece, 0, MetadataPiece.Length); } } }