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


C# CodedInputStream.ReadUInt32方法代码示例

本文整理汇总了C#中Google.Protobuf.CodedInputStream.ReadUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# CodedInputStream.ReadUInt32方法的具体用法?C# CodedInputStream.ReadUInt32怎么用?C# CodedInputStream.ReadUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google.Protobuf.CodedInputStream的用法示例。


在下文中一共展示了CodedInputStream.ReadUInt32方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ByteStringToValueType

 public void ByteStringToValueType ()
 {
     // From Google's protobuf documentation, varint encoding example:
     // 300 = 1010 1100 0000 0010 = 0xAC 0x02
     byte[] bytes = { 0xAC, 0x02 };
     var codedStream = new CodedInputStream (bytes);
     uint value = codedStream.ReadUInt32 ();
     Assert.AreEqual (300, value);
 }
开发者ID:paperclip,项目名称:krpc,代码行数:9,代码来源:SchemaTest.cs

示例2: Decode

 /// <summary>
 /// Decode a value of the given type.
 /// Should not be called directly. This interface is used by service client stubs.
 /// </summary>
 public static object Decode(ByteString value, Type type, Connection client)
 {
     var stream = new CodedInputStream (value.ToByteArray ());
     if (type == typeof(double))
         return stream.ReadDouble ();
     else if (type == typeof(float))
         return stream.ReadFloat ();
     else if (type == typeof(int))
         return stream.ReadInt32 ();
     else if (type == typeof(long))
         return stream.ReadInt64 ();
     else if (type == typeof(uint))
         return stream.ReadUInt32 ();
     else if (type == typeof(ulong))
         return stream.ReadUInt64 ();
     else if (type == typeof(bool))
         return stream.ReadBool ();
     else if (type == typeof(string))
         return stream.ReadString ();
     else if (type == typeof(byte[]))
         return stream.ReadBytes ().ToByteArray ();
     else if (type.IsEnum)
         return stream.ReadInt32 ();
     else if (typeof(RemoteObject).IsAssignableFrom (type)) {
         if (client == null)
             throw new ArgumentException ("Client not passed when decoding remote object");
         var id = stream.ReadUInt64 ();
         if (id == 0)
             return null;
         return (RemoteObject)Activator.CreateInstance (type, client, id);
     } else if (typeof(IMessage).IsAssignableFrom (type)) {
         IMessage message = (IMessage)Activator.CreateInstance (type);
         message.MergeFrom (stream);
         return message;
     } else if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof(IList<>))
         return DecodeList (value, type, client);
     else if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof(IDictionary<,>))
         return DecodeDictionary (value, type, client);
     else if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof(ISet<>))
         return DecodeSet (value, type, client);
     else if (type.IsGenericType &&
              (type.GetGenericTypeDefinition () == typeof(Tuple<>) ||
              type.GetGenericTypeDefinition () == typeof(Tuple<,>) ||
              type.GetGenericTypeDefinition () == typeof(Tuple<,,>) ||
              type.GetGenericTypeDefinition () == typeof(Tuple<,,,>) ||
              type.GetGenericTypeDefinition () == typeof(Tuple<,,,,>) ||
              type.GetGenericTypeDefinition () == typeof(Tuple<,,,,,>)))
         return DecodeTuple (value, type, client); // TODO: ugly handing of tuple types
     throw new ArgumentException (type + " is not a serializable type");
 }
开发者ID:artwhaley,项目名称:krpc,代码行数:54,代码来源:Encoder.cs

示例3: Read

 protected override int Read (ref Request request, byte[] data, int offset, int length)
 {
     try {
         var codedStream = new CodedInputStream (data, offset, length);
         // Get the protobuf message size
         int size = (int)codedStream.ReadUInt32 ();
         int totalSize = (int)codedStream.Position + size;
         // Check if enough data is available, if not then delay the decoding
         if (length < totalSize)
             return 0;
         // Decode the request
         request = Schema.KRPC.Request.Parser.ParseFrom (codedStream).ToMessage ();
         return totalSize;
     } catch (InvalidProtocolBufferException e) {
         throw new MalformedRequestException (e.Message);
     }
 }
开发者ID:paperclip,项目名称:krpc,代码行数:17,代码来源:RPCStream.cs

示例4: ReadValue

 /// <summary>
 /// Convert a Protocol Buffer value type, encoded as a byte string, to a C# value.
 /// </summary>
 public static object ReadValue(ByteString value, Type type)
 {
     if (value.Length == 0)
         throw new ArgumentException ("Value is empty");
     var stream = new CodedInputStream (value.ToByteArray ());
     if (type == typeof(double)) {
         return stream.ReadDouble ();
     } else if (type == typeof(float)) {
         return stream.ReadFloat ();
     } else if (type == typeof(int)) {
         return stream.ReadInt32 ();
     } else if (type == typeof(long)) {
         return stream.ReadInt64 ();
     } else if (type == typeof(uint)) {
         return stream.ReadUInt32 ();
     } else if (type == typeof(ulong)) {
         return stream.ReadUInt64 ();
     } else if (type == typeof(bool)) {
         return stream.ReadBool ();
     } else if (type == typeof(string)) {
         return stream.ReadString ();
     } else if (type == typeof(byte[])) {
         return stream.ReadBytes ().ToByteArray();
     }
     throw new ArgumentException (type + " is not a Protocol Buffer value type");
 }
开发者ID:artwhaley,项目名称:krpc,代码行数:29,代码来源:ProtocolBuffers.cs


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