// ----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ----------------------------------------------------------------------------
namespace Iso9660
{
///
/// This class contains static methods for marshalling and unmarshalling
/// 32-bit integers.
///
public class Int {
///
/// The size (in bytes) of the marshalled representation of an integer.
///
public const int Size = 4;
///
/// Marshalls an integer into a buffer starting at a pointer into the
/// buffer, and advances the pointer accordingly.
///
/// The integer that is being marshalled.
/// The buffer into which the integer is marshalled.
/// The position in the buffer where the Handle starts.
/// After completion, offset is the next position after the Handle.
public static void Marshall(int i, byte[] bytes, ref int offset) {
bytes[offset+0] = (byte)(i & 0xff); i >>= 8;
bytes[offset+1] = (byte)(i & 0xff); i >>= 8;
bytes[offset+2] = (byte)(i & 0xff); i >>= 8;
bytes[offset+3] = (byte)(i & 0xff); i >>= 8;
offset += 4;
}
///
/// Given a buffer and a pointer into it, unmarshalls an integer from the
/// buffer, advancing the pointer by 4 bytes.
///
/// The buffer from which the integer is unmarshalled.
/// The position in the buffer where the Handle starts.
/// After completion, offset is the next position after the Handle.
/// The integer that was unmarshalled.
public static int Unmarshall(byte[] bytes, ref int offset) {
int i = 0;
i = (i << 8) | bytes[offset+3];
i = (i << 8) | bytes[offset+2];
i = (i << 8) | bytes[offset+1];
i = (i << 8) | bytes[offset+0];
offset += 4;
return i;
}
public static int Parse(string val) {
int num;
if (val.Length > 2 && val[0] == '0' &&
(val[1] == 'x' || val[1] == 'X')) {
num = System.Int32.Parse(val.Substring(2),
System.Globalization.NumberStyles.AllowHexSpecifier);
}
else {
num = System.Int32.Parse(val);
}
return num;
}
}
}