コード例 #1
0
        public static Whisper.Messages.TreeMessage Deserialize(Stream stream, Whisper.Messages.TreeMessage 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.Name = ProtocolParser.ReadString(stream);
                    break;

                case 18:                 //Field 2 LengthDelimited
                    instance.TreeChunkHash = 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 void Write(Stream stream, Whisper.Messages.TreeMessage instance)
 {
     Whisper.Messages.TreeMessage.Serialize(stream, instance);
 }
コード例 #3
0
 public static Whisper.Messages.TreeMessage Read(byte[] buffer, Whisper.Messages.TreeMessage instance)
 {
     using (MemoryStream ms = new MemoryStream(buffer))
         Whisper.Messages.TreeMessage.Deserialize(ms, instance);
     return(instance);
 }
コード例 #4
0
 public static Whisper.Messages.TreeMessage Read(Stream stream, Whisper.Messages.TreeMessage instance)
 {
     return(Whisper.Messages.TreeMessage.Deserialize(stream, instance));
 }