예제 #1
0
		public static Whisper.Repos.Pipe.RequestStoreMessage Deserialize (Stream stream, Whisper.Repos.Pipe.RequestStoreMessage instance)
		{
			while (true) {
				ProtocolBuffers.Key key = null;
				int keyByte = stream.ReadByte ();
				if (keyByte == -1)
					break;
				//Optimized reading of known fields with field ID < 16
				switch (keyByte) {
				case 10: //Field 1 LengthDelimited
					instance.Prefix = ProtocolParser.ReadString (stream);
					break;
				case 18: //Field 2 LengthDelimited
					instance.ChunkHash = ProtocolParser.ReadBytes (stream);
					break;
				default:
					key = ProtocolParser.ReadKey ((byte)keyByte, stream);
					break;
				}
		
				if (key == null)
					continue;
		
				//Reading field ID > 16 and unknown field ID/wire type combinations
				switch (key.Field) {
				case 0:
					throw new InvalidDataException ("Invalid field id: 0, something went wrong in the stream");
				default:
					ProtocolParser.SkipKey (stream, key);
					break;
				}
			}
			
			return instance;
		}
예제 #2
0
		public static Whisper.Repos.Pipe.ReplyWriteChunk Deserialize (Stream stream, Whisper.Repos.Pipe.ReplyWriteChunk instance)
		{
			while (true) {
				ProtocolBuffers.Key key = null;
				int keyByte = stream.ReadByte ();
				if (keyByte == -1)
					break;
				//Optimized reading of known fields with field ID < 16
				switch (keyByte) {
				default:
					key = ProtocolParser.ReadKey ((byte)keyByte, stream);
					break;
				}
		
				if (key == null)
					continue;
		
				//Reading field ID > 16 and unknown field ID/wire type combinations
				switch (key.Field) {
				case 0:
					throw new InvalidDataException ("Invalid field id: 0, something went wrong in the stream");
				default:
					ProtocolParser.SkipKey (stream, key);
					break;
				}
			}
			
			return instance;
		}
예제 #3
0
        public static Whisper.ChunkGenerator.TreeChunk Deserialize(Stream stream, Whisper.ChunkGenerator.TreeChunk instance)
        {
            if (instance.Directories == null)
            {
                instance.Directories = new List <Whisper.ChunkGenerator.TreeFile> ();
            }
            if (instance.Files == null)
            {
                instance.Files = new List <Whisper.ChunkGenerator.TreeFile> ();
            }
            while (true)
            {
                ProtocolBuffers.Key key = null;
                int keyByte             = stream.ReadByte();
                if (keyByte == -1)
                {
                    break;
                }
                //Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                case 10:                 //Field 1 LengthDelimited
                    instance.Directories.Add(Whisper.ChunkGenerator.TreeFile.Deserialize(ProtocolParser.ReadBytes(stream)));

                    break;

                case 18:                 //Field 2 LengthDelimited
                    instance.Files.Add(Whisper.ChunkGenerator.TreeFile.Deserialize(ProtocolParser.ReadBytes(stream)));

                    break;

                default:
                    key = ProtocolParser.ReadKey((byte)keyByte, stream);
                    break;
                }

                if (key == null)
                {
                    continue;
                }

                //Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                case 0:
                    throw new InvalidDataException("Invalid field id: 0, something went wrong in the stream");

                default:
                    ProtocolParser.SkipKey(stream, key);
                    break;
                }
            }

            return(instance);
        }
예제 #4
0
        public static Whisper.Messages.MessageHeader Deserialize(Stream stream, Whisper.Messages.MessageHeader instance)
        {
            while (true)
            {
                ProtocolBuffers.Key key = null;
                int keyByte             = stream.ReadByte();
                if (keyByte == -1)
                {
                    break;
                }
                //Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                case 8:                 //Field 1 Varint
                    instance.MessageId = ProtocolParser.ReadUInt32(stream);
                    break;

                case 18:                 //Field 2 LengthDelimited
                    instance.Signature = ProtocolParser.ReadBytes(stream);
                    break;

                default:
                    key = ProtocolParser.ReadKey((byte)keyByte, stream);
                    break;
                }

                if (key == null)
                {
                    continue;
                }

                //Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                case 0:
                    throw new InvalidDataException("Invalid field id: 0, something went wrong in the stream");

                default:
                    ProtocolParser.SkipKey(stream, key);
                    break;
                }
            }

            return(instance);
        }
예제 #5
0
 public static void SkipKey(Stream stream, Key key)
 {
     switch (key.WireType) {
     case Wire.Fixed32:
         stream.Seek (4, SeekOrigin.Current);
         return;
     case Wire.Fixed64:
         stream.Seek (8, SeekOrigin.Current);
         return;
     case Wire.LengthDelimited:
         stream.Seek (ProtocolParser.ReadUInt32 (stream), SeekOrigin.Current);
         return;
     case Wire.Varint:
         ProtocolParser.ReadSkipVarInt (stream);
         return;
     default:
         throw new NotImplementedException ("Unknown wire type: " + key.WireType);
     }
 }
예제 #6
0
 public static void WriteKey(Stream stream, Key key)
 {
     uint n = (key.Field << 3) | ((uint)key.WireType);
     WriteUInt32 (stream, n);
 }