-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thrift/Python compact protocol fast extension
Summary: Making use of the c++ classes using cython This implementation is on par with speeds of fastbinary, and can also preform the work of fast binary. Test Plan: run unit tests Reviewed By: davejwatson@fb.com Subscribers: mshneer, ruibalp, alandau, bmatheny FB internal diff: D1409955 Tasks: 4605665, 3906100
- Loading branch information
Showing
4 changed files
with
606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2014 Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "thrift/lib/cpp/transport/TCallbackTransport.h" | ||
|
||
#include <exception> | ||
|
||
using namespace std; | ||
|
||
namespace apache { namespace thrift { namespace transport { | ||
|
||
uint32_t TCallbackTransport::read(uint8_t* buf, uint32_t len) { | ||
uint32_t rv = read_callback(userData, buf, len); | ||
if (rv < 0) { | ||
throw TTransportException(TTransportException::UNKNOWN, | ||
"TCallbackTransport::read()", | ||
rv); | ||
} | ||
return rv; | ||
} | ||
|
||
void TCallbackTransport::write(const uint8_t* buf, uint32_t len) { | ||
uint32_t rv = write_callback(userData, buf, len); | ||
|
||
if (rv < 0) { | ||
throw TTransportException(TTransportException::UNKNOWN, | ||
"TCallbackTransport::write()", | ||
rv); | ||
} | ||
} | ||
|
||
}}} // apache::thrift::transport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2014 Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef _THRIFT_TRANSPORT_TCALLBACKTRANSPORT_H_ | ||
#define _THRIFT_TRANSPORT_TCALLBACKTRANSPORT_H_ 1 | ||
|
||
#include "TTransport.h" | ||
#include "TVirtualTransport.h" | ||
|
||
namespace apache { namespace thrift { namespace transport { | ||
|
||
typedef uint32_t (*WriteCallback)(void* userdata, const uint8_t* buf, uint32_t len); | ||
typedef uint32_t (*ReadCallback)(void* userdata, uint8_t* buf, uint32_t len); | ||
|
||
/** | ||
* Call some callbacks to do transport | ||
* | ||
*/ | ||
class TCallbackTransport : public TVirtualTransport<TCallbackTransport> { | ||
public: | ||
|
||
TCallbackTransport() {} | ||
|
||
~TCallbackTransport() {} | ||
|
||
bool isOpen() { return true; } | ||
|
||
void open() {} | ||
|
||
void close() {} | ||
|
||
uint32_t read(uint8_t* buf, uint32_t len); | ||
|
||
void write(const uint8_t* buf, uint32_t len); | ||
|
||
void setWriteCallback(WriteCallback callback, void* userdata) { | ||
write_callback = callback; | ||
userData = userdata; | ||
} | ||
void setReadCallback(ReadCallback callback, void* userdata) { | ||
read_callback = callback; | ||
userData = userdata; | ||
} | ||
|
||
protected: | ||
void* userData; | ||
WriteCallback write_callback; | ||
ReadCallback read_callback; | ||
}; | ||
|
||
}}} // apache::thrift::transport | ||
|
||
#endif // #ifndef _THRIFT_TRANSPORT_TCALLBACKTRANSPORT_H_ |
Oops, something went wrong.