當前位置: 首頁>>代碼示例>>C#>>正文


C# ProtoReader.ReadUInt32Variant方法代碼示例

本文整理匯總了C#中ProtoBuf.ProtoReader.ReadUInt32Variant方法的典型用法代碼示例。如果您正苦於以下問題:C# ProtoReader.ReadUInt32Variant方法的具體用法?C# ProtoReader.ReadUInt32Variant怎麽用?C# ProtoReader.ReadUInt32Variant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProtoBuf.ProtoReader的用法示例。


在下文中一共展示了ProtoReader.ReadUInt32Variant方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AppendBytes

 /// <summary>
 /// Reads a byte-sequence from the stream, appending them to an existing byte-sequence (which can be null); supported wire-types: String
 /// </summary>
 public static byte[] AppendBytes(byte[] value, ProtoReader reader)
 {
     switch (reader.wireType)
     {
         case WireType.String:
             int len = (int)reader.ReadUInt32Variant(false);
             reader.wireType = WireType.None;
             if (len == 0) return value;
             int offset;
             if(value == null || value.Length == 0) {
                 offset = 0;
                 value = new byte[len];
             } else {
                 offset = value.Length;
                 byte[] tmp = new byte[value.Length + len];
                 Helpers.BlockCopy(value, 0, tmp, 0, value.Length);
                 value = tmp;
             }
             // value is now sized with the final length, and (if necessary)
             // contains the old data up to "offset"
             reader.position += len; // assume success
             while (len > reader.available)
             {
                 if (reader.available > 0)
                 {
                     // copy what we *do* have
                     Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, reader.available);
                     len -= reader.available;
                     offset += reader.available;
                     reader.ioIndex = reader.available = 0; // we've drained the buffer
                 }
                 //  now refill the buffer (without overflowing it)
                 int count = len > reader.ioBuffer.Length ? reader.ioBuffer.Length : len;
                 if (count > 0) reader.Ensure(count, true);
             }
             // at this point, we know that len <= available
             if (len > 0)
             {   // still need data, but we have enough buffered
                 Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, len);
                 reader.ioIndex += len;
                 reader.available -= len;
             }
             return value;
         default:
             throw reader.CreateException();
     }
 }
開發者ID:AugustoAngeletti,項目名稱:blockspaces,代碼行數:50,代碼來源:ProtoReader.cs

示例2: StartSubItem

 public static SubItemToken StartSubItem(ProtoReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     WireType wireType = reader.wireType;
     if (wireType != WireType.String)
     {
         if (wireType != WireType.StartGroup)
         {
             throw reader.CreateWireTypeException();
         }
         reader.wireType = WireType.None;
         reader.depth++;
         return new SubItemToken(-reader.fieldNumber);
     }
     else
     {
         int num = (int)reader.ReadUInt32Variant(false);
         if (num < 0)
         {
             throw ProtoReader.AddErrorData(new InvalidOperationException(), reader);
         }
         int value = reader.blockEnd;
         reader.blockEnd = reader.position + num;
         reader.depth++;
         return new SubItemToken(value);
     }
 }
開發者ID:floatyears,項目名稱:Decrypt,代碼行數:30,代碼來源:ProtoReader.cs

示例3: StartSubItem

 /// <summary>
 /// Begins consuming a nested message in the stream; supported wire-types: StartGroup, String
 /// </summary>
 /// <remarks>The token returned must be help and used when callining EndSubItem</remarks>
 public static SubItemToken StartSubItem(ProtoReader reader)
 {
     switch (reader.wireType)
     {
         case WireType.StartGroup:
             reader.wireType = WireType.None; // to prevent glitches from double-calling
             reader.depth++;
             return new SubItemToken(-reader.fieldNumber);
         case WireType.String:
             int len = (int)reader.ReadUInt32Variant(false);
             if (len < 0) throw AddErrorData(new InvalidOperationException(), reader);
             int lastEnd = reader.blockEnd;
             reader.blockEnd = reader.position + len;
             reader.depth++;
             return new SubItemToken(lastEnd);
         default:
             throw reader.CreateException(); // throws
     }
 }
開發者ID:AugustoAngeletti,項目名稱:blockspaces,代碼行數:23,代碼來源:ProtoReader.cs

示例4: AppendBytes

 public static byte[] AppendBytes(byte[] value, ProtoReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     WireType wireType = reader.wireType;
     if (wireType != WireType.String)
     {
         throw reader.CreateWireTypeException();
     }
     int i = (int)reader.ReadUInt32Variant(false);
     reader.wireType = WireType.None;
     if (i == 0)
     {
         return (value != null) ? value : ProtoReader.EmptyBlob;
     }
     int num;
     if (value == null || value.Length == 0)
     {
         num = 0;
         value = new byte[i];
     }
     else
     {
         num = value.Length;
         byte[] array = new byte[value.Length + i];
         Helpers.BlockCopy(value, 0, array, 0, value.Length);
         value = array;
     }
     reader.position += i;
     while (i > reader.available)
     {
         if (reader.available > 0)
         {
             Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, num, reader.available);
             i -= reader.available;
             num += reader.available;
             reader.ioIndex = (reader.available = 0);
         }
         int num2 = (i <= reader.ioBuffer.Length) ? i : reader.ioBuffer.Length;
         if (num2 > 0)
         {
             reader.Ensure(num2, true);
         }
     }
     if (i > 0)
     {
         Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, num, i);
         reader.ioIndex += i;
         reader.available -= i;
     }
     return value;
 }
開發者ID:floatyears,項目名稱:Decrypt,代碼行數:54,代碼來源:ProtoReader.cs


注:本文中的ProtoBuf.ProtoReader.ReadUInt32Variant方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。