import { BaseVisitor } from "@wapc/widl/ast";
import { encode, isReference, strQuote } from "./helpers";
export class EncoderVisitor extends 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(${strQuote(field.name.value)});\n`);
        this.write(encode("this." + field.name.value, field.type, isReference(field.annotations)));
        super.triggerObjectField(context);
    }
    visitObjectFieldsAfter(context) {
        this.write(`  }\n`);
        super.triggerObjectFieldsAfter(context);
    }
}
//# sourceMappingURL=encoder_visitor.js.map