How to use the capnp-ts/lib/std/schema.capnp.Type 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
set = ts.createCall(ts.createPropertyAccess(STRUCT, "copyFrom"), __, [
        VALUE,
        get
      ]);

      break;

    case s.Type.BOOL:
    case s.Type.ENUM:
    case s.Type.FLOAT32:
    case s.Type.FLOAT64:
    case s.Type.INT16:
    case s.Type.INT32:
    case s.Type.INT64:
    case s.Type.INT8:
    case s.Type.UINT16:
    case s.Type.UINT32:
    case s.Type.UINT64:
    case s.Type.UINT8:
      const { byteLength, getter, setter } = Primitive[whichType as number];
      // NOTE: For a BOOL type this is actually a bit offset; `byteLength` will be `1` in that case.
      const byteOffset = ts.createNumericLiteral(
        (offset * byteLength).toString()
      );
      getArgs = [byteOffset, THIS];

      if (defaultValue) getArgs.push(defaultValue);

      /** __S.getXYZ(0, this) */
      get = ts.createCall(ts.createPropertyAccess(STRUCT, getter), __, getArgs);
      /** __S.setXYZ(0, value, this) */
      set = ts.createCall(ts.createPropertyAccess(STRUCT, setter), __, [
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / generators.ts View on Github external
ts.createPropertyAccess(STRUCT, "getData"),
        __,
        getArgs
      );
      has = true;
      /** __S.initData(0, length, this) */
      init = ts.createCall(ts.createPropertyAccess(STRUCT, "initData"), __, [
        offsetLiteral,
        LENGTH,
        THIS
      ]);
      set = copyFromValue;

      break;

    case s.Type.INTERFACE:
      if (hadExplicitDefault) {
        throw new Error(
          format(E.GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE, "INTERFACE")
        );
      }

      /** __S.getPointerAs(0, Foo, this) */
      get = ts.createCall(ts.createPropertyAccess(STRUCT, "getPointerAs"), __, [
        offsetLiteral,
        ts.createIdentifier(jsType),
        THIS
      ]);
      set = copyFromValue;

      break;
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / constants.ts View on Github external
/** undefined */

export const __ = undefined;

/** boolean */

export const BOOLEAN_TYPE = ts.createTypeReferenceNode("boolean", __);

/** capnp */

export const CAPNP = ts.createIdentifier("capnp");

/** A Mapping of various types to their list type constructor. */

export const ConcreteListType = {
  [s.Type.ANY_POINTER]: "capnp.AnyPointerList",
  [s.Type.BOOL]: "capnp.BoolList",
  [s.Type.DATA]: "capnp.DataList",
  [s.Type.ENUM]: "capnp.Uint16List",
  [s.Type.FLOAT32]: "capnp.Float32List",
  [s.Type.FLOAT64]: "capnp.Float64List",
  [s.Type.INT16]: "capnp.Int16List",
  [s.Type.INT32]: "capnp.Int32List",
  [s.Type.INT64]: "capnp.Int64List",
  [s.Type.INT8]: "capnp.Int8List",
  [s.Type.INTERFACE]: "capnp.InterfaceList",
  [s.Type.LIST]: "capnp.PointerList",
  [s.Type.STRUCT]: "capnp.CompositeList",
  [s.Type.TEXT]: "capnp.TextList",
  [s.Type.UINT16]: "capnp.Uint16List",
  [s.Type.UINT32]: "capnp.Uint32List",
  [s.Type.UINT64]: "capnp.Uint64List",
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / constants.ts View on Github external
/** Some data used to help generate code for primitive struct fields. */

export const Primitive = {
  [s.Type.BOOL]: {
    byteLength: 1,
    getter: "getBit",
    mask: "getBitMask",
    setter: "setBit"
  },
  [s.Type.ENUM]: {
    byteLength: 2,
    getter: "getUint16",
    mask: "getUint16Mask",
    setter: "setUint16"
  },
  [s.Type.FLOAT32]: {
    byteLength: 4,
    getter: "getFloat32",
    mask: "getFloat32Mask",
    setter: "setFloat32"
  },
  [s.Type.FLOAT64]: {
    byteLength: 8,
    getter: "getFloat64",
    mask: "getFloat64Mask",
    setter: "setFloat64"
  },
  [s.Type.INT16]: {
    byteLength: 2,
    getter: "getInt16",
    mask: "getInt16Mask",
    setter: "setInt16"
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / file.ts View on Github external
case s.Type.FLOAT64:
    case s.Type.INT16:
    case s.Type.INT32:
    case s.Type.INT8:
    case s.Type.UINT16:
    case s.Type.UINT32:
    case s.Type.UINT8:
      return "number";

    case s.Type.INT64:
      return "capnp.Int64";

    case s.Type.INTERFACE:
      return "capnp.Interface";

    case s.Type.LIST:
      return `capnp.List${constructor ? "Ctor" : ""}<${getJsType(
        ctx,
        type.getList().getElementType(),
        false
      )}>`;

    case s.Type.STRUCT:
      const c = getFullClassName(lookupNode(ctx, type.getStruct().getTypeId()));

      return constructor ? `capnp.StructCtor<${c}>` : c;

    case s.Type.UINT64:
      return "capnp.Uint64";

    case s.Type.TEXT:
      return "string";
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / file.ts View on Github external
case s.Type.LIST:
      return `capnp.List${constructor ? "Ctor" : ""}<${getJsType(
        ctx,
        type.getList().getElementType(),
        false
      )}>`;

    case s.Type.STRUCT:
      const c = getFullClassName(lookupNode(ctx, type.getStruct().getTypeId()));

      return constructor ? `capnp.StructCtor<${c}>` : c;

    case s.Type.UINT64:
      return "capnp.Uint64";

    case s.Type.TEXT:
      return "string";

    case s.Type.VOID:
      return "capnp.Void";

    default:
      throw new Error(format(E.GEN_UNKNOWN_TYPE, whichType));
  }
}