本文整理汇总了C#中Key.GetWireType方法的典型用法代码示例。如果您正苦于以下问题:C# Key.GetWireType方法的具体用法?C# Key.GetWireType怎么用?C# Key.GetWireType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Key
的用法示例。
在下文中一共展示了Key.GetWireType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SkipKey
/// <summary>
/// Seek past the value for the previously read key.
/// </summary>
public static void SkipKey(CitoStream stream, Key key)
{
switch (key.GetWireType())
{
case Wire.Fixed32:
stream.Seek(4, CitoSeekOrigin.Current);
return;
case Wire.Fixed64:
stream.Seek(8, CitoSeekOrigin.Current);
return;
case Wire.LengthDelimited:
stream.Seek(ProtocolParser.ReadUInt32(stream), CitoSeekOrigin.Current);
return;
case Wire.Varint:
ProtocolParser.ReadSkipVarInt(stream);
return;
default:
#if !CITO
throw new NotImplementedException("Unknown wire type: " + key.GetWireType());
#else
return;
#endif
}
}
示例2: WriteKey
public static void WriteKey(CitoStream stream, Key key)
{
int n = (key.GetField() << 3) | (key.GetWireType());
WriteUInt32_(stream, n);
}
示例3: ReadValueBytes
/// <summary>
/// Read the value for an unknown key as bytes.
/// Used to preserve unknown keys during deserialization.
/// Requires the message option preserveunknown=true.
/// </summary>
public static byte[] ReadValueBytes(CitoStream stream, Key key)
{
byte[] b;
int offset = 0;
switch (key.GetWireType())
{
case Wire.Fixed32:
b = new byte[4];
while (offset < 4)
offset += stream.Read(b, offset, 4 - offset);
return b;
case Wire.Fixed64:
b = new byte[8];
while (offset < 8)
offset += stream.Read(b, offset, 8 - offset);
return b;
case Wire.LengthDelimited:
//Read and include length in value buffer
int length = ProtocolParser.ReadUInt32(stream);
CitoMemoryStream ms = new CitoMemoryStream();
{
//TODO: pass b directly to MemoryStream constructor or skip usage of it completely
ProtocolParser.WriteUInt32(ms, length);
b = new byte[length + ms.Length()];
byte[] arr = ms.ToArray();
for (int i = 0; i < ProtoPlatform.ArrayLength(arr); i++)
{
b[i] = arr[i];
}
offset = ms.Length();
}
//Read data into buffer
while (offset < ProtoPlatform.ArrayLength(b))
offset += stream.Read(b, offset, ProtoPlatform.ArrayLength(b) - offset);
return b;
case Wire.Varint:
return ProtocolParser.ReadVarIntBytes(stream);
default:
#if !CITO
throw new NotImplementedException("Unknown wire type: " + key.GetWireType());
#else
return null;
#endif
}
}