Beispiel #1
0
        /// <summary>
        /// Creates new Protobuf_Field class instance by reading and decoding it from Protobuf_Streamer.
        /// </summary>
        /// <param name="streamer">Protobuf_Streamer for reading.</param>
        public Protobuf_Field(Protobuf_Streamer streamer)
        {
            Int64 head = streamer.ReadVarint();

            if (head == 0) // end of stream or read error
            {
                throw new Exception("End of underlaying stream of read error");
            }

            this.p_wt    = (Protobuf.WireType)(head & 0x07);
            this.p_fn    = (ushort)(head >> 3);
            this.p_data  = null;
            this.p_idata = 0;

            switch (this.p_wt)
            {
            case Protobuf.WireType.Varint:
                this.p_idata = streamer.ReadVarint();
                break;

            case Protobuf.WireType.Fixed64bit:
                this.p_data = streamer.ReadBytes(8);
                break;

            case Protobuf.WireType.LengthDelimited:
                int len = (int)(streamer.ReadVarint());
                this.p_data = streamer.ReadBytes(len);
                break;

            /*case Protobuf.WireType_StartGroup: -- deprecated
             *  break;
             * case Protobuf.WireType_EndGroup: -- deprecated
             *  break;*/
            case Protobuf.WireType.Fixed32bit:
                this.p_data = streamer.ReadBytes(4);
                break;

            default:
                throw new Exception("Unknown protobuf wire type " + this.p_wt);
            }
        }