Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* 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.
*/
var thrift = require('thrift');
// var ThriftTransports = require('thrift/transport');
// var ThriftProtocols = require('thrift/protocol');
var Calculator = require('./gen-nodejs/Calculator');
var ttypes = require('./gen-nodejs/tutorial_types');
transport = thrift.TBufferedTransport()
protocol = thrift.TBinaryProtocol()
var connection = thrift.createConnection("127.0.0.1", 9090, {
transport : transport,
protocol : protocol
});
connection.on('error', function(err) {
console.error(false, err);
});
// Create a Calculator client with the connection
var client = thrift.createClient(Calculator, connection);
var num_requests = 20000;
var times = 0;
init(broker) {
super.init(broker);
try {
const Thrift = require("thrift");
this.TBufferedTransport = Thrift.TBufferedTransport;
this.TBinaryProtocol = Thrift.TBinaryProtocol;
const transport = new Thrift.TBufferedTransport(null, (res) => this.serialized = res);
this.protocol = new Thrift.TBinaryProtocol(transport);
} catch(err) {
/* istanbul ignore next */
this.broker.fatal("The 'thrift' package is missing! Please install it with 'npm install thrift --save' command!", err, true);
}
this.packets = require("./thrift/gen-nodejs/packets_types.js");
}
ensureConnection(opts) {
// Connection already established. Nothing to do.
if (this._connection) {
return;
}
var thriftOptions = {
transport : thrift.TBufferedTransport,
protocol : thrift.TBinaryProtocol,
path : "/_rpc/v1/reports/binary",
https : (opts.collector_encryption !== 'none'),
nodeOptions : {},
};
if (!opts.certificate_verification) {
// https://github.com/request/request/issues/418
thriftOptions.nodeOptions.rejectUnauthorized = false;
thriftOptions.nodeOptions.strictSSL = false;
}
this._connection = thrift.createHttpConnection(opts.collector_host, opts.collector_port, thriftOptions);
this._client = thrift.createHttpClient(crouton_thrift.ReportingServiceClient, this._connection);
}
function encode(value) {
var output = []
var transport = new thrift.TBufferedTransport(null, function (buf) {
output.push(buf)
})
var protocol = new thrift.TCompactProtocol(transport)
value.write(protocol)
transport.flush()
return Buffer.concat(output)
}
return new Promise((resolve, reject) => {
const trans = new TBufferedTransport(null, (msg, seqid) => {
resolve(msg)
})
const proto = new TCompactProtocol(trans)
payload.encode(proto)
proto.flush()
})
}
));
}
if (span.remoteEndpoint) {
const address = toThriftAddress(addressKey, span.remoteEndpoint);
res.binary_annotations.push(address);
}
if (span.debug) {
res.debug = true;
}
return res;
}
let serialized;
const transport = new TBufferedTransport(null, (res) => {
serialized = res;
});
const protocol = new TBinaryProtocol(transport);
module.exports = {
encode(span) {
const spanThrift = toThriftSpan(span);
spanThrift.write(protocol);
protocol.flush();
return serialized;
}
};
exports.serializeThrift = function(obj) {
let output = []
let transport = new thrift.TBufferedTransport(null, function (buf) {
output.push(buf)
})
let protocol = new thrift.TCompactProtocol(transport)
obj.write(protocol)
transport.flush()
return Buffer.concat(output)
}