本文整理汇总了C#中WireType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# WireType.ToString方法的具体用法?C# WireType.ToString怎么用?C# WireType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WireType
的用法示例。
在下文中一共展示了WireType.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFieldHeader
/// <summary>
/// Writes a field-header, indicating the format of the next data we plan to write.
/// </summary>
public static void WriteFieldHeader(int fieldNumber, WireType wireType, ProtoWriter writer) {
if (writer == null) throw new ArgumentNullException("writer");
if (writer.wireType != WireType.None) throw new InvalidOperationException("Cannot write a " + wireType.ToString()
+ " header until the " + writer.wireType.ToString() + " data has been written");
if(fieldNumber < 0) throw new ArgumentOutOfRangeException("fieldNumber");
#if DEBUG
switch (wireType)
{ // validate requested header-type
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.String:
case WireType.StartGroup:
case WireType.SignedVariant:
case WireType.Variant:
break; // fine
case WireType.None:
case WireType.EndGroup:
default:
throw new ArgumentException("Invalid wire-type: " + wireType.ToString(), "wireType");
}
#endif
if (writer.packedFieldNumber == 0) {
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
WriteHeaderCore(fieldNumber, wireType, writer);
}
else if (writer.packedFieldNumber == fieldNumber)
{ // we'll set things up, but note we *don't* actually write the header here
switch (wireType)
{
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.Variant:
case WireType.SignedVariant:
break; // fine
default:
throw new InvalidOperationException("Wire-type cannot be encoded as packed: " + wireType.ToString());
}
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
}
else
{
throw new InvalidOperationException("Field mismatch during packed encoding; expected " + writer.packedFieldNumber.ToString() + " but received " + fieldNumber.ToString());
}
}
示例2: WriteFieldHeader
public static void WriteFieldHeader(int fieldNumber, WireType wireType, ProtoWriter writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (writer.wireType != WireType.None)
{
throw new InvalidOperationException(string.Concat(new string[]
{
"Cannot write a ",
wireType.ToString(),
" header until the ",
writer.wireType.ToString(),
" data has been written"
}));
}
if (fieldNumber < 0)
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
if (writer.packedFieldNumber == 0)
{
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
ProtoWriter.WriteHeaderCore(fieldNumber, wireType, writer);
}
else
{
if (writer.packedFieldNumber != fieldNumber)
{
throw new InvalidOperationException("Field mismatch during packed encoding; expected " + writer.packedFieldNumber.ToString() + " but received " + fieldNumber.ToString());
}
switch (wireType)
{
case WireType.Variant:
case WireType.Fixed64:
case WireType.Fixed32:
goto IL_D7;
case WireType.String:
case WireType.StartGroup:
case WireType.EndGroup:
IL_CB:
if (wireType != WireType.SignedVariant)
{
throw new InvalidOperationException("Wire-type cannot be encoded as packed: " + wireType.ToString());
}
goto IL_D7;
}
goto IL_CB;
IL_D7:
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
}
}