private static int WriteReferenceInteger(BinaryWriter writer, long value, int size)
{
byte[] buffer;
switch (size)
{
case 1:
buffer = new byte[] { (byte)value };
break;
case 2:
buffer = BitConverter.GetBytes(((short)value).ToBigEndianConditional());
break;
case 4:
buffer = BitConverter.GetBytes(((int)value).ToBigEndianConditional());
break;
case 8:
buffer = BitConverter.GetBytes(value.ToBigEndianConditional());
break;
default:
throw new ArgumentException("The reference size must be one of 1, 2, 4 or 8. The specified reference size was: " + size, "size");
}
writer.Write(buffer, 0, buffer.Length);
return buffer.Length;
}