Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1.  
  2.  
  3. /* THIS FILE HAS BEEN GENERATED BY A TOOL !!!
  4.  * DO NOT EDIT THIS FILE AS ALL CHANGES WILL BE LOST DURING THE NEXT BUILD */
  5. using System;
  6. using System.IO;
  7. using System.Collections;
  8. using Arendee.Protobuf_Micro.Extensions;
  9.  
  10. namespace Signax.DistributedDisplayProtocol
  11. {
  12.     public class BeginDownloadingFileRequest : IProtocolMessage
  13.     {
  14.         private static ushort PAYLOAD_IDENTIFIER = 0x0005;
  15.  
  16.         public ushort PayloadIdentifier
  17.         {
  18.             get
  19.             {
  20.                 return PAYLOAD_IDENTIFIER;
  21.             }
  22.         }
  23.  
  24.  
  25.         public string Path { get; set; }
  26.         public uint BlockSize { get; set; }
  27.         public uint Address { get; set; }
  28.  
  29.         public BeginDownloadingFileRequest()
  30.         {
  31.             BlockSize = 1024;
  32.             Address = 1;
  33.         }
  34.  
  35.         public static BeginDownloadingFileRequest Decode(Stream stream)
  36.         {
  37.             var message = new BeginDownloadingFileRequest();
  38.  
  39.             uint repeatedLength = 0;
  40.             while (stream.Position < stream.Length)
  41.             {
  42.                 var tag = stream.ReadTag();
  43.  
  44.                 switch (tag.Id)
  45.                 {
  46.                     case 1:
  47.                         message.Path = stream.ReadLengthDelimitedString();
  48.                         break;
  49.                     case 2:
  50.                         message.BlockSize = stream.ReadVarUInt32();
  51.                         break;
  52.                     case 15:
  53.                         message.Address = stream.ReadVarUInt32();
  54.                         break;
  55.                     default:
  56.                         break;
  57.                 }
  58.             }
  59.  
  60.             return message;
  61.         }
  62.  
  63.         //When the message is part of a repeated field
  64.         public static BeginDownloadingFileRequest Decode(Stream stream, uint length)
  65.         {
  66.             var message = new BeginDownloadingFileRequest();
  67.  
  68.             long carret = 0;
  69.  
  70.             while (stream.Position < stream.Length && carret < length)
  71.             {
  72.                 var initialPosition = stream.Position;
  73.                 var tag = stream.ReadTag();
  74.                 uint repeatedLength = 0;
  75.                 switch (tag.Id)
  76.                 {
  77.                     case 1:
  78.                         message.Path = stream.ReadLengthDelimitedString();
  79.                         break;
  80.                     case 2:
  81.                         message.BlockSize = stream.ReadVarUInt32();
  82.                         break;
  83.                     case 15:
  84.                         message.Address = stream.ReadVarUInt32();
  85.                         break;
  86.                     default:
  87.                         break;
  88.                 }
  89.  
  90.                 carret += stream.Position - initialPosition;
  91.             }
  92.  
  93.             return message;
  94.         }
  95.  
  96.  
  97.         public static BeginDownloadingFileRequest Decode(byte[] data)
  98.         {
  99.             using (var stream = new MemoryStream(data))
  100.             {
  101.                 return BeginDownloadingFileRequest.Decode(stream);
  102.             }
  103.         }
  104.  
  105.         public Stream Encode(Stream stream)
  106.         {
  107.             stream.WriteLengthDelimitedStringWithTag(1, Path);
  108.  
  109.             if (BlockSize != 1024)
  110.                 stream.WriteVarUInt32WithTag(2, BlockSize);
  111.             if (Address != 1)
  112.                 stream.WriteVarUInt32WithTag(15, Address);
  113.  
  114.             return stream;
  115.         }
  116.  
  117.         public byte[] Encode()
  118.         {
  119.             using (var stream = new MemoryStream())
  120.             {
  121.                 return ((MemoryStream)Encode(stream)).ToArray();
  122.             }
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement