本文整理匯總了C#中Bits.AddBits方法的典型用法代碼示例。如果您正苦於以下問題:C# Bits.AddBits方法的具體用法?C# Bits.AddBits怎麽用?C# Bits.AddBits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Bits
的用法示例。
在下文中一共展示了Bits.AddBits方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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));
}
示例2: 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();
}
示例3: ToLittleEndianByteArray
public byte[] ToLittleEndianByteArray()
{
var bits = new Bits(20);
bits.AddOffBit();
bits.AddOffBit();
bits.AddBits(Type.Bits);
var length = (ushort)(Attributes.Count() * 4 * 8);
bits.AddUInt16LittleEndian(length);
bits.AddUInt32LittleEndian(MagicCookie);
bits.AddBytesLittleEndian(Id.Bytes);
return bits.ToLittleEndianByteArray();
}