/Mono.Cecil.Metadata/BlobHeap.cs
C# | 54 lines | 32 code | 13 blank | 9 comment | 7 complexity | 0dbc76eb241e39ee93a549fc37024dd5 MD5 | raw file
1// 2// Author: 3// Jb Evain (jbevain@gmail.com) 4// 5// Copyright (c) 2008 - 2015 Jb Evain 6// Copyright (c) 2008 - 2011 Novell, Inc. 7// 8// Licensed under the MIT/X11 license. 9// 10 11using System; 12 13namespace Mono.Cecil.Metadata { 14 15 sealed class BlobHeap : Heap { 16 17 public BlobHeap (byte [] data) 18 : base (data) 19 { 20 } 21 22 public byte [] Read (uint index) 23 { 24 if (index == 0 || index > this.data.Length - 1) 25 return Empty<byte>.Array; 26 27 int position = (int) index; 28 int length = (int) data.ReadCompressedUInt32 (ref position); 29 30 if (length > data.Length - position) 31 return Empty<byte>.Array; 32 33 var buffer = new byte [length]; 34 35 Buffer.BlockCopy (data, position, buffer, 0, length); 36 37 return buffer; 38 } 39 40 public void GetView (uint signature, out byte [] buffer, out int index, out int length) 41 { 42 if (signature == 0 || signature > data.Length - 1) { 43 buffer = null; 44 index = length = 0; 45 return; 46 } 47 48 buffer = data; 49 50 index = (int) signature; 51 length = (int) buffer.ReadCompressedUInt32 (ref index); 52 } 53 } 54}