コード例 #1
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);
        }
コード例 #2
0
 public static void Write(Stream stream, Whisper.ChunkGenerator.TreeChunk instance)
 {
     Whisper.ChunkGenerator.TreeChunk.Serialize(stream, instance);
 }
コード例 #3
0
 public static Whisper.ChunkGenerator.TreeChunk Read(byte[] buffer, Whisper.ChunkGenerator.TreeChunk instance)
 {
     using (MemoryStream ms = new MemoryStream(buffer))
         Whisper.ChunkGenerator.TreeChunk.Deserialize(ms, instance);
     return(instance);
 }
コード例 #4
0
 public static Whisper.ChunkGenerator.TreeChunk Read(Stream stream, Whisper.ChunkGenerator.TreeChunk instance)
 {
     return(Whisper.ChunkGenerator.TreeChunk.Deserialize(stream, instance));
 }