2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
20
#include "PeekProcessor.h"
22
using namespace apache::thrift::transport;
23
using namespace apache::thrift::protocol;
24
using namespace apache::thrift;
26
namespace apache { namespace thrift { namespace processor {
28
PeekProcessor::PeekProcessor() {
29
memoryBuffer_.reset(new TMemoryBuffer());
30
targetTransport_ = memoryBuffer_;
32
PeekProcessor::~PeekProcessor() {}
34
void PeekProcessor::initialize(boost::shared_ptr<TProcessor> actualProcessor,
35
boost::shared_ptr<TProtocolFactory> protocolFactory,
36
boost::shared_ptr<TPipedTransportFactory> transportFactory) {
37
actualProcessor_ = actualProcessor;
38
pipedProtocol_ = protocolFactory->getProtocol(targetTransport_);
39
transportFactory_ = transportFactory;
40
transportFactory_->initializeTargetTransport(targetTransport_);
43
boost::shared_ptr<TTransport> PeekProcessor::getPipedTransport(boost::shared_ptr<TTransport> in) {
44
return transportFactory_->getTransport(in);
47
void PeekProcessor::setTargetTransport(boost::shared_ptr<TTransport> targetTransport) {
48
targetTransport_ = targetTransport;
49
if (boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport_)) {
50
memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport);
51
} else if (boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)) {
52
memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)->getTargetTransport());
56
throw TException("Target transport must be a TMemoryBuffer or a TPipedTransport with TMemoryBuffer");
60
bool PeekProcessor::process(boost::shared_ptr<TProtocol> in,
61
boost::shared_ptr<TProtocol> out,
62
void* connectionContext) {
67
in->readMessageBegin(fname, mtype, seqid);
69
if (mtype != T_CALL) {
70
throw TException("Unexpected message type");
79
in->readFieldBegin(fname, ftype, fid);
80
if (ftype == T_STOP) {
84
// Peek at the variable
89
in->getTransport()->readEnd();
92
// All the data is now in memoryBuffer_ and ready to be processed
95
// Let's first take a peek at the full data in memory
98
memoryBuffer_->getBuffer(&buffer, &size);
99
peekBuffer(buffer, size);
101
// Done peeking at variables
104
bool ret = actualProcessor_->process(pipedProtocol_, out, connectionContext);
105
memoryBuffer_->resetBuffer();
109
void PeekProcessor::peekName(const std::string& fname) {
113
void PeekProcessor::peekBuffer(uint8_t* buffer, uint32_t size) {
118
void PeekProcessor::peek(boost::shared_ptr<TProtocol> in,
125
void PeekProcessor::peekEnd() {}