makeRecordUnionCodec = recordTypes => {
  const recordTable = Object.fromEntries(
    Object.values(recordTypes).map(recordCodec => {
      return [recordCodec.label, recordCodec];
    }),
  );
  const supports = label => {
    return recordTable[label] !== undefined;
  };
  const read = syrupReader => {
    syrupReader.enterRecord();
    const labelInfo = syrupReader.readRecordLabel();
    const labelString =
      labelInfo.type === 'bytestring'
        ? textDecoder.decode(labelInfo.value)
        : labelInfo.value;
    const recordCodec = recordTable[labelString];
    if (!recordCodec) {
      throw Error(`Unexpected record type: ${quote(labelString)}`);
    }
    const result = recordCodec.readBody(syrupReader);
    syrupReader.exitRecord();
    return result;
  };
  const write = (value, syrupWriter) => {
    const recordCodec = recordTable[value.type];
    if (!recordCodec) {
      throw Error(`Unexpected record type: ${quote(value.type)}`);
    }
    recordCodec.write(value, syrupWriter);
  };
  return freeze({ read, write, supports });
}
@param {Record<string, SyrupRecordCodec>} recordTypes
@returns {SyrupRecordUnionCodec}