How to use the thrift.TBinaryProtocol function in thrift

To help you get started, we’ve selected a few thrift examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-pinus / pinus / packages / pinus-rpc / sample / thrift / client.js View on Github external
* 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;
var start = Date.now();
github moleculerjs / moleculer / src / serializers / thrift.js View on Github external
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");
	}
github lightstep / lightstep-tracer-javascript / src / imp / platform / node / transport_node.js View on Github external
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);
    }
github apache / thrift / lib / nodejs / examples / parse.js View on Github external
function parseThrift(thriftEncodedData, callback) {
  var thrift = require('thrift');
  var transport = new thrift.TFramedTransport(thriftEncodedData);
  var protocol  = new thrift.TBinaryProtocol(transport);

  var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME;
  var client = new clientClass();
  client.read(protocol);
  callback(null, client);
}
github openzipkin / zipkin-js / packages / zipkin-encoder-thrift / src / index.js View on Github external
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;
  }
};