How to use the capnp-ts/lib/std/schema.capnp.Field 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
} else if (field.isGroup()) {
    jsType = getFullClassName(lookupNode(ctx, field.getGroup().getTypeId()));
    whichType = "group";
  } else {
    throw new Error(format(E.GEN_UNKNOWN_STRUCT_FIELD, field.which()));
  }

  const jsTypeReference = ts.createTypeReferenceNode(jsType, __);
  const discriminantOffset = node.getStruct().getDiscriminantOffset();
  const name = field.getName();
  const properName = util.c2t(name);
  const hadExplicitDefault =
    field.isSlot() && field.getSlot().getHadExplicitDefault();
  const discriminantValue = field.getDiscriminantValue();
  const fullClassName = getFullClassName(node);
  const union = discriminantValue !== s.Field.NO_DISCRIMINANT;
  const offset = (field.isSlot() && field.getSlot().getOffset()) || 0;
  const offsetLiteral = ts.createNumericLiteral(offset.toString());
  /** __S.getPointer(0, this) */
  const getPointer = ts.createCall(
    ts.createPropertyAccess(STRUCT, "getPointer"),
    __,
    [offsetLiteral, THIS]
  );
  /** __S.copyFrom(value, __S.getPointer(0, this)) */
  const copyFromValue = ts.createCall(
    ts.createPropertyAccess(STRUCT, "copyFrom"),
    __,
    [VALUE, getPointer]
  );
  /** capnp.Orphan */
  const orphanType = ts.createTypeReferenceNode("capnp.Orphan", [
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / file.ts View on Github external
    .filter(f => f.getDiscriminantValue() !== s.Field.NO_DISCRIMINANT);
}