Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.getSlot()
.getType()
.getList()
.getElementType()
.which();
let listClass = ConcreteListType[whichElementType];
if (
whichElementType === s.Type.LIST ||
whichElementType === s.Type.STRUCT
) {
listClass = `${fullClassName}._${properName}`;
} else if (listClass === void 0) {
/* istanbul ignore next */
throw new Error(
format(E.GEN_UNSUPPORTED_LIST_ELEMENT_TYPE, whichElementType)
);
}
const listClassIdentifier = ts.createIdentifier(listClass);
getArgs = [offsetLiteral, listClassIdentifier, THIS];
if (defaultValue) getArgs.push(defaultValue);
adopt = true;
disown = true;
/** __S.getList(0, MyStruct._Foo, this) */
get = ts.createCall(
ts.createPropertyAccess(STRUCT, "getList"),
__,
getArgs
);
/** __S.setText(0, value, this) */
set = ts.createCall(ts.createPropertyAccess(STRUCT, "setText"), __, [
offsetLiteral,
VALUE,
THIS
]);
break;
case s.Type.VOID:
break;
case "group":
if (hadExplicitDefault) {
throw new Error(format(E.GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE, "group"));
}
const groupType = ts.createIdentifier(jsType);
/** __S.getAs(Foo, this); */
get = ts.createCall(ts.createPropertyAccess(STRUCT, "getAs"), __, [
groupType,
THIS
]);
init = get;
break;
default:
// TODO Maybe this should be an error?
function Event (buf) {
// force usage of new
if (!(this instanceof Event)) {
return new Event(buf);
}
this.msg = new capnp.Message(buf, false);
this.event = this.msg.getRoot(CapnpEvent);
this.toJSON = partial(toJSON, this.event);
}
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), __, [
export function generateCapnpImport(ctx: CodeGeneratorFileContext): void {
// Look for the special importPath annotation on the file to see if we need a different import path for capnp-ts.
const fileNode = lookupNode(ctx, ctx.file);
const tsFileId = capnp.Uint64.fromHexString(TS_FILE_ID);
// This may be undefined if ts.capnp is not imported; fine, we'll just use the default.
const tsAnnotationFile = ctx.nodes.find(n => n.getId().equals(tsFileId));
// We might not find the importPath annotation; that's definitely a bug but let's move on.
const tsImportPathAnnotation =
tsAnnotationFile &&
tsAnnotationFile.getNestedNodes().find(n => n.getName() === "importPath");
// There may not necessarily be an import path annotation on the file node. That's fine.
const importAnnotation =
tsImportPathAnnotation &&
fileNode
.getAnnotations()
.find(a => a.getId().equals(tsImportPathAnnotation.getId()));
const importPath =
importAnnotation === undefined
? "capnp-ts"
: importAnnotation.getValue().getText();
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:
CarEvent.prototype.setWarning = function (value) { capnp_ts_1.Struct.setBit(18, value, this); };
CarEvent.prototype.getUserDisable = function () { return capnp_ts_1.Struct.getBit(19, this); };
CarEvent.prototype.setUserDisable = function (value) { capnp_ts_1.Struct.setBit(19, value, this); };
CarEvent.prototype.getSoftDisable = function () { return capnp_ts_1.Struct.getBit(20, this); };
CarEvent.prototype.setSoftDisable = function (value) { capnp_ts_1.Struct.setBit(20, value, this); };
CarEvent.prototype.getImmediateDisable = function () { return capnp_ts_1.Struct.getBit(21, this); };
CarEvent.prototype.setImmediateDisable = function (value) { capnp_ts_1.Struct.setBit(21, value, this); };
CarEvent.prototype.getPreEnable = function () { return capnp_ts_1.Struct.getBit(22, this); };
CarEvent.prototype.setPreEnable = function (value) { capnp_ts_1.Struct.setBit(22, value, this); };
CarEvent.prototype.getPermanent = function () { return capnp_ts_1.Struct.getBit(23, this); };
CarEvent.prototype.setPermanent = function (value) { capnp_ts_1.Struct.setBit(23, value, this); };
CarEvent.prototype.toString = function () { return 'CarEvent_' + _super.prototype.toString.call(this); };
CarEvent.EventName = CarEvent_EventName;
CarEvent._capnp = { displayName: 'CarEvent', id: '9b1657f34caf3ad3', size: new capnp_ts_1.ObjectSize(8, 0) };
return CarEvent;
}(capnp_ts_1.Struct));
exports.CarEvent = CarEvent;
var CarState_WheelSpeeds = /** @class */ (function (_super) {
__extends(CarState_WheelSpeeds, _super);
function CarState_WheelSpeeds () {
return _super !== null && _super.apply(this, arguments) || this;
}
CarState_WheelSpeeds.prototype.getFl = function () { return capnp_ts_1.Struct.getFloat32(0, this); };
CarState_WheelSpeeds.prototype.setFl = function (value) { capnp_ts_1.Struct.setFloat32(0, value, this); };
CarState_WheelSpeeds.prototype.getFr = function () { return capnp_ts_1.Struct.getFloat32(4, this); };
CarState_WheelSpeeds.prototype.setFr = function (value) { capnp_ts_1.Struct.setFloat32(4, value, this); };
CarState_WheelSpeeds.prototype.getRl = function () { return capnp_ts_1.Struct.getFloat32(8, this); };
CarState_WheelSpeeds.prototype.setRl = function (value) { capnp_ts_1.Struct.setFloat32(8, value, this); };
CarState_WheelSpeeds.prototype.getRr = function () { return capnp_ts_1.Struct.getFloat32(12, this); };
CarState_WheelSpeeds.prototype.setRr = function (value) { capnp_ts_1.Struct.setFloat32(12, value, this); };
CarState_WheelSpeeds.prototype.toString = function () { return 'CarState_WheelSpeeds_' + _super.prototype.toString.call(this); };
CarState_WheelSpeeds._capnp = { displayName: 'WheelSpeeds', id: '991a37a6155935a3', size: new capnp_ts_1.ObjectSize(16, 0) };
CarParams.prototype.getDirectAccelControl = function () { return capnp_ts_1.Struct.getBit(8, this); };
CarParams.prototype.setDirectAccelControl = function (value) { capnp_ts_1.Struct.setBit(8, value, this); };
CarParams.prototype.setDirectAccelControl = function (value) { capnp_ts_1.Struct.setBit(8, value, this); };
CarParams.prototype.getStoppingControl = function () { return capnp_ts_1.Struct.getBit(9, this); };
CarState.prototype.setSteeringPressed = function (value) { capnp_ts_1.Struct.setBit(66, value, this); };
CarState.prototype.adoptCruiseState = function (value) { capnp_ts_1.Struct.adopt(value, capnp_ts_1.Struct.getPointer(2, this)); };