How to use the capnp-ts/lib/std/schema.capnp.Node 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 / generators.ts View on Github external
groupNodes.forEach(n => generateNode(ctx, n));

  const whichNode = node.which();

  switch (whichNode) {
    case s.Node.STRUCT:
      generateStructNode(ctx, node, false);

      break;

    case s.Node.CONST:
      // Const nodes are generated along with the containing class, ignore these.

      break;

    case s.Node.ENUM:
      generateEnumNode(ctx, node);

      break;

    case s.Node.INTERFACE:
      generateStructNode(ctx, node, true);

      break;

    case s.Node.ANNOTATION:
      trace("ignoring unsupported annotation node: %s", node.getDisplayName());

      break;

    case s.Node.FILE:
    default:
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / generators.ts View on Github external
export function generateStructNode(
  ctx: CodeGeneratorFileContext,
  node: s.Node,
  interfaceNode: boolean
): void {
  trace("generateStructNode(%s) [%s]", node, node.getDisplayName());

  const displayNamePrefix = getDisplayNamePrefix(node);
  const fullClassName = getFullClassName(node);
  const nestedNodes = node
    .getNestedNodes()
    .map(n => lookupNode(ctx, n))
    .filter(n => !n.isConst() && !n.isAnnotation());
  const nodeId = node.getId();
  const nodeIdHex = nodeId.toHexString();
  const struct = node.which() === s.Node.STRUCT ? node.getStruct() : undefined;
  const unionFields = getUnnamedUnionFields(node).sort(compareCodeOrder);

  const dataWordCount = struct ? struct.getDataWordCount() : 0;
  const dataByteLength = struct ? dataWordCount * 8 : 0;
  const discriminantCount = struct ? struct.getDiscriminantCount() : 0;
  const discriminantOffset = struct ? struct.getDiscriminantOffset() : 0;
  const fields = struct
    ? struct
        .getFields()
        .toArray()
        .sort(compareCodeOrder)
    : [];
  const pointerCount = struct ? struct.getPointerCount() : 0;

  const concreteLists = fields
    .filter(needsConcreteListClass)