"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EncoderVisitor = void 0;
const ast_1 = require("@wapc/widl/ast");
const helpers_1 = require("./helpers");
class EncoderVisitor extends ast_1.BaseVisitor {
    constructor(writer) {
        super(writer);
    }
    visitObjectFieldsBefore(context) {
        super.triggerObjectFieldsBefore(context);
        this.write(`  encode(encoder: Writer): void {
    encoder.writeMapSize(${context.fields.length});\n`);
    }
    visitObjectField(context) {
        const field = context.field;
        this.write(`encoder.writeString(${helpers_1.strQuote(field.name.value)});\n`);
        this.write(helpers_1.encode("this." + field.name.value, field.type, helpers_1.isReference(field.annotations)));
        super.triggerObjectField(context);
    }
    visitObjectFieldsAfter(context) {
        this.write(`  }\n`);
        super.triggerObjectFieldsAfter(context);
    }
}
exports.EncoderVisitor = EncoderVisitor;
//# sourceMappingURL=encoder_visitor.js.map