{{ self::ts_doc_block(doc, "") }}export enum {{ name }} {
{%- for variant in variants %}
{{ self::ts_doc_block(variant.doc, "  ") }}  {{ variant.name }} = {{ variant.discriminant }},
{%- endfor %}
}

const {{ name }}Codec: WireCodec<{{ name }}> = {
  size: (_v) => 4,
  encode: (writer, v) => {
    switch (v) {
{%- for variant in variants %}
      case {{ name }}.{{ variant.name }}:
        writer.writeI32({{ loop.index0 }});
        break;
{%- endfor %}
    }
  },
  decode: (reader) => {
    const value = reader.readI32();
    switch (value) {
{%- for variant in variants %}
      case {{ loop.index0 }}: return {{ name }}.{{ variant.name }};
{%- endfor %}
      default: throw new Error(`Unknown {{ name }} wire tag: ${value}`);
    }
  },
};
