"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(`func (o *${helpers_1.capitalize(context.object.name.value)}) Encode(encoder msgpack.Writer) error {
    if o == nil {
      encoder.WriteNil()
      return nil
    }
    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(false, "o." + helpers_1.fieldName(field.name.value), field.type, helpers_1.isReference(field.annotations)));
        super.triggerObjectField(context);
    }
    visitObjectFieldsAfter(context) {
        this.write(`
    return nil
  }\n\n`);
        super.triggerObjectFieldsAfter(context);
    }
}
exports.EncoderVisitor = EncoderVisitor;
//# sourceMappingURL=encoder_visitor.js.map