How to use the rsocket-core.createBuffer function in rsocket-core

To help you get started, we’ve selected a few rsocket-core 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 rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / frames / src / Metadata.js View on Github external
export function encodeMetadata(
  service: string,
  method: string,
  tracing: Encodable,
  metadata: Encodable,
): Buffer {
  const serviceLength = UTF8Encoder.byteLength(service);
  const methodLength = UTF8Encoder.byteLength(method);
  const metadataLength = BufferEncoder.byteLength(metadata);
  // We can't overload the method call directly and the code generator currently only populates
  // the first 3 parameters
  if (undefined === tracing) {
    tracing = createBuffer(0);
  }
  const tracingLength = BufferEncoder.byteLength(tracing);

  const buffer = createBuffer(
    VERSION_SIZE +
      SERVICE_LENGTH_SIZE +
      serviceLength +
      METHOD_LENGTH_SIZE +
      methodLength +
      TRACING_LENGTH_SIZE +
      tracingLength +
      metadataLength,
  );

  let offset = buffer.writeUInt16BE(VERSION, 0);
github rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / frames / src / Metadata.js View on Github external
service: string,
  method: string,
  tracing: Encodable,
  metadata: Encodable,
): Buffer {
  const serviceLength = UTF8Encoder.byteLength(service);
  const methodLength = UTF8Encoder.byteLength(method);
  const metadataLength = BufferEncoder.byteLength(metadata);
  // We can't overload the method call directly and the code generator currently only populates
  // the first 3 parameters
  if (undefined === tracing) {
    tracing = createBuffer(0);
  }
  const tracingLength = BufferEncoder.byteLength(tracing);

  const buffer = createBuffer(
    VERSION_SIZE +
      SERVICE_LENGTH_SIZE +
      serviceLength +
      METHOD_LENGTH_SIZE +
      methodLength +
      TRACING_LENGTH_SIZE +
      tracingLength +
      metadataLength,
  );

  let offset = buffer.writeUInt16BE(VERSION, 0);

  offset = buffer.writeUInt16BE(serviceLength, offset);
  offset = UTF8Encoder.encode(service, buffer, offset, offset + serviceLength);

  offset = buffer.writeUInt16BE(methodLength, offset);
github rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / tracing / src / Tracing.js View on Github external
export function mapToBuffer(map: Object): Buffer {
  if (!map || Object.keys(map).length <= 0) {
    return createBuffer(0);
  }

  const aggregatedTags = Object.keys(map).reduce(
    (aggregate, key) => {
      const val = map[key];
      const keyLen = UTF8Encoder.byteLength(key);
      const keyBuf = createBuffer(keyLen);
      UTF8Encoder.encode(key, keyBuf, 0, keyLen);

      const valLen = UTF8Encoder.byteLength(val);
      const valBuf = createBuffer(valLen);
      UTF8Encoder.encode(val, valBuf, 0, valLen);

      const newEntries = aggregate.entries;
      newEntries.push({keyLen, keyBuf, valLen, valBuf});
github rsocket / rsocket-js / packages / rsocket-tcp-client / src / RSocketTcpClient.js View on Github external
constructor(socket: ?net$Socket, encoders: ?Encoders<*>) {
    this._buffer = createBuffer(0);
    this._encoders = encoders;
    this._receivers = new Set();
    this._senders = new Set();
    this._statusSubscribers = new Set();

    if (socket) {
      this.setupSocket(socket);
      this._status = CONNECTION_STATUS.CONNECTED;
    } else {
      this._socket = null;
      this._status = CONNECTION_STATUS.NOT_CONNECTED;
    }
  }
github rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / tracing / src / Tracing.js View on Github external
UTF8Encoder.encode(val, valBuf, 0, valLen);

      const newEntries = aggregate.entries;
      newEntries.push({keyLen, keyBuf, valLen, valBuf});

      return {
        //4 for the sizes plus the actual key and actual value
        totalSize: aggregate.totalSize + 4 + keyLen + valLen,
        entries: newEntries,
      };
    },
    {totalSize: 0, entries: []},
  );

  let offset = 0;
  const resultBuf = createBuffer(aggregatedTags.totalSize);
  aggregatedTags.entries.forEach(entry => {
    resultBuf.writeUInt16BE(entry.keyLen, offset);
    offset += 2; //2 bytes for key length

    BufferEncoder.encode(
      entry.keyBuf,
      resultBuf,
      offset,
      offset + entry.keyLen,
    );
    offset += entry.keyLen;

    resultBuf.writeUInt16BE(entry.valLen, offset);
    offset += 2;

    BufferEncoder.encode(
github rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / tracing / src / Tracing.js View on Github external
(aggregate, key) => {
      const val = map[key];
      const keyLen = UTF8Encoder.byteLength(key);
      const keyBuf = createBuffer(keyLen);
      UTF8Encoder.encode(key, keyBuf, 0, keyLen);

      const valLen = UTF8Encoder.byteLength(val);
      const valBuf = createBuffer(valLen);
      UTF8Encoder.encode(val, valBuf, 0, valLen);

      const newEntries = aggregate.entries;
      newEntries.push({keyLen, keyBuf, valLen, valBuf});

      return {
        //4 for the sizes plus the actual key and actual value
        totalSize: aggregate.totalSize + 4 + keyLen + valLen,
        entries: newEntries,
      };
    },
    {totalSize: 0, entries: []},
github rsocket / rsocket-rpc-js / rsocket-rpc-js / packages / tracing / src / Tracing.js View on Github external
(aggregate, key) => {
      const val = map[key];
      const keyLen = UTF8Encoder.byteLength(key);
      const keyBuf = createBuffer(keyLen);
      UTF8Encoder.encode(key, keyBuf, 0, keyLen);

      const valLen = UTF8Encoder.byteLength(val);
      const valBuf = createBuffer(valLen);
      UTF8Encoder.encode(val, valBuf, 0, valLen);

      const newEntries = aggregate.entries;
      newEntries.push({keyLen, keyBuf, valLen, valBuf});

      return {
        //4 for the sizes plus the actual key and actual value
        totalSize: aggregate.totalSize + 4 + keyLen + valLen,
        entries: newEntries,
      };
    },
    {totalSize: 0, entries: []},