예제 #1
0
 internal ResultResponse(ResponseFrame frame)
     : base(frame)
 {
     Kind = (ResultResponseKind) BeBinaryReader.ReadInt32();
     switch (Kind)
     {
         case ResultResponseKind.Void:
             Output = new OutputVoid(TraceId);
             break;
         case ResultResponseKind.Rows:
             Output = new OutputRows(frame.Header.Version, BeBinaryReader, true, TraceId);
             break;
         case ResultResponseKind.SetKeyspace:
             Output = new OutputSetKeyspace(BeBinaryReader.ReadString());
             break;
         case ResultResponseKind.Prepared:
             Output = new OutputPrepared(BeBinaryReader, frame.Header.Version > 1);
             break;
         case ResultResponseKind.SchemaChange:
             Output = new OutputSchemaChange(BeBinaryReader, TraceId);
             break;
         default:
             throw new DriverInternalError("Unknown ResultResponseKind Type");
     }
 }
예제 #2
0
 public AbstractResponse Parse(ResponseFrame frame)
 {
     var opcode = frame.FrameHeader.Opcode;
     if (RegisteredResponses[opcode] != null)
         return RegisteredResponses[opcode](frame);
     throw new DriverInternalError("Unknown Response Frame type");
 }
예제 #3
0
 public AbstractResponse Parse(ResponseFrame frame)
 {
     var opcode = frame.FrameHeader.Opcode;
     if (RegisteredResponses[opcode] != null)
         return RegisteredResponses[opcode](frame);
     return null;
 }
        internal ResultResponse(ResponseFrame frame) : base(frame)
        {
            //Handle result flags
            if ((frame.Header.Flags & FrameHeader.HeaderFlag.Warning) != 0)
            {
                Warnings = BeBinaryReader.ReadStringList();
            }
            if ((frame.Header.Flags &FrameHeader.HeaderFlag.CustomPayload) != 0)
            {
                CustomPayload = BeBinaryReader.ReadBytesMap();
            }

            Kind = (ResultResponseKind) BeBinaryReader.ReadInt32();
            switch (Kind)
            {
                case ResultResponseKind.Void:
                    Output = new OutputVoid(TraceId);
                    break;
                case ResultResponseKind.Rows:
                    Output = new OutputRows(frame.Header.Version, BeBinaryReader, TraceId);
                    break;
                case ResultResponseKind.SetKeyspace:
                    Output = new OutputSetKeyspace(BeBinaryReader.ReadString());
                    break;
                case ResultResponseKind.Prepared:
                    Output = new OutputPrepared(frame.Header.Version, BeBinaryReader);
                    break;
                case ResultResponseKind.SchemaChange:
                    Output = new OutputSchemaChange(BeBinaryReader, TraceId);
                    break;
                default:
                    throw new DriverInternalError("Unknown ResultResponseKind Type");
            }
        }
예제 #5
0
 /// <summary>
 /// Parses the response frame
 /// </summary>
 public static AbstractResponse Parse(ResponseFrame frame)
 {
     byte opcode = frame.Header.Opcode;
     if (!_responseHandlerFactory.ContainsKey(opcode))
     {
         throw new DriverInternalError("Unknown Response Frame type " + opcode);
     }
     return _responseHandlerFactory[opcode](frame);
 }
예제 #6
0
        public ResponseFrame MakeFrame(IProtoBuf stream)
        {
            var bodyLen = TypeInterpreter.BytesToInt32(Len, 0);

            if (MaxFrameSize - 8 < bodyLen) throw new DriverInternalError("Frame length mismatch");

            var frame = new ResponseFrame() { FrameHeader = this, RawStream = stream };
            return frame;
        }
예제 #7
0
 internal AbstractResponse(ResponseFrame frame)
 {
     BEBinaryReader = new BEBinaryReader(frame);
     if ((frame.FrameHeader.Flags & 0x02) == 0x02)
     {
         var buffer = new byte[16];
         BEBinaryReader.Read(buffer, 0, 16);
         TraceID = new Guid(TypeInterpreter.GuidShuffle(buffer));
     }
 }
예제 #8
0
        internal AbstractResponse(ResponseFrame frame)
        {
            BeBinaryReader = new BEBinaryReader(frame.Body);

            if ((frame.Header.Flags & 0x02) == 0x02)
            {
                var buffer = new byte[16];
                BeBinaryReader.Read(buffer, 0, 16);
                TraceId = new Guid(TypeCodec.GuidShuffle(buffer));
            }
        }
예제 #9
0
        internal AbstractResponse(ResponseFrame frame)
        {
            BEBinaryReader = new BEBinaryReader(frame);
            if (frame.FrameHeader.Version != ResponseFrame.ProtocolResponseVersionByte)
                throw new ProtocolErrorException("Invalid protocol version");

            if ((frame.FrameHeader.Flags & 0x02) == 0x02)
            {
                var buffer = new byte[16];
                BEBinaryReader.Read(buffer, 0, 16);
                TraceID = new Guid(TypeInterpreter.GuidShuffle(buffer));
            }
        }
        internal AbstractResponse(ResponseFrame frame)
        {
            if (frame == null) throw new ArgumentNullException("frame");
            if (frame.Body == null) throw new InvalidOperationException("Response body of the received frame was null");

            BeBinaryReader = new BEBinaryReader(frame.Body);

            // If a response frame has the tracing flag set, its body contains a tracing ID.
            // the frame body. 
            if ((frame.Header.Flags & FrameHeader.HeaderFlag.Tracing) != 0)
            {
                var buffer = new byte[16];
                BeBinaryReader.Read(buffer, 0, 16);
                TraceId = new Guid(TypeCodec.GuidShuffle(buffer));
            }
        }
예제 #11
0
        public virtual IEnumerable<ResponseFrame> Process(byte[] buffer, int size, Stream stream, IProtoBufComporessor compressor)
        {
            Init(buffer, size);

            int bodyLen = int.MaxValue;
            while (AreMore())
            {

                byte b = GetByte();

                switch (ByteIdx)
                {
                    case 0: TmpFrameHeader.Version = b; break;
                    case 1: TmpFrameHeader.Flags = b; break;
                    case 2: TmpFrameHeader.StreamId = b; break;
                    case 3: TmpFrameHeader.Opcode = b; break;
                    case 4:
                        {
                            TmpFrameHeader.Len[0] = b;
                        } break;
                    case 5: TmpFrameHeader.Len[1] = b; break;
                    case 6: TmpFrameHeader.Len[2] = b; break;
                    case 7: TmpFrameHeader.Len[3] = b;
                        bodyLen = TypeInterpreter.BytesToInt32(TmpFrameHeader.Len, 0);
                        TmpFrame = TmpFrameHeader.MakeFrame(new StreamProtoBuf(stream, ((TmpFrameHeader.Flags & 0x01) == 0x01) ? compressor : null));
                        yield return TmpFrame;
                        break;
                    default:
                        throw new DriverInternalError("Invalid state");
                }

                ByteIdx++;
                if (ByteIdx >= FrameHeader.Size)
                {
                    ByteIdx = 0;
                    TmpFrameHeader = new FrameHeader();
                }
            }
        }
예제 #12
0
 public BEBinaryReader(ResponseFrame input)
 {
     _stream = input.RawStream;
 }
예제 #13
0
 private AbstractResponse ReadParseResponse(FrameHeader header, Stream body)
 {
     //Start at the first byte
     body.Position = 0;
     if ((header.Flags & 0x01) > 0)
     {
         body = Compressor.Decompress(body);
     }
     var frame = new ResponseFrame(header, body);
     var response = FrameParser.Parse(frame);
     return response;
 }
 private void EventOccured(ResponseFrame frame)
 {
     var response = FrameParser.Parse(frame);
     if (response is EventResponse)
     {
         if (CassandraEvent != null)
             CassandraEvent.Invoke(this, (response as EventResponse).CassandraEventArgs);
         return;
     }
     throw new DriverInternalError("Unexpected response frame");
 }
예제 #15
0
 internal static ResultResponse Create(ResponseFrame frame)
 {
     return new ResultResponse(frame);
 }