writeRelativePosition = (encoder, rpos) => {
  const {
    type,
    tname,
    item,
    assoc
  } = rpos;

  if (item !== null) {
    encoding.writeVarUint(encoder, 0);
    writeID(encoder, item);
  } else if (tname !== null) {
    // case 2: found position at the end of the list and type is stored in y.share
    encoding.writeUint8(encoder, 1);
    encoding.writeVarString(encoder, tname);
  } else if (type !== null) {
    // case 3: found position at the end of the list and type is attached to an item
    encoding.writeUint8(encoder, 2);
    writeID(encoder, type);
  } else {
    throw error.unexpectedCase();
  }

  encoding.writeVarInt(encoder, assoc);
  return encoder;
}
@param {encoding.Encoder} encoder
@param {RelativePosition} rpos

@function