当前位置: 首页>>代码示例>>C#>>正文


C# Key.GetWireType方法代码示例

本文整理汇总了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
     }
 }
开发者ID:huodianyan,项目名称:CitoProtobuf,代码行数:27,代码来源:ProtocolParser.cs

示例2: WriteKey

 public static void WriteKey(CitoStream stream, Key key)
 {
     int n = (key.GetField() << 3) | (key.GetWireType());
     WriteUInt32_(stream, n);
 }
开发者ID:huodianyan,项目名称:CitoProtobuf,代码行数:5,代码来源:ProtocolParser.cs

示例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
        }
    }
开发者ID:huodianyan,项目名称:CitoProtobuf,代码行数:52,代码来源:ProtocolParser.cs


注:本文中的Key.GetWireType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。