private static int Read7Bit(ReadBuffer readBuffer) { var position = readBuffer.Position; readBuffer.Fill(1); byte currentByte; var result = 0; while (((currentByte = readBuffer[readBuffer.Index++]) & 0x80) > 0) { result |= currentByte & 0x7F; // - 1 accounts for the fact that we must not overwrite the sign bit by shifting in bits const int DiscardBitsMask = Constants.AllBitsSetInt << (Constants.BitsPerInt - Constants.BitsPerEncodedByte - 1); if ((result & DiscardBitsMask) != 0) { throw CreateEmberException( "The identifier number or subidentifier at position {0} exceeds the expected range.", position); } result <<= Constants.BitsPerEncodedByte; readBuffer.Fill(1); } result |= currentByte; return(result); }
/// <summary>See <i>"X.690"</i><cite>X.690</cite>, chapter 8.1.3.</summary> private static int?ReadLength(ReadBuffer readBuffer) { var position = readBuffer.Position; readBuffer.Fill(1); var leadingOctet = readBuffer[readBuffer.Index++]; if ((leadingOctet & 0x80) > 0) { var length = leadingOctet & 0x7F; if (length == 0) { return(null); } readBuffer.Fill(length); var result = Read8Bit(readBuffer, length, false); if (result > int.MaxValue) { throw CreateEmberException("The length at position {0} exceeds the expected range.", position); } return((int)result); } else { return(leadingOctet); } }
/// <summary>See <i>"X.690"</i><cite>X.690</cite>, chapter 8.1.2.</summary> private static EmberId ReadIdentifier(ReadBuffer readBuffer) { readBuffer.Fill(1); var leadingOctet = readBuffer[readBuffer.Index++]; var theClass = (Class)(leadingOctet & 0xC0); var isConstructed = (leadingOctet & 0x20) > 0; var number = leadingOctet & 0x1F; return(new EmberId(theClass, isConstructed, (number <= 30) ? number : Read7Bit(readBuffer))); }
private static int Read7Bit(ReadBuffer readBuffer) { var position = readBuffer.Position; readBuffer.Fill(1); byte currentByte; var result = 0; while (((currentByte = readBuffer[readBuffer.Index++]) & 0x80) > 0) { result |= currentByte & 0x7F; // - 1 accounts for the fact that we must not overwrite the sign bit by shifting in bits const int DiscardBitsMask = Constants.AllBitsSetInt << (Constants.BitsPerInt - Constants.BitsPerEncodedByte - 1); if ((result & DiscardBitsMask) != 0) { throw CreateEmberException( "The identifier number or subidentifier at position {0} exceeds the expected range.", position); } result <<= Constants.BitsPerEncodedByte; readBuffer.Fill(1); } result |= currentByte; return result; }
/// <summary>See <i>"X.690"</i><cite>X.690</cite>, chapter 8.1.3.</summary> private static int? ReadLength(ReadBuffer readBuffer) { var position = readBuffer.Position; readBuffer.Fill(1); var leadingOctet = readBuffer[readBuffer.Index++]; if ((leadingOctet & 0x80) > 0) { var length = leadingOctet & 0x7F; if (length == 0) { return null; } readBuffer.Fill(length); var result = Read8Bit(readBuffer, length, false); if (result > int.MaxValue) { throw CreateEmberException("The length at position {0} exceeds the expected range.", position); } return (int)result; } else { return leadingOctet; } }
/// <summary>See <i>"X.690"</i><cite>X.690</cite>, chapter 8.1.2.</summary> private static EmberId ReadIdentifier(ReadBuffer readBuffer) { readBuffer.Fill(1); var leadingOctet = readBuffer[readBuffer.Index++]; var theClass = (Class)(leadingOctet & 0xC0); var isConstructed = (leadingOctet & 0x20) > 0; var number = leadingOctet & 0x1F; return new EmberId(theClass, isConstructed, (number <= 30) ? number : Read7Bit(readBuffer)); }