How to use the capnp-ts/lib/std/schema.capnp.Value_Which function in capnp-ts

To help you get started, we’ve selected a few capnp-ts 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 jdiaz5513 / capnp-ts / packages / capnpc-ts / src / ast-creators.ts View on Github external
break;

    case s.Value.LIST:
      p = value.getList();

      break;

    case s.Value.STRUCT:
      p = value.getStruct();

      break;

    case s.Value.INTERFACE:
    default:
      throw new Error(
        format(E.GEN_SERIALIZE_UNKNOWN_VALUE, s.Value_Which[value.which()])
      );
  }

  const m = new capnp.Message();
  m.setRoot(p);

  const buf = new Uint8Array(m.toPackedArrayBuffer());
  const bytes = new Array(buf.byteLength);

  for (let i = 0; i < buf.byteLength; i++) {
    bytes[i] = ts.createNumericLiteral(`0x${pad(buf[i].toString(16), 2)}`);
  }

  return ts.createCall(ts.createPropertyAccess(CAPNP, "readRawPointer"), __, [
    ts.createPropertyAccess(
      ts.createNew(ts.createIdentifier("Uint8Array"), __, [