コード例 #1
0
        public static Whisper.ChunkGenerator.StreamChunk Deserialize(Stream stream, Whisper.ChunkGenerator.StreamChunk instance)
        {
            if (instance.Chunks == null)
            {
                instance.Chunks = new List <byte[]> ();
            }
            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.Size = ProtocolParser.ReadUInt64(stream);
                    break;

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