/// <summary>
        /// Reads an unknown field, either parsing it and storing it or skipping it.
        /// </summary>
        /// <remarks>
        /// If the current set of options is empty and we manage to read a field, a new set of options
        /// will be created and returned. Otherwise, the return value is <c>this</c>. This allows
        /// us to start with a singleton empty set of options and just create new ones where necessary.
        /// </remarks>
        /// <param name="input">Input stream to read from. </param>
        /// <returns>The resulting set of custom options, either <c>this</c> or a new set.</returns>
        internal CustomOptions ReadOrSkipUnknownField(CodedInputStream input)
        {
            var tag   = input.LastTag;
            var field = WireFormat.GetTagFieldNumber(tag);

            switch (WireFormat.GetTagWireType(tag))
            {
            case WireFormat.WireType.LengthDelimited:
                return(AddValue(field, new FieldValue(input.ReadBytes())));

            case WireFormat.WireType.Fixed32:
                return(AddValue(field, new FieldValue(input.ReadFixed32())));

            case WireFormat.WireType.Fixed64:
                return(AddValue(field, new FieldValue(input.ReadFixed64())));

            case WireFormat.WireType.Varint:
                return(AddValue(field, new FieldValue(input.ReadRawVarint64())));

            // For StartGroup, EndGroup or any wire format we don't understand,
            // just use the normal behavior (call SkipLastField).
            default:
                input.SkipLastField();
                return(this);
            }
        }
Example #2
0
        public BNetHeader(CodedInputStream stream)
        {
            var serviceId = stream.ReadRawByte();
            var methodId  = stream.ReadRawVarint32();
            var requestId = stream.ReadRawByte() | (stream.ReadRawByte() << 8);

            var objectId = 0UL;

            if (serviceId != 0xfe)
            {
                objectId = stream.ReadRawVarint64();
            }
            var payloadLength = stream.ReadRawVarint32();

            this.SetData(serviceId, methodId, requestId, payloadLength, objectId);
        }
Example #3
0
        public ClientPacket(CodedInputStream stream)
        {
            m_stream = stream;

            // Read header
            m_service    = m_stream.ReadRawByte();
            m_method     = m_stream.ReadInt32();
            m_requestId  = m_stream.ReadInt16();
            m_listenerId = 0;

            Console.WriteLine("IN: service {0}, method {1:X}, requestId {2}, listenerId {3}", m_service, m_method, m_requestId, m_listenerId);

            if (m_service != 0xFE)
            {
                m_listenerId = m_stream.ReadRawVarint64();
            }
        }