export const enum {{ident}} {
  {%- for variant in variants %}
  {{variant.clone().ident()}} = {{variant.clone().value()}},
  {%- endfor %} 
}

export function write{{ident}}(value: {{ident}}, sinkOrBuf?: SinkOrBuf,): Sink {
  const sink = Sink.create(sinkOrBuf);
  switch (value) {
  {%- for variant in variants %}
    case {{variant.clone().value()}}:
      writeU32({{ loop.index - 1 }}, sink);
      break;
  {%- endfor %}
    default:
      throw new Error(`'${value}' is invalid value for enum '{{ident}}'`);
  }

  return sink;
}

export function read{{ident}}(sinkOrBuf: SinkOrBuf): {{ident}} {
  const sink = Sink.create(sinkOrBuf);
  const value = readU32(sink);
  switch (value) {
  {%- for variant in variants %}
    case {{ loop.index - 1 }}:
      return {{variant.clone().value()}};
  {%- endfor %}
    default:
      throw new Error(`'${value}' is invalid value for enum '{{ident}}'`);
  }
}