本文整理汇总了C#中Bits.Pop方法的典型用法代码示例。如果您正苦于以下问题:C# Bits.Pop方法的具体用法?C# Bits.Pop怎么用?C# Bits.Pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bits
的用法示例。
在下文中一共展示了Bits.Pop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static StunMessage Parse(byte[] bytes)
{
var bits = new Bits(bytes);
if (bits.Pop() != false || bits.Pop() != false)
{
throw new Exception("First two bits must be zeroes.");
}
var type = StunMessageType.Parse(bits.PopBits(14));
var length = BitConverter.ToUInt16(bits.PopLittleEndianBytes(2), 0);
var magicCookie = BitConverter.ToUInt32(bits.PopLittleEndianBytes(4), 0);
if (magicCookie != MagicCookie)
{
throw new ArgumentException($"The parse magic cookie {magicCookie} doesn't match {MagicCookie}.", nameof(MagicCookie));
}
var attributes = new List<StunMessageAttribute>();
for (var index = 0; index < length; index++)
{
attributes.Add(StunMessageAttribute.Parse(bits.PopBits(12 * 8)));
}
var id = StunMessageId.Parse(bits.PopLittleEndianBytes(12));
return new StunMessage(type, attributes, id);
}
示例2: Parse
public static StunMessageType Parse(Bits bits)
{
if (bits.Count != 14)
{
throw new ArgumentException("The number of bits must be 14.", nameof(bits));
}
var methodBits = new Bits(12);
var classBits = new Bits(2);
methodBits.AddBits(bits.PopBits(5));
classBits.AddBit(bits.Pop());
methodBits.AddBits(bits.PopBits(3));
classBits.AddBit(bits.Pop());
methodBits.AddBits(bits);
return new StunMessageType(StunMessageMethod.Parse(methodBits), StunMessageClass.Parse(classBits));
}
示例3: StunMessageType
public StunMessageType(StunMessageMethod method, StunMessageClass @class)
{
if (!method.PermittedClasses.Contains(@class))
{
throw new ArgumentException($"The class {@class} is not permitted by the method {method}.", nameof(@class));
}
Name = method.Name + " " + @class.Name;
var methodBits = new Bits(method.Bits);
var classBits = new Bits(@class.Bits);
var bits = new Bits(14);
bits.AddBits(methodBits.PopBits(5));
bits.AddBit(classBits.Pop());
bits.AddBits(methodBits.PopBits(3));
bits.AddBit(classBits.Pop());
bits.AddBits(methodBits);
Bits = bits.ToBitArray();
}