public long ReadLong(int numbytes)
{
Debug.Assert((buffer.Position + numbytes) <= buffer.Length);
byte[] bytes = buffer.GetBuffer();
int pos = (int)buffer.Position;
buffer.Position += numbytes;
switch (numbytes)
{
case 2: return BitConverter.ToUInt16(bytes, pos);
case 4: return BitConverter.ToUInt32(bytes, pos);
case 8: return BitConverter.ToInt64(bytes, pos);
}
throw new NotSupportedException("Only byte lengths of 2, 4, or 8 are supported");
}